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/Config/Source/BusinessVertical.php b/Config/Source/BusinessVertical.php
new file mode 100644
index 00000000..a78b8c66
--- /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/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/PurchaseWebhookEvent.php b/DataLayer/Event/PurchaseWebhookEvent.php
index 0e2b9a0e..8cd6b004 100644
--- a/DataLayer/Event/PurchaseWebhookEvent.php
+++ b/DataLayer/Event/PurchaseWebhookEvent.php
@@ -99,17 +99,38 @@ 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() ?? '',
- "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_first_name" => $firstName,
+ "customer_last_name" => $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() ?? '' : '',
@@ -119,9 +140,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..27e5db52 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,8 @@ public function get(): array
'event' => 'trytagging_user_data',
'page' => [
'title' => $this->pageTitle->get(),
- 'type' => $this->pageType->get()
- ],
- 'store' => $this->currentStore->get(),
+ 'location' => $this->pagePath->get()
+ ]
];
}
}
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/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/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']);
}
diff --git a/composer.json b/composer.json
index 89227e00..608993e4 100644
--- a/composer.json
+++ b/composer.json
@@ -1,6 +1,6 @@
{
"name": "tagginggroup/gtm",
- "version": "1.0.13",
+ "version": "2.0.0",
"license": "OSL-3.0",
"type": "magento2-module",
"description": "AdPage tagging integration for Magento 2",
diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml
index a3bf6247..072e703d 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\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. ]]>
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..e4afcea2 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..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,6 +21,7 @@ define([
const eventData = {
'event': 'trytagging_add_to_cart',
'ecommerce': {
+ '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..b8e4080f 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;
+ }
}
if (cleanEventData.marketing) {