From 6aba5095ffeae0879bbff3aa9c29d5a9d90a83d2 Mon Sep 17 00:00:00 2001 From: Jeroen Frenken Date: Thu, 2 Jan 2025 12:03:17 +0100 Subject: [PATCH 01/10] New plugin version --- Config/Config.php | 16 ++++++++++++++++ DataLayer/Event/AddShippingInfo.php | 11 ++++++++--- DataLayer/Event/Purchase.php | 11 +++++++++++ DataLayer/Event/PurchaseWebhookEvent.php | 12 +++++++++--- DataLayer/Event/RemoveFromCart.php | 19 ++++++++++++++++--- DataLayer/Event/UserData.php | 14 ++++++++------ DataLayer/Mapper/ProductDataMapper.php | 10 ++++++---- composer.json | 2 +- .../frontend/layout/catalog_category_view.xml | 1 + .../templates/hyva/script-pusher.phtml | 6 +++++- view/frontend/templates/script.phtml | 8 +++----- .../js/mixins/catalog-add-to-cart-mixin.js | 2 ++ view/frontend/web/js/push.js | 7 ++++++- 13 files changed, 92 insertions(+), 27 deletions(-) diff --git a/Config/Config.php b/Config/Config.php index 973d5bec..ce683cdf 100644 --- a/Config/Config.php +++ b/Config/Config.php @@ -58,6 +58,22 @@ public function isEnabled(): bool return true; } + public function isEnabledBusinessVertical(): bool + { + $configValue = $this->getModuleConfigValue('business_vertical', ''); + + if (empty($configValue)) { + return false; + } + + return true; + } + + public function getBusinessVertical(): string + { + return (string)$this->getModuleConfigValue('business_vertical', ''); + } + /** * Check if lifetime value calculation is enabled in configuration * diff --git a/DataLayer/Event/AddShippingInfo.php b/DataLayer/Event/AddShippingInfo.php index 3e562418..5ebfe994 100644 --- a/DataLayer/Event/AddShippingInfo.php +++ b/DataLayer/Event/AddShippingInfo.php @@ -11,13 +11,13 @@ use Magento\Quote\Api\ShippingMethodManagementInterface; use Tagging\GTM\Api\Data\EventInterface; use Tagging\GTM\DataLayer\Tag\Cart\CartItems; - +use Tagging\GTM\Util\PriceFormatter; class AddShippingInfo implements EventInterface { private CartItems $cartItems; private ShippingMethodManagementInterface $shippingMethodManagement; private CheckoutSession $checkoutSession; - + private PriceFormatter $priceFormatter; /** * @param CartItems $cartItems * @param ShippingMethodManagementInterface $shippingMethodManagement @@ -26,11 +26,13 @@ class AddShippingInfo implements EventInterface public function __construct( CartItems $cartItems, ShippingMethodManagementInterface $shippingMethodManagement, - CheckoutSession $checkoutSession + CheckoutSession $checkoutSession, + PriceFormatter $priceFormatter ) { $this->cartItems = $cartItems; $this->shippingMethodManagement = $shippingMethodManagement; $this->checkoutSession = $checkoutSession; + $this->priceFormatter = $priceFormatter; } /** @@ -56,6 +58,9 @@ public function get(): array return [ 'event' => 'trytagging_add_shipping_info', 'ecommerce' => [ + 'currency' => $quote->getQuoteCurrencyCode(), + 'value' => $this->priceFormatter->format((float)$quote->getGrandTotal()), + 'coupon' => $quote->getCouponCode(), 'shipping_tier' => $shippingMethod, 'items' => $this->cartItems->get(), ], diff --git a/DataLayer/Event/Purchase.php b/DataLayer/Event/Purchase.php index 078aee32..1aa010a8 100644 --- a/DataLayer/Event/Purchase.php +++ b/DataLayer/Event/Purchase.php @@ -42,6 +42,17 @@ public function get(): array 'shipping' => $this->priceFormatter->format((float)$order->getShippingInclTax()), 'coupon' => $order->getCouponCode(), 'items' => $this->orderItems->setOrder($order)->get() + ], + 'user_data' => [ + 'customer_id' => $order->getCustomerId() ?? '', + 'customer_email' => $order->getCustomerEmail() ?? '', + 'customer_name' => $order->getCustomerFirstname() ?? '' . ' ' . $order->getCustomerLastname() ?? '', + 'customer_phone' => $order->getCustomerTelephone() ?? '', + 'customer_address' => $order->getCustomerAddress() ?? '', + 'customer_city' => $order->getCustomerCity() ?? '', + 'customer_state' => $order->getCustomerState() ?? '', + 'customer_zip' => $order->getCustomerPostcode() ?? '', + 'customer_country' => $order->getCustomerCountry() ?? '', ] ]; } diff --git a/DataLayer/Event/PurchaseWebhookEvent.php b/DataLayer/Event/PurchaseWebhookEvent.php index 071dc680..35d805a3 100644 --- a/DataLayer/Event/PurchaseWebhookEvent.php +++ b/DataLayer/Event/PurchaseWebhookEvent.php @@ -101,6 +101,15 @@ public function purchase(OrderInterface $order) try { $data['user_data'] = [ "customer_id" => $order->getCustomerId() ?? '', + "customer_email" => $order->getCustomerEmail() ?? '', + "customer_name" => $order->getCustomerFirstname() ?? '' . ' ' . $order->getCustomerLastname() ?? '', + "customer_phone" => $order->getCustomerTelephone() ?? '', + "customer_address" => $order->getCustomerAddress() ?? '', + "customer_city" => $order->getCustomerCity() ?? '', + "customer_state" => $order->getCustomerState() ?? '', + "customer_zip" => $order->getCustomerPostcode() ?? '', + "customer_country" => $order->getCustomerCountry() ?? '', + "billing_first_name" => $order->getBillingAddress() ? $order->getBillingAddress()->getFirstname() ?? '' : '', "billing_last_name" => $order->getBillingAddress() ? $order->getBillingAddress()->getLastname() ?? '' : '', "billing_address" => $order->getBillingAddress() && $order->getBillingAddress()->getStreet() ? $order->getBillingAddress()->getStreet()[0] ?? '' : '', @@ -119,9 +128,6 @@ public function purchase(OrderInterface $order) "shipping_state" => $order->getShippingAddress() ? $order->getShippingAddress()->getRegion() ?? '' : '', "shipping_city" => $order->getShippingAddress() ? $order->getShippingAddress()->getCity() ?? '' : '', "shipping_phone" => $order->getShippingAddress() ? $order->getShippingAddress()->getTelephone() ?? '' : '', - "email" => $order->getCustomerEmail() ?? '', - "first_name" => $order->getCustomerFirstname() ?? '', - "last_name" => $order->getCustomerLastname() ?? '', "new_customer" => (string)($order->getCustomerIsGuest() ? "true" : "false") ]; } catch (\Exception $e) { diff --git a/DataLayer/Event/RemoveFromCart.php b/DataLayer/Event/RemoveFromCart.php index abe6359b..48bed5bf 100644 --- a/DataLayer/Event/RemoveFromCart.php +++ b/DataLayer/Event/RemoveFromCart.php @@ -1,22 +1,33 @@ -cartItemDataMapper = $cartItemDataMapper; + $this->currencyCode = $currencyCode; + $this->priceFormatter = $priceFormatter; } /** @@ -28,6 +39,8 @@ public function get(): array return [ 'event' => 'trytagging_remove_from_cart', 'ecommerce' => [ + 'currency' => $this->currencyCode->get(), + 'value' => $this->priceFormatter->format((float)$cartItemData['price'] * (int)$cartItemData['quantity']), 'items' => [$cartItemData] ] ]; diff --git a/DataLayer/Event/UserData.php b/DataLayer/Event/UserData.php index b67553c1..0f6eea94 100644 --- a/DataLayer/Event/UserData.php +++ b/DataLayer/Event/UserData.php @@ -8,13 +8,13 @@ use Magento\Framework\Exception\NoSuchEntityException; use Tagging\GTM\Api\Data\EventInterface; use Tagging\GTM\DataLayer\Tag\PageTitle; -use Tagging\GTM\DataLayer\Tag\PageType; +use Tagging\GTM\DataLayer\Tag\PagePath; use Tagging\GTM\DataLayer\Tag\Store\CurrentStore; class UserData implements EventInterface { private PageTitle $pageTitle; - private PageType $pageType; + private PagePath $pagePath; private CurrentStore $currentStore; /** @@ -22,11 +22,11 @@ class UserData implements EventInterface */ public function __construct( PageTitle $pageTitle, - PageType $pageType, + PagePath $pagePath, CurrentStore $currentStore ) { $this->pageTitle = $pageTitle; - $this->pageType = $pageType; + $this->pagePath = $pagePath; $this->currentStore = $currentStore; } @@ -41,9 +41,11 @@ public function get(): array 'event' => 'trytagging_user_data', 'page' => [ 'title' => $this->pageTitle->get(), - 'type' => $this->pageType->get() + 'location' => $this->pagePath->get() ], - 'store' => $this->currentStore->get(), + 'cart' => [ + 'total' => doubleval(0) + ] ]; } } diff --git a/DataLayer/Mapper/ProductDataMapper.php b/DataLayer/Mapper/ProductDataMapper.php index a3eb624b..d6481f4a 100644 --- a/DataLayer/Mapper/ProductDataMapper.php +++ b/DataLayer/Mapper/ProductDataMapper.php @@ -75,16 +75,14 @@ public function mapByProduct(ProductInterface $product): array $productData[$dataLayerKey] = $attributeValue; } - $productData['item_id'] = $product->getSku(); - $productData['item_sku'] = $product->getSku(); - $productData['magento_sku'] = $product->getSku(); + $productData['item_id'] = strval($product->getSku()); $productData['magento_id'] = $product->getId(); $parentIds = $this->configurableType->getParentIdsByChild($product->getId()); if (!empty($parentIds)) { $parentProduct = $this->productRepository->getById($parentIds[0]); - $productData['item_id'] = $parentProduct->getSku(); + $productData['item_id'] = strval($parentProduct->getSku()); $productData['item_variant'] = $product->getSku(); } @@ -101,6 +99,10 @@ public function mapByProduct(ProductInterface $product): array $productData = $this->parseDataLayerMapping($product, $productData); $productData['index'] = $this->counter++; + if ($this->config->isEnabledBusinessVertical()) { + $productData['google_business_vertical'] = $this->config->getBusinessVertical(); + } + // @todo: Add "variant" reference to Configurable Product return $productData; diff --git a/composer.json b/composer.json index e86ea89f..608993e4 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "tagginggroup/gtm", - "version": "1.0.11", + "version": "2.0.0", "license": "OSL-3.0", "type": "magento2-module", "description": "AdPage tagging integration for Magento 2", diff --git a/view/frontend/layout/catalog_category_view.xml b/view/frontend/layout/catalog_category_view.xml index fb868eff..5f09e2d5 100644 --- a/view/frontend/layout/catalog_category_view.xml +++ b/view/frontend/layout/catalog_category_view.xml @@ -21,6 +21,7 @@ trytagging_view_item_list + Tagging\GTM\DataLayer\Tag\CurrencyCode Tagging\GTM\DataLayer\Tag\Category\Products diff --git a/view/frontend/templates/hyva/script-pusher.phtml b/view/frontend/templates/hyva/script-pusher.phtml index 8eb8bbe0..2fa6ba1b 100644 --- a/view/frontend/templates/hyva/script-pusher.phtml +++ b/view/frontend/templates/hyva/script-pusher.phtml @@ -39,7 +39,11 @@ declare(strict_types=1); if (window.taggingHelpers) { eventData.marketing = window.taggingHelpers.getMarketingObject(); - eventData.device = window.taggingHelpers.getDeviceInfo(); + + if (eventData.event === 'trytagging_user_data') { + eventData.device = window.taggingHelpers.getDeviceInfo(); + eventData.cart.total = 0.00; // TODO: Needs to be implemented + } } if (eventData.marketing) { diff --git a/view/frontend/templates/script.phtml b/view/frontend/templates/script.phtml index 00c43b3a..e7fb8d95 100644 --- a/view/frontend/templates/script.phtml +++ b/view/frontend/templates/script.phtml @@ -48,10 +48,8 @@ $config = $block->getConfig(); }) }) })(['load']); - -isDebug()) : ?> - - \ No newline at end of file + + \ No newline at end of file diff --git a/view/frontend/web/js/mixins/catalog-add-to-cart-mixin.js b/view/frontend/web/js/mixins/catalog-add-to-cart-mixin.js index 9ed44629..10fe26b3 100644 --- a/view/frontend/web/js/mixins/catalog-add-to-cart-mixin.js +++ b/view/frontend/web/js/mixins/catalog-add-to-cart-mixin.js @@ -21,6 +21,8 @@ define([ const eventData = { 'event': 'trytagging_add_to_cart', 'ecommerce': { + 'currency': 'IMPLEMENT_ME', + 'value': productData.price * productData.quantity, 'items': [productData] } }; diff --git a/view/frontend/web/js/push.js b/view/frontend/web/js/push.js index bf48d8e0..5eac2bf5 100644 --- a/view/frontend/web/js/push.js +++ b/view/frontend/web/js/push.js @@ -43,13 +43,18 @@ define(["googleTagManagerLogger"], function (logger) { logger(message, eventData); window.dataLayer = window.dataLayer || []; + if (cleanEventData && cleanEventData.ecommerce) { window.dataLayer.push({ ecommerce: null }); } if (window.taggingHelpers) { cleanEventData.marketing = window.taggingHelpers.getMarketingObject(); - cleanEventData.device = window.taggingHelpers.getDeviceInfo(); + + if (eventData.event === 'trytagging_user_data') { + cleanEventData.device = window.taggingHelpers.getDeviceInfo(); + cleanEventData.cart.total = 0.00; // TODO: Needs to be implemented + } } if (cleanEventData.marketing) { From 10847ff747986d463bdf28ec004851f11825fefc Mon Sep 17 00:00:00 2001 From: Jeroen Frenken Date: Thu, 2 Jan 2025 12:08:53 +0100 Subject: [PATCH 02/10] Updating config page --- Config/Source/BusinessVertical.php | 17 +++++++++++++++++ etc/adminhtml/system.xml | 28 ++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 Config/Source/BusinessVertical.php diff --git a/Config/Source/BusinessVertical.php b/Config/Source/BusinessVertical.php new file mode 100644 index 00000000..ebd63c16 --- /dev/null +++ b/Config/Source/BusinessVertical.php @@ -0,0 +1,17 @@ + '', 'label' => __('Disabled')], + ['value' => 'retail', 'label' => __('Retail')], + ['value' => 'flights', 'label' => __('Flights')], + ['value' => 'hotel_rental', 'label' => __('Hotel Rental')], + ['value' => 'jobs', 'label' => __('Jobs')], + ['value' => 'real_estate', 'label' => __('Real Estate')] + ]; + } +} diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index a3bf6247..053127fe 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -32,13 +32,7 @@ 1 - - - Magento\Config\Model\Config\Source\Yesno - - 1 - - + Enter the container url without https://
@@ -54,8 +48,26 @@ 1
+ + + Tagging\GTM\Model\Config\Source\BusinessVertical + This will add the google_business_vertical field to the data layer. ]]> + + 1 + + + + + + + Magento\Config\Model\Config\Source\Yesno + Disable the lifetime value variable in the data layer. ]]> + + 1 + + - + Magento\Config\Model\Config\Source\Yesno If you want to control on where the scripts are placed you can enable this option. Then the plugin will not load the files and you have to do it on your own.
NOTE; If all necessary scripts are not included, tracking will not function. ]]>
From 43229afa0a052a493c098d43c6991de3dbdce803 Mon Sep 17 00:00:00 2001 From: Jeroen Frenken Date: Thu, 2 Jan 2025 12:15:25 +0100 Subject: [PATCH 03/10] Config update --- etc/adminhtml/system.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 053127fe..881610ce 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -50,7 +50,7 @@
- Tagging\GTM\Model\Config\Source\BusinessVertical + Tagging\GTM\Config\Source\BusinessVertical This will add the google_business_vertical field to the data layer. ]]> 1 From 61ce74e364c968f588919cbafc2e56c23197d698 Mon Sep 17 00:00:00 2001 From: Jeroen Frenken Date: Thu, 2 Jan 2025 12:16:22 +0100 Subject: [PATCH 04/10] class update --- Config/Source/BusinessVertical.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Config/Source/BusinessVertical.php b/Config/Source/BusinessVertical.php index ebd63c16..3b0f7916 100644 --- a/Config/Source/BusinessVertical.php +++ b/Config/Source/BusinessVertical.php @@ -1,5 +1,5 @@ Date: Thu, 2 Jan 2025 12:17:11 +0100 Subject: [PATCH 05/10] fix --- Config/Source/BusinessVertical.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Config/Source/BusinessVertical.php b/Config/Source/BusinessVertical.php index 3b0f7916..a78b8c66 100644 --- a/Config/Source/BusinessVertical.php +++ b/Config/Source/BusinessVertical.php @@ -1,5 +1,5 @@ Date: Thu, 2 Jan 2025 14:30:22 +0100 Subject: [PATCH 06/10] Fixes --- DataLayer/Event/Purchase.php | 11 ------ DataLayer/Event/PurchaseWebhookEvent.php | 46 ++++++++++++++---------- DataLayer/Mapper/OrderItemDataMapper.php | 2 +- etc/adminhtml/system.xml | 4 +-- 4 files changed, 31 insertions(+), 32 deletions(-) diff --git a/DataLayer/Event/Purchase.php b/DataLayer/Event/Purchase.php index 1aa010a8..078aee32 100644 --- a/DataLayer/Event/Purchase.php +++ b/DataLayer/Event/Purchase.php @@ -42,17 +42,6 @@ public function get(): array 'shipping' => $this->priceFormatter->format((float)$order->getShippingInclTax()), 'coupon' => $order->getCouponCode(), 'items' => $this->orderItems->setOrder($order)->get() - ], - 'user_data' => [ - 'customer_id' => $order->getCustomerId() ?? '', - 'customer_email' => $order->getCustomerEmail() ?? '', - 'customer_name' => $order->getCustomerFirstname() ?? '' . ' ' . $order->getCustomerLastname() ?? '', - 'customer_phone' => $order->getCustomerTelephone() ?? '', - 'customer_address' => $order->getCustomerAddress() ?? '', - 'customer_city' => $order->getCustomerCity() ?? '', - 'customer_state' => $order->getCustomerState() ?? '', - 'customer_zip' => $order->getCustomerPostcode() ?? '', - 'customer_country' => $order->getCustomerCountry() ?? '', ] ]; } diff --git a/DataLayer/Event/PurchaseWebhookEvent.php b/DataLayer/Event/PurchaseWebhookEvent.php index 35d805a3..e7499f66 100644 --- a/DataLayer/Event/PurchaseWebhookEvent.php +++ b/DataLayer/Event/PurchaseWebhookEvent.php @@ -99,26 +99,36 @@ public function purchase(OrderInterface $order) ]; try { + $email = $order->getBillingAddress() ? $order->getBillingAddress()->getEmail() ?? '' : ''; + $firstName = $order->getBillingAddress() ? $order->getBillingAddress()->getFirstname() ?? '' : ''; + $lastName = $order->getBillingAddress() ? $order->getBillingAddress()->getLastname() ?? '' : ''; + $phone = $order->getBillingAddress() ? $order->getBillingAddress()->getTelephone() ?? '' : ''; + $address = $order->getBillingAddress() && $order->getBillingAddress()->getStreet() ? $order->getBillingAddress()->getStreet()[0] ?? '' : ''; + $city = $order->getBillingAddress() ? $order->getBillingAddress()->getCity() ?? '' : ''; + $state = $order->getBillingAddress() ? $order->getBillingAddress()->getRegion() ?? '' : ''; + $postcode = $order->getBillingAddress() ? $order->getBillingAddress()->getPostcode() ?? '' : ''; + $country = $order->getBillingAddress() ? $order->getBillingAddress()->getCountryId() ?? '' : ''; + $data['user_data'] = [ "customer_id" => $order->getCustomerId() ?? '', - "customer_email" => $order->getCustomerEmail() ?? '', - "customer_name" => $order->getCustomerFirstname() ?? '' . ' ' . $order->getCustomerLastname() ?? '', - "customer_phone" => $order->getCustomerTelephone() ?? '', - "customer_address" => $order->getCustomerAddress() ?? '', - "customer_city" => $order->getCustomerCity() ?? '', - "customer_state" => $order->getCustomerState() ?? '', - "customer_zip" => $order->getCustomerPostcode() ?? '', - "customer_country" => $order->getCustomerCountry() ?? '', - - "billing_first_name" => $order->getBillingAddress() ? $order->getBillingAddress()->getFirstname() ?? '' : '', - "billing_last_name" => $order->getBillingAddress() ? $order->getBillingAddress()->getLastname() ?? '' : '', - "billing_address" => $order->getBillingAddress() && $order->getBillingAddress()->getStreet() ? $order->getBillingAddress()->getStreet()[0] ?? '' : '', - "billing_postcode" => $order->getBillingAddress() ? $order->getBillingAddress()->getPostcode() ?? '' : '', - "billing_country" => $order->getBillingAddress() ? $order->getBillingAddress()->getCountryId() ?? '' : '', - "billing_state" => $order->getBillingAddress() ? $order->getBillingAddress()->getRegion() ?? '' : '', - "billing_city" => $order->getBillingAddress() ? $order->getBillingAddress()->getCity() ?? '' : '', - "billing_email" => $order->getBillingAddress() ? $order->getBillingAddress()->getEmail() ?? '' : '', - "billing_phone" => $order->getBillingAddress() ? $order->getBillingAddress()->getTelephone() ?? '' : '', + "customer_email" => $email, + "customer_name" => $firstName . ' ' . $lastName, + "customer_phone" => $phone, + "customer_address" => $address, + "customer_city" => $city, + "customer_state" => $state, + "customer_zip" => $postcode, + "customer_country" => $country, + + "billing_first_name" => $firstName, + "billing_last_name" => $lastName, + "billing_address" => $address, + "billing_postcode" => $postcode, + "billing_country" => $country, + "billing_state" => $state, + "billing_city" => $city, + "billing_email" => $email, + "billing_phone" => $phone, "shipping_first_name" => $order->getShippingAddress() ? $order->getShippingAddress()->getFirstname() ?? '' : '', "shipping_last_name" => $order->getShippingAddress() ? $order->getShippingAddress()->getLastname() ?? '' : '', "shipping_company" => $order->getShippingAddress() ? $order->getShippingAddress()->getCompany() ?? '' : '', diff --git a/DataLayer/Mapper/OrderItemDataMapper.php b/DataLayer/Mapper/OrderItemDataMapper.php index 979bf351..b4ce686e 100644 --- a/DataLayer/Mapper/OrderItemDataMapper.php +++ b/DataLayer/Mapper/OrderItemDataMapper.php @@ -55,7 +55,7 @@ public function mapByOrderItem(OrderItemInterface $orderItem, ?OrderInterface $o $orderItemData = [ 'item_id' => $orderItem->getSku(), 'item_name' => $orderItem->getName(), - 'discount' => (float) $orderItem->getDiscountAmount(), + 'discount' => $this->priceFormatter->format((float) $orderItem->getDiscountAmount()), 'quantity' => (float) $orderItem->getQtyOrdered(), 'price' => $this->getPrice($orderItem) ]; diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 881610ce..072e703d 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -58,7 +58,7 @@ - + Magento\Config\Model\Config\Source\Yesno Disable the lifetime value variable in the data layer. ]]> @@ -66,7 +66,7 @@ 1 - + Magento\Config\Model\Config\Source\Yesno If you want to control on where the scripts are placed you can enable this option. Then the plugin will not load the files and you have to do it on your own.
From d216a4002a5072b5fc079767b5557c8793bbee1a Mon Sep 17 00:00:00 2001 From: Jeroen Frenken Date: Sun, 12 Jan 2025 13:16:15 +0100 Subject: [PATCH 07/10] Added some customer fields to webhook --- DataLayer/Event/PurchaseWebhookEvent.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DataLayer/Event/PurchaseWebhookEvent.php b/DataLayer/Event/PurchaseWebhookEvent.php index e7499f66..b8472d09 100644 --- a/DataLayer/Event/PurchaseWebhookEvent.php +++ b/DataLayer/Event/PurchaseWebhookEvent.php @@ -113,6 +113,8 @@ public function purchase(OrderInterface $order) "customer_id" => $order->getCustomerId() ?? '', "customer_email" => $email, "customer_name" => $firstName . ' ' . $lastName, + "customer_first_name" => $firstName, + "customer_last_name" => $lastName, "customer_phone" => $phone, "customer_address" => $address, "customer_city" => $city, From c3464f3387830bec3eedb7f20c186fb8977089f0 Mon Sep 17 00:00:00 2001 From: Jeroen Frenken Date: Sun, 12 Jan 2025 13:18:19 +0100 Subject: [PATCH 08/10] Commented out non implemented functions --- DataLayer/Event/UserData.php | 3 --- view/frontend/templates/hyva/script-pusher.phtml | 2 +- view/frontend/web/js/push.js | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/DataLayer/Event/UserData.php b/DataLayer/Event/UserData.php index 0f6eea94..27e5db52 100644 --- a/DataLayer/Event/UserData.php +++ b/DataLayer/Event/UserData.php @@ -42,9 +42,6 @@ public function get(): array 'page' => [ 'title' => $this->pageTitle->get(), 'location' => $this->pagePath->get() - ], - 'cart' => [ - 'total' => doubleval(0) ] ]; } diff --git a/view/frontend/templates/hyva/script-pusher.phtml b/view/frontend/templates/hyva/script-pusher.phtml index 2fa6ba1b..e4afcea2 100644 --- a/view/frontend/templates/hyva/script-pusher.phtml +++ b/view/frontend/templates/hyva/script-pusher.phtml @@ -42,7 +42,7 @@ declare(strict_types=1); if (eventData.event === 'trytagging_user_data') { eventData.device = window.taggingHelpers.getDeviceInfo(); - eventData.cart.total = 0.00; // TODO: Needs to be implemented + // eventData.cart.total = 0.00; TODO: Needs to be implemented } } diff --git a/view/frontend/web/js/push.js b/view/frontend/web/js/push.js index 5eac2bf5..b8e4080f 100644 --- a/view/frontend/web/js/push.js +++ b/view/frontend/web/js/push.js @@ -53,7 +53,7 @@ define(["googleTagManagerLogger"], function (logger) { if (eventData.event === 'trytagging_user_data') { cleanEventData.device = window.taggingHelpers.getDeviceInfo(); - cleanEventData.cart.total = 0.00; // TODO: Needs to be implemented + // cleanEventData.cart.total = 0.00; } } From 5493a712f7f865a15be973ad955bbb07bc392710 Mon Sep 17 00:00:00 2001 From: Jeroen Frenken Date: Sun, 12 Jan 2025 13:35:00 +0100 Subject: [PATCH 09/10] Changed --- view/frontend/web/js/mixins/catalog-add-to-cart-mixin.js | 1 - 1 file changed, 1 deletion(-) diff --git a/view/frontend/web/js/mixins/catalog-add-to-cart-mixin.js b/view/frontend/web/js/mixins/catalog-add-to-cart-mixin.js index 10fe26b3..bfc07af2 100644 --- a/view/frontend/web/js/mixins/catalog-add-to-cart-mixin.js +++ b/view/frontend/web/js/mixins/catalog-add-to-cart-mixin.js @@ -21,7 +21,6 @@ define([ const eventData = { 'event': 'trytagging_add_to_cart', 'ecommerce': { - 'currency': 'IMPLEMENT_ME', 'value': productData.price * productData.quantity, 'items': [productData] } From 1edd965464e8fc6cf95956d35f7f04697eee69d1 Mon Sep 17 00:00:00 2001 From: Jeroen Frenken Date: Sun, 12 Jan 2025 13:37:34 +0100 Subject: [PATCH 10/10] Fixed tests --- Test/Integration/Page/CategoryPageTest.php | 1 - Test/Integration/Util/ProductDataMapperTest.php | 2 -- 2 files changed, 3 deletions(-) diff --git a/Test/Integration/Page/CategoryPageTest.php b/Test/Integration/Page/CategoryPageTest.php index 7ffa49f0..459ae8ef 100644 --- a/Test/Integration/Page/CategoryPageTest.php +++ b/Test/Integration/Page/CategoryPageTest.php @@ -81,7 +81,6 @@ public function testValidDataLayerWithOneCategory() $this->assertNotEmpty($event['ecommerce']['items'], var_export($event, true)); foreach ($event['ecommerce']['items'] as $productData) { $this->assertNotEmpty($productData['item_id']); - $this->assertNotEmpty($productData['item_sku']); $this->assertNotEmpty($productData['item_list_name']); } } diff --git a/Test/Integration/Util/ProductDataMapperTest.php b/Test/Integration/Util/ProductDataMapperTest.php index 2c6d57c2..e7669ced 100644 --- a/Test/Integration/Util/ProductDataMapperTest.php +++ b/Test/Integration/Util/ProductDataMapperTest.php @@ -27,9 +27,7 @@ public function testMapByProduct() $this->assertNonEmptyValueInArray('item_id', $productData); $this->assertSame(1, $productData['magento_id']); - $this->assertSame('product1', $productData['magento_sku']); $this->assertSame('product1', $productData['item_id']); - $this->assertSame('product1', $productData['item_sku']); $this->assertSame('Product 1', $productData['item_name']); $this->assertSame(1.42, $productData['price']); }