Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <{* Template: tracking_top.html
- Function: Tracking through dataLayer and GTM for GA4
- Reference: https://developers.google.com/analytics/devguides/collection/ga4/ecommerce?client_type=gtm
- https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtm
- https://support.google.com/analytics/answer/9267735
- https://support.google.com/analytics/answer/9234069
- https://www.simoahava.com/analytics/google-analytics-4-ecommerce-guide-google-tag-manager/
- Author: Nicolai Teglskov
- Author e-mail: info@nicolaiteglskov.dk
- Author URL: https://nicolaiteglskov.dk
- Last Updated: 2022/08/10
- *}>
- <{strip}>
- <{if $webshop->getEnableTracking()}>
- <{* Theme settings pushed to dataLayer start *}>
- <script>
- window.dataLayer = window.dataLayer || [];
- window.dataLayer.push({
- 'event': 'ShopOramaSettings',
- <{if $webshop->getFbId()}>
- 'settings.Facebook.Pixel_ID': '<{$webshop->getFbId()}>',
- <{/if}>
- <{if $webshop->getGaId()}>
- 'settings.Google.Analytics_Tracking_ID': '<{$webshop->getGaId()}>',
- <{/if}>
- <{if $webshop->getGoogleAdsConversionId()}>
- 'settings.Google.Ads_Conversion_ID': '<{$webshop->getGoogleAdsConversionId()}>',
- <{/if}>
- <{if $webshop->getGoogleAdsConversionLabelOrder()}>
- 'settings.Google.Ads_Conversion_Label_Order': '<{$webshop->getGoogleAdsConversionLabelOrder()}>',
- <{/if}>
- <{if $webshop->getGoogleMerchantId()}>
- 'settings.Google.Merchant_Center_ID': '<{$webshop->getGoogleMerchantId()}>',
- <{/if}>
- <{if $webshop->getGoogleMerchantDeliveryDays()}>
- 'settings.Google.Merchant_Center_Delivery_Days': '<{$webshop->getGoogleMerchantDeliveryDays()}>',
- <{/if}>
- <{if $webshop->getGoogleTagManagerId()}>
- 'settings.Google.Tag_Manager_Containder_ID': '<{$webshop->getGoogleTagManagerId()}>',
- <{/if}>
- <{if $webshop->getGA4MeasurementID()}>
- 'settings.Google.GA4_Measurement_ID': '<{$webshop->getGA4MeasurementID()}>',
- <{/if}>
- <{if $webshop->getGooglePlaceID()}>
- 'settings.Google.Place_ID': '<{$webshop->getGooglePlaceID()}>',
- <{/if}>
- <{if $webshop->getPinterestTagID()}>
- 'settings.Pinterest.Tag_ID': '<{$webshop->getPinterestTagID()}>',
- <{/if}>
- <{if $webshop->getSnapPixelID()}>
- 'settings.Snap.Pixel_ID': '<{$webshop->getSnapPixelID()}>',
- <{/if}>
- <{if $webshop->getTikTokPixelID()}>
- 'settings.TikTok.Pixel_ID': '<{$webshop->getTikTokPixelID()}>',
- <{/if}>
- <{if $webshop->getLinkedInID()}>
- 'settings.LinkedIn.Insight_Tag': '<{$webshop->getLinkedInID()}>',
- <{/if}>
- <{if $webshop->getKlaviyoPublicKey()}>
- 'settings.Klaviyo.PublicKey': '<{$webshop->getKlaviyoPublicKey()}>',
- <{/if}>
- <{if $webshop->getCompany()}>
- <{assign var="company" value=$webshop->getCompany()}>
- 'settings.webshopName': '<{$company->getName()|escape}>',
- <{/if}>
- <{if $webshop->getCurrency()}>
- 'settings.currencyCode': '<{$webshop->getCurrency()}>'
- <{/if}>
- });
- </script>
- <{* Theme settings pushed to dataLayer end *}>
- <{* Customer Information start *}>
- <{if $customer && $customer->getEmail()}>
- <script>
- window.dataLayer = window.dataLayer || [];
- window.dataLayer.push({
- event: 'customerInfo',
- 'user.loggedIn': true
- ,'user.email': '<{$customer->getEmail()|escape}>'
- <{if $customer->getCustomerId()}>
- ,'user.ID': '<{$customer->getCustomerId()|escape}>'
- <{/if}>
- <{if $customer->getSubscriptionId()}>
- ,'user.subscriptionId': '<{$customer->getSubscriptionId()|escape}>'
- <{/if}>
- <{if $customer->getPhone()}>
- ,'user.phone': '<{$customer->getPhone()|escape}>'
- <{/if}>
- <{if $customer->getName()}>
- <{assign var="names" value=" "|explode:$customer->getName()|escape}>
- ,'user.name': '<{$customer->getName()|escape}>'
- ,'user.firstName': '<{$names[0]|ucfirst}>'
- ,'user.lastName': '<{$names[1]|ucfirst}>'
- <{/if}>
- <{if $customer->getCompany()}>
- ,'user.companyName': '<{$customer->getCompany()|escape}>'
- <{/if}>
- <{if $customer->getVatNumber()}>
- ,'user.companyVat' : '<{$customer->getVatNumber()|escape}>'
- <{/if}>
- <{if $customer->getAddress()}>
- ,'user.address': '<{$customer->getAddress()|escape}>'
- <{/if}>
- <{if $customer->getZipcode()}>
- ,'user.zipcode': '<{$customer->getZipcode()|escape}>'
- <{/if}>
- <{if $customer->getCity()}>
- ,'user.city': '<{$customer->getCity()|escape}>'
- <{/if}>
- <{if $customer->getCountry()}>
- <{assign var="usercountry" value=$customer->getCountry()}>
- ,'user.country': '<{$usercountry->getName()|escape}>'
- <{/if}>
- <{if $webshop->paidOrders($customer->getEmail())}>
- ,'user.paidOrders': <{$webshop->paidOrders($customer->getEmail())}>
- <{/if}>
- });
- </script>
- <{elseif $order && $order->getEmail()}>
- <script>
- window.dataLayer = window.dataLayer || [];
- window.dataLayer.push({
- event: 'orderInfo',
- 'user.loggedIn': false
- ,'user.email': '<{$order->getEmail()|escape}>'
- <{if $order->getPhone()}>
- ,'user.phone': '<{$order->getPhone()|escape}>'
- <{/if}>
- <{if $order->getOrderName()}>
- <{assign var="names" value=" "|explode:$order->getOrderName()|escape}>
- ,'user.name': '<{$order->getOrderName()|escape}>'
- ,'user.firstName': '<{$names[0]|ucfirst}>'
- ,'user.lastName': '<{$names[1]|ucfirst}>'
- <{/if}>
- <{if $order->getOrderCompanyName()}>
- ,'user.companyName': '<{$order->getOrderCompanyName()|escape}>'
- <{/if}>
- <{if $order->getVatNumber()}>
- ,'user.companyVat' : '<{$order->getVatNumber()|escape}>'
- <{/if}>
- <{if $order->getOrderAddress()}>
- ,'user.address': '<{$order->getOrderAddress()|escape}>'
- <{/if}>
- <{if $order->getOrderZipcode()}>
- ,'user.zipcode': '<{$order->getOrderZipcode()|escape}>'
- <{/if}>
- <{if $order->getOrderCity()}>
- ,'user.city': '<{$order->getOrderCity()|escape}>'
- <{/if}>
- <{if $order->getOrderCountry()}>
- ,'user.country': '<{$order->getOrderCountry()|escape}>'
- <{/if}>
- <{if $order->getDelCountry()}>
- ,'user.delCountry': '<{$order->getDelCountry()|escape}>'
- <{/if}>
- <{if $webshop->paidOrders($order->getEmail())}>
- ,'user.paidOrders': <{$webshop->paidOrders($order->getEmail())}>
- <{/if}>
- });
- </script>
- <{elseif $session_order && $session_order.email}>
- <script>
- window.dataLayer = window.dataLayer || [];
- window.dataLayer.push({
- event: 'sessionInfo',
- 'user.loggedIn': false
- ,'user.email': '<{$session_order.email|escape}>'
- <{if $session_order.phone}>
- ,'user.phone': '<{$session_order.phone|escape}>'
- <{/if}>
- <{if $session_order.name}>
- <{assign var="names" value=" "|explode:$session_order.name|escape}>
- ,'user.name': '<{$session_order.name|escape|ucfirst}>'
- ,'user.firstName': '<{$names[0]|ucfirst}>'
- ,'user.lastName': '<{$names[1]|ucfirst}>'
- <{/if}>
- <{if $session_order.company_name}>
- ,'user.companyName': '<{$session_order.company_name|escape}>'
- <{/if}>
- <{if $session_order.vat_number}>
- ,'user.companyVat': '<{$session_order.vat_number|escape}>'
- <{/if}>
- <{if $session_order.address}>
- ,'user.address': '<{$session_order.address|escape}>'
- <{/if}>
- <{if $session_order.zipcode|escape}>
- ,'user.zipcode': '<{$session_order.zipcode|escape}>'
- <{/if}>
- <{if $session_order.city}>
- ,'user.city': '<{$session_order.city|escape|ucfirst}>'
- <{/if}>
- <{if $session_order.country_name}>
- ,'user.country': '<{$session_order.country_name|escape|ucfirst}>'
- <{/if}>
- <{if $webshop->paidOrders($session_order.email)}>
- ,'user.paidOrders': <{$webshop->paidOrders($session_order.email)}>
- <{/if}>
- });
- </script>
- <{/if}>
- <{* Customer Information end *}>
- <{* Category dataLayer start *}>
- <{if $category}>
- <{if $category->isFront()}>
- <{assign var="products" value=$category->getOnlineProducts()}>
- <{/if}>
- <{* GA4 View item list:
- https://developers.google.com/analytics/devguides/collection/ga4/ecommerce?client_type=gtm#view_item_list
- https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtm#view_item_list
- https://www.simoahava.com/analytics/google-analytics-4-ecommerce-guide-google-tag-manager/#view_item_list
- *}>
- <script>
- window.dataLayer = window.dataLayer || [];
- window.dataLayer.push({ ecommerce: null });
- window.dataLayer.push({
- event: 'view_item_list',
- ecommerce: {
- items: [
- <{section name='catimpr' loop=$products max=10}>
- {
- <{if $products[catimpr]->getProductId()}>
- item_id: '<{$products[catimpr]->getProductId()}>',
- <{/if}>
- <{if $products[catimpr]->getName()}>
- item_name: '<{$products[catimpr]->getName()|escape}>',
- <{/if}>
- <{if $webshop->getName()}>
- affiliation: '<{$webshop->getName()|escape}>',
- <{/if}>
- currency: '<{$webshop->getCurrency()}>',
- index: <{$smarty.section.catimpr.index}>,
- <{if $products[catimpr]->getBrand()}>
- item_brand: '<{$products[catimpr]->getBrandName()|escape}>',
- <{/if}>
- <{if $products[catimpr]->getMainCategory()}>
- <{assign var="prodmaincat" value=$products[catimpr]->getMainCategory()}>
- <{if $prodmaincat->getParents()}>
- <{assign var="prodmaincatparents" value=$prodmaincat->getParents()}>
- <{assign var="catlevel" value=0}>
- <{section name="parents" loop=$prodmaincatparents max=5}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- <{if $smarty.section.parents.first}>
- item_category: '<{$prodmaincatparents[parents]->getName()|escape}>',
- <{else}>
- item_category<{$catlevel}>: '<{$prodmaincatparents[parents]->getName()|escape}>',
- <{/if}>
- <{/section}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- item_category<{$catlevel}>: '<{$products[catimpr]->getMainCategoryName()|escape}>',
- <{else}>
- item_category: '<{$products[catimpr]->getMainCategoryName()|escape}>',
- <{/if}>
- <{elseif $products[catimpr]->getCategory()}>
- <{assign var="prodcat" value=$products[catimpr]->getCategory()}>
- <{if $prodcat->getParents()}>
- <{assign var="prodcatparents" value=$prodcat->getParents()}>
- <{assign var="catlevel" value=0}>
- <{section name="parents" loop=$prodcatparents max=5}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- <{if $smarty.section.parents.first}>
- item_category: '<{$prodcatparents[parents]->getName()|escape}>',
- <{else}>
- item_category<{$catlevel}>: '<{$prodcatparents[parents]->getName()|escape}>',
- <{/if}>
- <{/section}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- item_category<{$catlevel}>: '<{$products[catimpr]->getCategoryName()|escape}>',
- <{else}>
- item_category: '<{$products[catimpr]->getCategoryName()|escape}>',
- <{/if}>
- <{/if}>
- <{if $category->getCategoryId()}>
- item_list_id: '<{$category->getCategoryId()}>',
- <{/if}>
- <{if $category->getName()|escape}>
- item_list_name: '<{$category->getName()|escape}>',
- <{/if}>
- <{if $webshop->getGooglePlaceID()}>
- location_id: '<{$webshop->getGooglePlaceID()}>',
- <{/if}>
- <{if $products[catimpr]->getRealPrice()}>
- price: <{$products[catimpr]->getRealPrice()|number_format:2:".":""}>,
- <{/if}>
- quantity: 1
- }
- <{if !$smarty.section.catimpr.last}>,<{/if}>
- <{/section}>
- ]
- }
- });
- </script>
- <{/if}>
- <{* Category dataLayer end *}>
- <{* Landingpage dataLayer start *}>
- <{if $landing_page}>
- <{* GA4 View item list:
- https://developers.google.com/analytics/devguides/collection/ga4/ecommerce?client_type=gtm#view_item_list
- https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtm#view_item_list
- https://www.simoahava.com/analytics/google-analytics-4-ecommerce-guide-google-tag-manager/#view_item_list
- *}>
- <script>
- window.dataLayer = window.dataLayer || [];
- window.dataLayer.push({ ecommerce: null });
- window.dataLayer.push({
- event: 'view_item_list',
- ecommerce: {
- items: [
- <{section name='lpimpr' loop=$products max=10}>
- {
- <{if $products[lpimpr]->getProductId()}>
- item_id: '<{$products[lpimpr]->getProductId()}>',
- <{/if}>
- <{if $products[lpimpr]->getName()}>
- item_name: '<{$products[lpimpr]->getName()|escape}>',
- <{/if}>
- <{if $webshop->getName()}>
- affiliation: '<{$webshop->getName()|escape}>',
- <{/if}>
- currency: '<{$webshop->getCurrency()}>',
- index: <{$smarty.section.lpimpr.index}>,
- <{if $products[lpimpr]->getBrand()}>
- item_brand: '<{$products[lpimpr]->getBrandName()|escape}>',
- <{/if}>
- <{if $products[lpimpr]->getMainCategory()}>
- <{assign var="prodmaincat" value=$products[lpimpr]->getMainCategory()}>
- <{if $prodmaincat->getParents()}>
- <{assign var="prodmaincatparents" value=$prodmaincat->getParents()}>
- <{assign var="catlevel" value=0}>
- <{section name="parents" loop=$prodmaincatparents max=5}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- <{if $smarty.section.parents.first}>
- item_category: '<{$prodmaincatparents[parents]->getName()|escape}>',
- <{else}>
- item_category<{$catlevel}>: '<{$prodmaincatparents[parents]->getName()|escape}>',
- <{/if}>
- <{/section}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- item_category<{$catlevel}>: '<{$products[lpimpr]->getMainCategoryName()|escape}>',
- <{else}>
- item_category: '<{$products[lpimpr]->getMainCategoryName()|escape}>',
- <{/if}>
- <{elseif $products[lpimpr]->getCategory()}>
- <{assign var="prodcat" value=$products[lpimpr]->getCategory()}>
- <{if $prodcat->getParents()}>
- <{assign var="prodcatparents" value=$prodcat->getParents()}>
- <{assign var="catlevel" value=0}>
- <{section name="parents" loop=$prodcatparents max=5}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- <{if $smarty.section.parents.first}>
- item_category: '<{$prodcatparents[parents]->getName()|escape}>',
- <{else}>
- item_category<{$catlevel}>: '<{$prodcatparents[parents]->getName()|escape}>',
- <{/if}>
- <{/section}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- item_category<{$catlevel}>: '<{$products[lpimpr]->getCategoryName()|escape}>',
- <{else}>
- item_category: '<{$products[lpimpr]->getCategoryName()|escape}>',
- <{/if}>
- <{/if}>
- <{if $landing_page->getLandingPageId()}>
- item_list_id: '<{$landing_page->getLandingPageId()}>',
- <{/if}>
- <{if $landing_page->getName()}>
- item_list_name: '<{$landing_page->getName()|escape}>',
- <{/if}>
- <{if $webshop->getGooglePlaceID()}>
- location_id: '<{$webshop->getGooglePlaceID()}>',
- <{/if}>
- <{if $products[lpimpr]->getRealPrice()}>
- price: <{$products[lpimpr]->getRealPrice()|number_format:2:".":""}>,
- <{/if}>
- quantity: 1
- }
- <{if !$smarty.section.lpimpr.last}>,<{/if}>
- <{/section}>
- ]
- }
- });
- </script>
- <{/if}>
- <{* Landingpage dataLayer end *}>
- <{* Search dataLayer start *}>
- <{if $inc == "search.html"}>
- <{* GA4 search:
- https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtm#search
- *}>
- <script>
- window.dataLayer = window.dataLayer || [];
- window.dataLayer.push({ ecommerce: null });
- window.dataLayer.push({
- event: 'search',
- search_term: '<{$get.search}>'
- });
- </script>
- <{/if}>
- <{* Search dataLayer end *}>
- <{* Product dataLayer start *}>
- <{if $product}>
- <{* GA4 View item:
- https://developers.google.com/analytics/devguides/collection/ga4/ecommerce?client_type=gtm#view_item
- https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtm#view_item
- https://www.simoahava.com/analytics/google-analytics-4-ecommerce-guide-google-tag-manager/#view_item
- *}>
- <script>
- window.dataLayer = window.dataLayer || [];
- window.dataLayer.push({ ecommerce: null });
- window.dataLayer.push({
- event: 'view_item',
- ecommerce: {
- items: [{
- <{if $product->getProductId()}>
- item_id: '<{$product->getProductId()}>',
- <{/if}>
- <{if $product->getName()}>
- item_name: '<{$product->getName()|escape}>',
- <{/if}>
- <{if $webshop->getName()}>
- affiliation: '<{$webshop->getName()|escape}>',
- <{/if}>
- currency: '<{$webshop->getCurrency()}>',
- index: 0,
- <{if $product->getBrand()}>
- item_brand: '<{$product->getBrandName()|escape}>',
- <{/if}>
- <{if $product->getMainCategory()}>
- <{assign var="prodmaincat" value=$product->getMainCategory()}>
- <{if $prodmaincat->getParents()}>
- <{assign var="prodmaincatparents" value=$prodmaincat->getParents()}>
- <{assign var="catlevel" value=0}>
- <{section name="parents" loop=$prodmaincatparents max=5}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- <{if $smarty.section.parents.first}>
- item_category: '<{$prodmaincatparents[parents]->getName()|escape}>',
- <{else}>
- item_category<{$catlevel}>: '<{$prodmaincatparents[parents]->getName()|escape}>',
- <{/if}>
- <{/section}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- item_category<{$catlevel}>: '<{$product->getMainCategoryName()|escape}>',
- <{else}>
- item_category: '<{$product->getMainCategoryName()|escape}>',
- <{/if}>
- <{elseif $product->getCategory()}>
- <{assign var="prodcat" value=$product->getCategory()}>
- <{if $prodcat->getParents()}>
- <{assign var="prodcatparents" value=$prodcat->getParents()}>
- <{assign var="catlevel" value=0}>
- <{section name="parents" loop=$prodcatparents max=5}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- <{if $smarty.section.parents.first}>
- item_category: '<{$prodcatparents[parents]->getName()|escape}>',
- <{else}>
- item_category<{$catlevel}>: '<{$prodcatparents[parents]->getName()|escape}>',
- <{/if}>
- <{/section}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- item_category<{$catlevel}>: '<{$product->getCategoryName()|escape}>',
- <{else}>
- item_category: '<{$product->getCategoryName()|escape}>',
- <{/if}>
- <{/if}>
- <{* TODO: add item_variant for products with attribute in URL *}>
- <{if $webshop->getGooglePlaceID()}>
- location_id: '<{$webshop->getGooglePlaceID()}>',
- <{/if}>
- <{if $product->getRealPrice()}>
- price: <{$product->getRealPrice()|number_format:2:".":""}>,
- <{/if}>
- quantity: 1
- }]
- }
- });
- </script>
- <{* GA4 Add to cart:
- https://developers.google.com/analytics/devguides/collection/ga4/ecommerce?client_type=gtm#add_to_cart
- https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtm#add_to_cart
- https://www.simoahava.com/analytics/google-analytics-4-ecommerce-guide-google-tag-manager/#add_to_cart
- *}>
- <script>
- document.addEventListener("DOMContentLoaded", function (event) {
- var formId = document.querySelector('#basket_form');
- var quantityId = document.querySelector('#qty');
- formId.addEventListener("submit", function(evt) {
- <{if $product->hasVariant()}>
- var variantList = document.getElementById('attributes');
- var variantName = variantList.options[variantList.selectedIndex].dataset.item_variant;
- <{/if}>
- window.dataLayer = window.dataLayer || [];
- window.dataLayer.push({ ecommerce: null });
- window.dataLayer.push({
- event: 'add_to_cart',
- ecommerce: {
- currency: '<{$webshop->getCurrency()}>',
- value: <{$product->getRealPrice()|number_format:2:".":""}> * quantityId.value,
- items: [{
- <{if $product->hasVariant()}>
- item_id: '<{$product->getProductId()}>:' + variantList.value,
- item_variant: variantName,
- <{elseif $product->getProductId()}>
- item_id: '<{$product->getProductId()}>',
- <{/if}>
- <{if $product->getName()}>
- item_name: '<{$product->getName()|escape}>',
- <{/if}>
- <{if $webshop->getName()}>
- affiliation: '<{$webshop->getName()|escape}>',
- <{/if}>
- currency: '<{$webshop->getCurrency()}>',
- index: 0,
- <{if $product->getBrand()}>
- item_brand: '<{$product->getBrandName()|escape}>',
- <{/if}>
- <{if $product->getMainCategory()}>
- <{assign var="prodmaincat" value=$product->getMainCategory()}>
- <{if $prodmaincat->getParents()}>
- <{assign var="prodmaincatparents" value=$prodmaincat->getParents()}>
- <{assign var="catlevel" value=0}>
- <{section name="parents" loop=$prodmaincatparents max=5}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- <{if $smarty.section.parents.first}>
- item_category: '<{$prodmaincatparents[parents]->getName()|escape}>',
- <{else}>
- item_category<{$catlevel}>: '<{$prodmaincatparents[parents]->getName()|escape}>',
- <{/if}>
- <{/section}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- item_category<{$catlevel}>: '<{$product->getMainCategoryName()|escape}>',
- <{else}>
- item_category: '<{$product->getMainCategoryName()|escape}>',
- <{/if}>
- <{elseif $product->getCategory()}>
- <{assign var="prodcat" value=$product->getCategory()}>
- <{if $prodcat->getParents()}>
- <{assign var="prodcatparents" value=$prodcat->getParents()}>
- <{assign var="catlevel" value=0}>
- <{section name="parents" loop=$prodcatparents max=5}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- <{if $smarty.section.parents.first}>
- item_category: '<{$prodcatparents[parents]->getName()|escape}>',
- <{else}>
- item_category<{$catlevel}>: '<{$prodcatparents[parents]->getName()|escape}>',
- <{/if}>
- <{/section}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- item_category<{$catlevel}>: '<{$product->getCategoryName()|escape}>',
- <{else}>
- item_category: '<{$product->getCategoryName()|escape}>',
- <{/if}>
- <{/if}>
- <{if $webshop->getGooglePlaceID()}>
- location_id: '<{$webshop->getGooglePlaceID()}>',
- <{/if}>
- <{if $product->getRealPrice()}>
- price: <{$product->getRealPrice()|number_format:2:".":""}>,
- <{/if}>
- quantity: quantityId.value
- }]
- }
- });
- });
- });
- </script>
- <{/if}>
- <{* Product dataLayer end *}>
- <{* Product listing pages start *}>
- <{if $category || $landing_page || $inc == "search.html" || $inc == "basket.html" || $inc == "product.html"}>
- <{* GA4 Select item:
- https://developers.google.com/analytics/devguides/collection/ga4/ecommerce?client_type=gtm#select_item
- https://www.simoahava.com/analytics/google-analytics-4-ecommerce-guide-google-tag-manager/#select_item
- https://medium.com/@sbuckpesch/2-steps-to-a-complete-enhanced-e-commerce-conversion-setup-in-google-analytics-using-google-tag-50cc9d09ab51
- *}>
- <script type="application/javascript">
- document.addEventListener("click", function(event) {
- if (event.target.classList.contains('productEntityClick') || event.target.parentNode.parentNode.classList.contains('productEntityClick')) {
- trackProductClickEvent(event.target, 'select_item')
- }
- if (event.target.classList.contains('productEntityAddToCart')) {
- trackProductClickEvent(event.target, 'add_to_cart')
- }
- if (event.target.classList.contains('productEntityRemoveFromCart')) {
- trackProductClickEvent(event.target, 'remove_from_cart')
- }
- if (event.target.classList.contains('productEntityIncreaseCart')) {
- trackProductClickEvent(event.target, 'IncreaseCart')
- }
- if (event.target.classList.contains('productEntityDecreaseCart')) {
- trackProductClickEvent(event.target, 'DecreaseCart')
- }
- });
- function findAncestor(el, selector) {
- while ((el = el.parentElement) && !((el.matches || el.matchesSelector).call(el, selector))) ;
- return el;
- }
- function trackProductClickEvent(clickedElement, event) {
- var productEntity = findAncestor(clickedElement, '.productEntity');
- if (productEntity) {
- var productKeyMapping = {
- 'item_id': 'item_id',
- 'item_name': 'item_name',
- 'affiliation': 'affiliation',
- 'currency': 'currency',
- 'index': 'index',
- 'item_brand': 'item_brand',
- 'item_category': 'item_category',
- 'item_category2': 'item_category2',
- 'item_category3': 'item_category3',
- 'item_category4': 'item_category4',
- 'item_category5': 'item_category5',
- 'item_list_id': 'item_list_id',
- 'item_list_name': 'item_list_name',
- 'item_variant': 'item_variant',
- 'location_id': 'location_id',
- 'price': 'price',
- 'quantity': 'quantity'
- };
- var productData = {};
- var keys = Object.keys(productKeyMapping);
- keys.forEach(function (key) {
- if (typeof productEntity.dataset[key] !== 'undefined') {
- productData[productKeyMapping[key]] = productEntity.dataset[key];
- }
- });
- var ecommerceData = {};
- switch (event) {
- case 'select_item':
- ecommerceData = {
- items: [productData]
- };
- window.dataLayer = window.dataLayer || [];
- window.dataLayer.push({ ecommerce: null });
- window.dataLayer.push({
- 'event': event,
- 'ecommerce': ecommerceData
- });
- break;
- case 'add_to_cart':
- productData.quantity = 1;
- ecommerceData = {
- items: [productData],
- currency: '<{$webshop->getCurrency()}>',
- value: [productData.price] * [productData.quantity]
- };
- window.dataLayer = window.dataLayer || [];
- window.dataLayer.push({ ecommerce: null });
- window.dataLayer.push({
- 'event': event,
- 'ecommerce': ecommerceData
- });
- break;
- case 'remove_from_cart':
- ecommerceData = {
- items: [productData],
- currency: '<{$webshop->getCurrency()}>',
- value: [productData.price] * [productData.quantity]
- };
- window.dataLayer = window.dataLayer || [];
- window.dataLayer.push({ ecommerce: null });
- window.dataLayer.push({
- 'event': event,
- 'ecommerce': ecommerceData
- });
- break;
- case 'IncreaseCart':
- productData.quantity = 1;
- ecommerceData = {
- items: [productData],
- currency: '<{$webshop->getCurrency()}>',
- value: [productData.price] * [productData.quantity]
- };
- window.dataLayer = window.dataLayer || [];
- window.dataLayer.push({ ecommerce: null });
- window.dataLayer.push({
- 'event': 'add_to_cart',
- 'ecommerce': ecommerceData
- });
- break;
- case 'DecreaseCart':
- productData.quantity = 1;
- ecommerceData = {
- items: [productData],
- currency: '<{$webshop->getCurrency()}>',
- value: [productData.price] * [productData.quantity]
- };
- window.dataLayer = window.dataLayer || [];
- window.dataLayer.push({ ecommerce: null });
- window.dataLayer.push({
- 'event': 'remove_from_cart',
- 'ecommerce': ecommerceData
- });
- break;
- }
- }
- }
- </script>
- <{/if}>
- <{* Product listing pages end *}>
- <{* Basket dataLayer start *}>
- <{if $inc == "basket.html"}>
- <{* GA4 View cart:
- https://developers.google.com/analytics/devguides/collection/ga4/ecommerce?client_type=gtm#view_cart
- https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtm#view_cart
- https://www.simoahava.com/analytics/google-analytics-4-ecommerce-guide-google-tag-manager/#view_cart
- *}>
- <script>
- window.dataLayer = window.dataLayer || [];
- window.dataLayer.push({ ecommerce: null });
- window.dataLayer.push({
- event: 'view_cart',
- ecommerce: {
- currency: '<{$webshop->getCurrency()}>',
- value: <{$total_price|number_format:2:".":""}>,
- items: [
- <{section name=basketimpr loop=$basket}>
- <{assign var="checkoutproduct" value=$basket[basketimpr].product}>
- <{assign var=attributes value=$basket[basketimpr].attributes}>
- {
- <{if $attributes|@count == 1}>
- <{section name="j" loop=$attributes}>
- item_id: '<{$checkoutproduct->getProductId()}>:<{$attributes[j].value_id}>',
- item_variant: '<{$attributes[j].value}>',
- <{/section}>
- <{else}>
- <{if $checkoutproduct->getProductId()}>
- item_id: '<{$checkoutproduct->getProductId()}>',
- <{/if}>
- <{/if}>
- <{if $checkoutproduct->getName()}>
- item_name: '<{$checkoutproduct->getName()|escape}>',
- <{/if}>
- <{if $webshop->getName()}>
- affiliation: '<{$webshop->getName()|escape}>',
- <{/if}>
- <{if $voucher}>
- coupon: '<{$voucher->getCode()|escape}>',
- <{/if}>
- currency: '<{$webshop->getCurrency()}>',
- index: <{$smarty.section.basketimpr.index}>,
- <{if $checkoutproduct->getBrand()}>
- item_brand: '<{$checkoutproduct->getBrandName()|escape}>',
- <{/if}>
- <{if $checkoutproduct->getMainCategory()}>
- <{assign var="prodmaincat" value=$checkoutproduct->getMainCategory()}>
- <{if $prodmaincat->getParents()}>
- <{assign var="prodmaincatparents" value=$prodmaincat->getParents()}>
- <{assign var="catlevel" value=0}>
- <{section name="parents" loop=$prodmaincatparents max=5}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- <{if $smarty.section.parents.first}>
- item_category: '<{$prodmaincatparents[parents]->getName()|escape}>',
- <{else}>
- item_category<{$catlevel}>: '<{$prodmaincatparents[parents]->getName()|escape}>',
- <{/if}>
- <{/section}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- item_category<{$catlevel}>: '<{$checkoutproduct->getMainCategoryName()|escape}>',
- <{else}>
- item_category: '<{$checkoutproduct->getMainCategoryName()|escape}>',
- <{/if}>
- <{elseif $checkoutproduct->getCategory()}>
- <{assign var="prodcat" value=$checkoutproduct->getCategory()}>
- <{if $prodcat->getParents()}>
- <{assign var="prodcatparents" value=$prodcat->getParents()}>
- <{assign var="catlevel" value=0}>
- <{section name="parents" loop=$prodcatparents max=5}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- <{if $smarty.section.parents.first}>
- item_category: '<{$prodcatparents[parents]->getName()|escape}>',
- <{else}>
- item_category<{$catlevel}>: '<{$prodcatparents[parents]->getName()|escape}>',
- <{/if}>
- <{/section}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- item_category<{$catlevel}>: '<{$checkoutproduct->getCategoryName()|escape}>',
- <{else}>
- item_category: '<{$checkoutproduct->getCategoryName()|escape}>',
- <{/if}>
- <{/if}>
- <{if $webshop->getGooglePlaceID()}>
- location_id: '<{$webshop->getGooglePlaceID()}>',
- <{/if}>
- <{if $checkoutproduct->getPrice()}>
- price: <{$checkoutproduct->getPrice()|number_format:2:".":""}>,
- <{/if}>
- quantity: <{$basket[basketimpr].amount}>
- }
- <{if !$smarty.section.basketimpr.last}>,<{/if}>
- <{/section}>
- ]
- }
- });
- </script>
- <{/if}>
- <{* Basket dataLayer end *}>
- <{* Address dataLayer start *}>
- <{if $inc == "address.html"}>
- <{* GA4 Begin checkout:
- https://developers.google.com/analytics/devguides/collection/ga4/ecommerce?client_type=gtm#begin_checkout
- https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtm#begin_checkout
- https://www.simoahava.com/analytics/google-analytics-4-ecommerce-guide-google-tag-manager/#begin_checkout
- *}>
- <script>
- window.dataLayer = window.dataLayer || [];
- window.dataLayer.push({ ecommerce: null });
- window.dataLayer.push({
- event: 'begin_checkout',
- ecommerce: {
- currency: '<{$webshop->getCurrency()}>',
- value: <{$total_price|number_format:2:".":""}>,
- <{if $voucher}>
- coupon: '<{$voucher->getCode()|escape}>',
- <{/if}>
- items: [
- <{section name=basketimpr loop=$basket}>
- <{assign var="checkoutproduct" value=$basket[basketimpr].product}>
- <{assign var=attributes value=$basket[basketimpr].attributes}>
- {
- <{if $attributes|@count == 1}>
- <{section name="j" loop=$attributes}>
- item_id: '<{$checkoutproduct->getProductId()}>:<{$attributes[j].value_id}>',
- item_variant: '<{$attributes[j].value}>',
- <{/section}>
- <{else}>
- <{if $checkoutproduct->getProductId()}>
- item_id: '<{$checkoutproduct->getProductId()}>',
- <{/if}>
- <{/if}>
- <{if $checkoutproduct->getName()}>
- item_name: '<{$checkoutproduct->getName()|escape}>',
- <{/if}>
- <{if $webshop->getName()}>
- affiliation: '<{$webshop->getName()|escape}>',
- <{/if}>
- <{if $voucher}>
- coupon: '<{$voucher->getCode()|escape}>',
- <{/if}>
- currency: '<{$webshop->getCurrency()}>',
- index: <{$smarty.section.basketimpr.index}>,
- <{if $checkoutproduct->getBrand()}>
- item_brand: '<{$checkoutproduct->getBrandName()|escape}>',
- <{/if}>
- <{if $checkoutproduct->getMainCategory()}>
- <{assign var="prodmaincat" value=$checkoutproduct->getMainCategory()}>
- <{if $prodmaincat->getParents()}>
- <{assign var="prodmaincatparents" value=$prodmaincat->getParents()}>
- <{assign var="catlevel" value=0}>
- <{section name="parents" loop=$prodmaincatparents max=5}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- <{if $smarty.section.parents.first}>
- item_category: '<{$prodmaincatparents[parents]->getName()|escape}>',
- <{else}>
- item_category<{$catlevel}>: '<{$prodmaincatparents[parents]->getName()|escape}>',
- <{/if}>
- <{/section}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- item_category<{$catlevel}>: '<{$checkoutproduct->getMainCategoryName()|escape}>',
- <{else}>
- item_category: '<{$checkoutproduct->getMainCategoryName()|escape}>',
- <{/if}>
- <{elseif $checkoutproduct->getCategory()}>
- <{assign var="prodcat" value=$checkoutproduct->getCategory()}>
- <{if $prodcat->getParents()}>
- <{assign var="prodcatparents" value=$prodcat->getParents()}>
- <{assign var="catlevel" value=0}>
- <{section name="parents" loop=$prodcatparents max=5}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- <{if $smarty.section.parents.first}>
- item_category: '<{$prodcatparents[parents]->getName()|escape}>',
- <{else}>
- item_category<{$catlevel}>: '<{$prodcatparents[parents]->getName()|escape}>',
- <{/if}>
- <{/section}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- item_category<{$catlevel}>: '<{$checkoutproduct->getCategoryName()|escape}>',
- <{else}>
- item_category: '<{$checkoutproduct->getCategoryName()|escape}>',
- <{/if}>
- <{/if}>
- <{if $webshop->getGooglePlaceID()}>
- location_id: '<{$webshop->getGooglePlaceID()}>',
- <{/if}>
- <{if $checkoutproduct->getPrice()}>
- price: <{$checkoutproduct->getPrice()|number_format:2:".":""}>,
- <{/if}>
- quantity: <{$basket[basketimpr].amount}>
- }
- <{if !$smarty.section.basketimpr.last}>,<{/if}>
- <{/section}>
- ]
- }
- });
- </script>
- <{/if}>
- <{* Address dataLayer end *}>
- <{* Shipping dataLayer start *}>
- <{if $inc == "shipping.html"}>
- <{* GA4 Add shipping information:
- https://developers.google.com/analytics/devguides/collection/ga4/ecommerce?client_type=gtm#add_shipping_info
- https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtm#add_shipping_info
- https://www.simoahava.com/analytics/google-analytics-4-ecommerce-guide-google-tag-manager/#add_shipping_info
- *}>
- <script>
- document.addEventListener("DOMContentLoaded", function (event) {
- var formId = document.querySelector('#shipping_form');
- formId.addEventListener("submit", function(evt) {
- var selectShipping = document.querySelector('[name=shipping_id]:checked');
- window.dataLayer = window.dataLayer || [];
- window.dataLayer.push({ ecommerce: null });
- window.dataLayer.push({
- event: 'add_shipping_info',
- ecommerce: {
- currency: '<{$webshop->getCurrency()}>',
- value: <{$total_price|number_format:2:".":""}>,
- <{if $voucher}>
- coupon: '<{$voucher->getCode()|escape}>',
- <{/if}>
- shipping_tier: selectShipping.dataset.shipping_name.toString(),
- items: [
- <{section name=basketimpr loop=$basket}>
- <{assign var="checkoutproduct" value=$basket[basketimpr].product}>
- <{assign var=attributes value=$basket[basketimpr].attributes}>
- {
- <{if $attributes|@count == 1}>
- <{section name="j" loop=$attributes}>
- item_id: '<{$checkoutproduct->getProductId()}>:<{$attributes[j].value_id}>',
- item_variant: '<{$attributes[j].value}>',
- <{/section}>
- <{else}>
- <{if $checkoutproduct->getProductId()}>
- item_id: '<{$checkoutproduct->getProductId()}>',
- <{/if}>
- <{/if}>
- <{if $checkoutproduct->getName()}>
- item_name: '<{$checkoutproduct->getName()|escape}>',
- <{/if}>
- <{if $webshop->getName()}>
- affiliation: '<{$webshop->getName()|escape}>',
- <{/if}>
- <{if $voucher}>
- coupon: '<{$voucher->getCode()|escape}>',
- <{/if}>
- currency: '<{$webshop->getCurrency()}>',
- index: <{$smarty.section.basketimpr.index}>,
- <{if $checkoutproduct->getBrand()}>
- item_brand: '<{$checkoutproduct->getBrandName()|escape}>',
- <{/if}>
- <{if $checkoutproduct->getMainCategory()}>
- <{assign var="prodmaincat" value=$checkoutproduct->getMainCategory()}>
- <{if $prodmaincat->getParents()}>
- <{assign var="prodmaincatparents" value=$prodmaincat->getParents()}>
- <{assign var="catlevel" value=0}>
- <{section name="parents" loop=$prodmaincatparents max=5}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- <{if $smarty.section.parents.first}>
- item_category: '<{$prodmaincatparents[parents]->getName()|escape}>',
- <{else}>
- item_category<{$catlevel}>: '<{$prodmaincatparents[parents]->getName()|escape}>',
- <{/if}>
- <{/section}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- item_category<{$catlevel}>: '<{$checkoutproduct->getMainCategoryName()|escape}>',
- <{else}>
- item_category: '<{$checkoutproduct->getMainCategoryName()|escape}>',
- <{/if}>
- <{elseif $checkoutproduct->getCategory()}>
- <{assign var="prodcat" value=$checkoutproduct->getCategory()}>
- <{if $prodcat->getParents()}>
- <{assign var="prodcatparents" value=$prodcat->getParents()}>
- <{assign var="catlevel" value=0}>
- <{section name="parents" loop=$prodcatparents max=5}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- <{if $smarty.section.parents.first}>
- item_category: '<{$prodcatparents[parents]->getName()|escape}>',
- <{else}>
- item_category<{$catlevel}>: '<{$prodcatparents[parents]->getName()|escape}>',
- <{/if}>
- <{/section}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- item_category<{$catlevel}>: '<{$checkoutproduct->getCategoryName()|escape}>',
- <{else}>
- item_category: '<{$checkoutproduct->getCategoryName()|escape}>',
- <{/if}>
- <{/if}>
- <{if $webshop->getGooglePlaceID()}>
- location_id: '<{$webshop->getGooglePlaceID()}>',
- <{/if}>
- <{if $checkoutproduct->getPrice()}>
- price: <{$checkoutproduct->getPrice()|number_format:2:".":""}>,
- <{/if}>
- quantity: <{$basket[basketimpr].amount}>
- }
- <{if !$smarty.section.basketimpr.last}>,<{/if}>
- <{/section}>
- ]
- }
- });
- });
- });
- </script>
- <{/if}>
- <{* Shipping dataLayer end *}>
- <{* Approve dataLayer start *}>
- <{if ($webshop->getSkipApprove() && $inc == "address.html") || ($webshop->getSkipApprove() && $inc == "shipping.html") || $inc == "approve.html"}>
- <{* GA4 Add payment information:
- https://developers.google.com/analytics/devguides/collection/ga4/ecommerce?client_type=gtm#add_payment_info
- https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtm#add_payment_info
- https://www.simoahava.com/analytics/google-analytics-4-ecommerce-guide-google-tag-manager/#add_payment_info
- *}>
- <script>
- document.addEventListener("click", function(event) {
- if (event.target.classList.contains('paymentStep')) {
- var selectPayment = document.querySelector('[name=payment_gateway_id]:checked');
- window.dataLayer = window.dataLayer || [];
- window.dataLayer.push({ ecommerce: null });
- window.dataLayer.push({
- event: 'add_payment_info',
- ecommerce: {
- currency: '<{$webshop->getCurrency()}>',
- value: <{$total_price|number_format:2:".":""}>,
- <{if $voucher}>
- coupon: '<{$voucher->getCode()|escape}>',
- <{/if}>
- payment_type: selectPayment.dataset.payment_name.toString(),
- items: [
- <{section name=basketimpr loop=$basket}>
- <{assign var="checkoutproduct" value=$basket[basketimpr].product}>
- <{assign var=attributes value=$basket[basketimpr].attributes}>
- {
- <{if $attributes|@count == 1}>
- <{section name="j" loop=$attributes}>
- item_id: '<{$checkoutproduct->getProductId()}>:<{$attributes[j].value_id}>',
- item_variant: '<{$attributes[j].value}>',
- <{/section}>
- <{else}>
- <{if $checkoutproduct->getProductId()}>
- item_id: '<{$checkoutproduct->getProductId()}>',
- <{/if}>
- <{/if}>
- <{if $checkoutproduct->getName()}>
- item_name: '<{$checkoutproduct->getName()|escape}>',
- <{/if}>
- <{if $webshop->getName()}>
- affiliation: '<{$webshop->getName()|escape}>',
- <{/if}>
- <{if $voucher}>
- coupon: '<{$voucher->getCode()|escape}>',
- <{/if}>
- currency: '<{$webshop->getCurrency()}>',
- index: <{$smarty.section.basketimpr.index}>,
- <{if $checkoutproduct->getBrand()}>
- item_brand: '<{$checkoutproduct->getBrandName()|escape}>',
- <{/if}>
- <{if $checkoutproduct->getMainCategory()}>
- <{assign var="prodmaincat" value=$checkoutproduct->getMainCategory()}>
- <{if $prodmaincat->getParents()}>
- <{assign var="prodmaincatparents" value=$prodmaincat->getParents()}>
- <{assign var="catlevel" value=0}>
- <{section name="parents" loop=$prodmaincatparents max=5}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- <{if $smarty.section.parents.first}>
- item_category: '<{$prodmaincatparents[parents]->getName()|escape}>',
- <{else}>
- item_category<{$catlevel}>: '<{$prodmaincatparents[parents]->getName()|escape}>',
- <{/if}>
- <{/section}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- item_category<{$catlevel}>: '<{$checkoutproduct->getMainCategoryName()|escape}>',
- <{else}>
- item_category: '<{$checkoutproduct->getMainCategoryName()|escape}>',
- <{/if}>
- <{elseif $checkoutproduct->getCategory()}>
- <{assign var="prodcat" value=$checkoutproduct->getCategory()}>
- <{if $prodcat->getParents()}>
- <{assign var="prodcatparents" value=$prodcat->getParents()}>
- <{assign var="catlevel" value=0}>
- <{section name="parents" loop=$prodcatparents max=5}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- <{if $smarty.section.parents.first}>
- item_category: '<{$prodcatparents[parents]->getName()|escape}>',
- <{else}>
- item_category<{$catlevel}>: '<{$prodcatparents[parents]->getName()|escape}>',
- <{/if}>
- <{/section}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- item_category<{$catlevel}>: '<{$checkoutproduct->getCategoryName()|escape}>',
- <{else}>
- item_category: '<{$checkoutproduct->getCategoryName()|escape}>',
- <{/if}>
- <{/if}>
- <{if $webshop->getGooglePlaceID()}>
- location_id: '<{$webshop->getGooglePlaceID()}>',
- <{/if}>
- <{if $checkoutproduct->getPrice()}>
- price: <{$checkoutproduct->getPrice()|number_format:2:".":""}>,
- <{/if}>
- quantity: <{$basket[basketimpr].amount}>
- }
- <{if !$smarty.section.basketimpr.last}>,<{/if}>
- <{/section}>
- ]
- }
- });
- }
- });
- </script>
- <{/if}>
- <{* Approve dataLayer end *}>
- <{* Thanks dataLayer start *}>
- <{if $inc == "thanks.html" && $order}>
- <{* Only once start *}>
- <{if !$order->getTrackingCalled()}>
- <{assign var="products" value=$order->getProducts()}>
- <{assign var="orderproducts" value=$order->getOrderProducts()}>
- <{assign var="totaldiscount" value=0}>
- <{* GA4 Purchase:
- https://developers.google.com/analytics/devguides/collection/ga4/ecommerce?client_type=gtm#purchase
- https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtm#purchase
- https://www.simoahava.com/analytics/google-analytics-4-ecommerce-guide-google-tag-manager/#purchase
- *}>
- <script>
- window.dataLayer = window.dataLayer || [];
- window.dataLayer.push({ ecommerce: null });
- window.dataLayer.push({
- event: 'purchase',
- ecommerce: {
- <{if $webshop->getCurrency()}>
- currency: '<{$webshop->getCurrency()}>',
- <{/if}>
- <{if $order->getWebshopOrderId()}>
- transaction_id: '<{$order->getWebshopOrderId()}>',
- <{/if}>
- <{if $order->getTotalPrice()}>
- value: '<{$order->getTotalPrice()|number_format:2:".":""}>',
- <{/if}>
- <{if $webshop->getName()|escape}>
- affiliation: '<{$webshop->getName()|escape}>',
- <{/if}>
- <{if $order->getVoucherCode()}>
- coupon: '<{$order->getVoucherCode()|escape}>',
- <{/if}>
- <{if $order->getShippingPrice()}>
- shipping: '<{$order->getShippingPrice()|number_format:2:".":""}>',
- <{/if}>
- <{if $order->getVat()}>
- tax: '<{$order->getVat()|number_format:2:".":""}>',
- <{/if}>
- <{* Google Ads Conversion with Cart Data:
- https://support.google.com/google-ads/answer/9028614?hl=en#zippy=%2Cinstall-with-google-tag-manager
- *}>
- <{if $order->getVoucherDiscountAmount()}>
- discount: <{$order->getVoucherDiscountAmount()}>,
- <{/if}>
- <{if $webshop->getGoogleMerchantId()}>
- aw_merchant_id: <{$webshop->getGoogleMerchantId()}>,
- aw_feed_country: 'DK',
- aw_feed_language: 'DA',
- <{/if}>
- items: [
- <{section name=purchaseimpr loop=$orderproducts}>
- <{assign var=attributes value=$orderproducts[purchaseimpr]->getAttributes()}>
- <{assign var="p" value=$orderproducts[purchaseimpr]->getProduct()}>
- <{if $orderproducts[purchaseimpr]->getFromBundle() == "0"}>
- {
- <{if $attributes|@count == 1}>
- <{section name="j" loop=$attributes}>
- item_id: '<{$orderproducts[purchaseimpr]->getProductId()}>:<{$attributes[j].attribute_value_id}>',
- item_variant: '<{$attributes[j].val}>',
- <{/section}>
- <{else}>
- item_id: '<{$orderproducts[purchaseimpr]->getProductId()}>',
- <{/if}>
- item_name: '<{$orderproducts[purchaseimpr]->getName()|escape}>',
- <{if $webshop->getName()}>
- affiliation: '<{$webshop->getName()|escape}>',
- <{/if}>
- <{if $voucher}>
- coupon: '<{$voucher->getCode()|escape}>',
- <{/if}>
- currency: '<{$webshop->getCurrency()}>',
- index: <{$smarty.section.purchaseimpr.index}>,
- <{if $p->getBrand()}>
- item_brand: '<{$p->getBrandName()|escape}>',
- <{/if}>
- <{if $p->getMainCategory()}>
- <{assign var="prodmaincat" value=$p->getMainCategory()}>
- <{if $prodmaincat->getParents()}>
- <{assign var="prodmaincatparents" value=$prodmaincat->getParents()}>
- <{assign var="catlevel" value=0}>
- <{section name="parents" loop=$prodmaincatparents max=5}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- <{if $smarty.section.parents.first}>
- item_category: '<{$prodmaincatparents[parents]->getName()|escape}>',
- <{else}>
- item_category<{$catlevel}>: '<{$prodmaincatparents[parents]->getName()|escape}>',
- <{/if}>
- <{/section}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- item_category<{$catlevel}>: '<{$p->getMainCategoryName()|escape}>',
- <{else}>
- item_category: '<{$p->getMainCategoryName()|escape}>',
- <{/if}>
- <{elseif $p->getCategory()}>
- <{assign var="prodcat" value=$p->getCategory()}>
- <{if $prodcat->getParents()}>
- <{assign var="prodcatparents" value=$prodcat->getParents()}>
- <{assign var="catlevel" value=0}>
- <{section name="parents" loop=$prodcatparents max=5}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- <{if $smarty.section.parents.first}>
- item_category: '<{$prodcatparents[parents]->getName()|escape}>',
- <{else}>
- item_category<{$catlevel}>: '<{$prodcatparents[parents]->getName()|escape}>',
- <{/if}>
- <{/section}>
- <{math assign="catlevel" equation=x+1 x=$catlevel}>
- item_category<{$catlevel}>: '<{$p->getCategoryName()|escape}>',
- <{else}>
- item_category: '<{$p->getCategoryName()|escape}>',
- <{/if}>
- <{/if}>
- <{if $webshop->getGooglePlaceID()}>
- location_id: '<{$webshop->getGooglePlaceID()}>',
- <{/if}>
- price: <{$orderproducts[purchaseimpr]->getPrice()|number_format:2:".":""}>,
- quantity: <{$orderproducts[purchaseimpr]->getAmount()}>
- }
- <{/if}>
- <{if !$smarty.section.purchaseimpr.last}>,<{/if}>
- <{/section}>
- ]
- }
- });
- </script>
- <{* Google Customer Reviews start *}>
- <{if $webshop->getGoogleMerchantId() && $webshop->getGoogleMerchantDeliveryDays()}>
- <{assign var="p" value=$order->getProducts()}>
- <script src="https://apis.google.com/js/platform.js?onload=renderOptIn" async defer></script>
- <script>
- window.renderOptIn = function() {
- window.gapi.load('surveyoptin', function() {
- window.gapi.surveyoptin.render(
- {
- 'merchant_id': <{$webshop->getGoogleMerchantId()}>,
- 'order_id': '<{$order->getWebshopOrderId()}>',
- 'email': '<{$order->getEmail()|escape}>',
- 'delivery_country': 'DK',
- 'estimated_delivery_date': '<{"+"|cat:$webshop->getGoogleMerchantDeliveryDays()|cat:" days"|date_format:"%Y-%m-%d"}>',
- 'products':
- <{strip}>
- [
- <{section name="googlemerchant" loop=$p}>
- {
- <{assign var="prodgtin" value=$p[googlemerchant]->getGtin()}>
- <{if $prodgtin}>
- 'gtin':'<{$prodgtin}>'
- <{/if}>
- }
- <{if $smarty.section.googlemerchant.last}><{else}>,<{/if}>
- <{/section}>
- ]
- <{/strip}>
- });
- });
- }
- </script>
- <{/if}>
- <{* Google Customer Reviews end *}>
- <{/if}>
- <{$order->setTrackingCalled()}>
- <{* Only once end *}>
- <{/if}>
- <{* Thanks dataLayer end *}>
- <{* Page dataLayer start *}>
- <{if $page}>
- <{/if}>
- <{* Page dataLayer end *}>
- <{* Blog post dataLayer start *}>
- <{if $blog_post || $blog}>
- <{/if}>
- <{* Blog post dataLayer end *}>
- <{* 404 dataLayer start *}>
- <{if $inc == "404.html"}>
- <{/if}>
- <{* 404 dataLayer end *}>
- <{* 410 dataLayer start *}>
- <{if $inc == "410.html"}>
- <{/if}>
- <{* 410 dataLayer end *}>
- <{* User sign in dataLayer start *}>
- <{if $inc == "user-sign-in.html" && $customer}>
- <{/if}>
- <{* User sign in dataLayer end *}>
- <{* User signup dataLayer start *}>
- <{if $inc == "user-sign-up.html" && $created}>
- <{/if}>
- <{* User signup dataLayer end*}>
- <{* Google Optimize start *}>
- <{if $webshop->getGoogleOptimizeId()}>
- <style>.async-hide { opacity: 0 !important} </style>
- <script>(function(a,s,y,n,c,h,i,d,e){s.className+=' '+y;h.start=1*new Date;
- h.end=i=function(){s.className=s.className.replace(RegExp(' ?'+y),'')};
- (a[n]=a[n]||[]).hide=h;setTimeout(function(){i();h.end=null},c);h.timeout=c;
- })(window,document.documentElement,'async-hide','dataLayer',4000,
- {'<{$webshop->getGoogleOptimizeId()}>':true});</script>
- <script src="https://www.googleoptimize.com/optimize.js?id=<{$webshop->getGoogleOptimizeId()}>"></script>
- <{/if}>
- <{* Google Optimize end *}>
- <{* Google Tag Manager container start *}>
- <script>
- (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
- new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
- j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
- 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
- })(window,document,'script','dataLayer','<{$webshop->getGoogleTagManagerId()}>');
- </script>
- <{* Google Tag Manager container end *}>
- <{/if}>
- <{/strip}>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement