<{if $webshop->getEnableTracking() && $cookie.accept_cookies == 'accept'}>
	<script>
	    product = []; // Containing all products of the current page
	    dataLayer = [];
	</script>


	<{* Theme settings pushed to dataLayer start *}>
	<script>
	    window.dataLayer = window.dataLayer || [];
	    window.dataLayer.push({
	        <{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->getGaId()}>
	            'settings.Google.Analytics_Tracking_ID': '<{$webshop->getGaId()}>',
	        <{/if}>

	        'settings.Google.Analytics_Anonymize_IP': 'true',
	        'settings.Google.Analytics_Enhanced_Link_Attribution': 'true',
	        'settings.Google.Analytics_Checkout_Label_Basket': '/basket',
	        'settings.Google.Analytics_Checkout_Label_Address': '/address',
	        'settings.Google.Analytics_Checkout_Label_Shipping': '/shipping',
	        'settings.Google.Analytics_Checkout_Label_Approve': '/approve',
	        'settings.Google.Analytics_Checkout_Label_Payment': '/payment',

	        <{if $webshop->getGoogleMerchantId()}>
	            'settings.Google.Merchant_Center_ID': '<{$webshop->getGoogleMerchantId()}>',
	        <{/if}>

	        <{if $webshop->getGoogleMerchantId()}>
	            'settings.Google.Merchant_Center_Customer_Reviews': 'true',
	        <{/if}>

	        <{if $webshop->getGoogleMerchantDeliveryDays()}>
	            'settings.Google.Merchant_Center_Delivery_Days': '<{$webshop->getGoogleMerchantDeliveryDays()}>',
	        <{/if}>

	        <{if $webshop->getGoogleOptimizeId()}>
	            'settings.Google.Optimize_Container_ID': '<{$webshop->getGoogleOptimizeId()}>',
	        <{/if}>

	        <{if $webshop->getGoogleTagManagerId()}>
	            'settings.Google.Tag_Manager_Containder_ID': '<{$webshop->getGoogleTagManagerId()}>',
	        <{/if}>
	        
	        <{if $webshop->getFbId()}>
			  	'settings.Facebook.Pixel_ID': '<{$webshop->getFbId()}>',
			<{/if}>

	        'event': 'ThemeSettings'
		});
	</script>
	<{* Theme settings pushed to dataLayer end *}>

	<{* Product dataLayer start *}>
	    <{if $product}>
	        <{* Google Ads Dynamic Remarketing start *}>
	            <script>
	                window.dataLayer = window.dataLayer || [];
	                window.dataLayer.push({
	                    'event': 'GoogleAdsDynamicRemarketing',
	                    <{if $product->getProductId()}>
	                        'ecomm_prodid': '<{$product->getProductId()}>',
	                    <{/if}>
	                    'ecomm_pagetype': 'product',
	                    <{if $product->getRealPrice()}>
	                        'ecomm_totalvalue': '<{$product->getRealPrice()}>',
	                    <{/if}>
	                    <{if $product->getMainCategory()}>
	                        <{assign var=prodmaincat value=$product->getMainCategory()}>
	                        'ecomm_category': '<{$prodmaincat->getName()}>',
	                    <{elseif $product->getCategory()}>
	                        'ecomm_category': '<{$product->getCategoryName()}>',
	                    <{/if}>
	                    <{if $product->getSalePrice() < 0}>
	                        isSaleItem: true
	                    <{else}>
	                        isSaleItem: false
	                    <{/if}>
	                });
	            </script>
	        <{* Google Ads Dynamic Remarketing end *}>

	        <{* Google Analytics Enhanced Ecommerce start *}>
	            <script>
	                window.dataLayer = window.dataLayer || [];
	                window.dataLayer.push({
	                    'event': 'view_item',
	                    'ecommerce': {
	                        'detail': {
	                            'products': [{
	                                <{if $product->getName()}>
	                                    'name': '<{$product->getName()}>',
	                                <{/if}>
	                                <{if $product->getProductId()}>
	                                    'id': '<{$product->getProductId()}>',
	                                <{/if}>
	                                <{if $product->getRealPrice()}>
	                                    'price': '<{$product->getRealPrice()}>',
	                                <{/if}>
	                                <{if $product->getBrand()}>
	                                    <{assign var=productbrand value=$product->getBrand()}>
	                                    'brand': '<{$productbrand->getName()}>',
	                                <{/if}>
	                                <{if $product->getMainCategory()}>
	                                    <{assign var=prodmaincat value=$product->getMainCategory()}>
	                                    'category': '<{$prodmaincat->getName()}>',
	                                <{/if}>
	                                <{* variant MISSING *}>
	                                'google_business_vertical': 'retail'
	                            }]
	                        }
	                    }
	                });
	            </script>
	        <{* Google Analytics Enhanced Ecommerce end *}>

	    <{/if}>
	<{* Product dataLayer end *}>

	<{* Category dataLayer start *}>
	    <{if $category}>
	        <{assign var="catproducts" value=$category->getOnlineProducts()}>

	        <{* Google Ads Dynamic Remarketing start *}>
	            <script>
	                window.dataLayer = window.dataLayer || [];
	                window.dataLayer.push({
	                    'event': 'GoogleAdsDynamicRemarketing',
	                    <{if $category->isFront()}>
	                        'ecomm_pagetype': 'home',
	                    <{else}>
	                        'ecomm_pagetype': 'category',
	                        'ecomm_category': '<{$category->getName()|escape}>'
	                    <{/if}>
	                });
	            </script>
	        <{* Google Ads Dynamic Remarketing end *}>

	    <{/if}>
	<{* Category dataLayer end *}>

	<{* Landingpage dataLayer start *}>
	    <{if $landing_page}>
	        <{assign var="lpproducts" value=$landing_page->getProducts()}>

	        <{* Google Ads Dynamic Remarketing start *}>
	            <script>
	                window.dataLayer = window.dataLayer || [];
	                window.dataLayer.push({
	                    'event': 'GoogleAdsDynamicRemarketing',
	                    'ecomm_pagetype': 'category'
	                });
	            </script>
	        <{* Google Ads Dynamic Remarketing end *}>

	    <{/if}>
	<{* Landingpage dataLayer end *}>

	<{* Page dataLayer start *}>
	    <{if $page}>
	        <{* Google Ads Dynamic Remarketing start *}>
	            <script>
	                window.dataLayer = window.dataLayer || [];
	                window.dataLayer.push({
	                    'event': 'GoogleAdsDynamicRemarketing',
	                    'ecomm_pagetype': 'other'
	                });
	            </script>
	        <{* Google Ads Dynamic Remarketing end *}>
	    <{/if}>
	<{* Page dataLayer end *}>

	<{* Blog post dataLayer start *}>
	    <{if $blog_post || $blog}>
	        <{* Google Ads Dynamic Remarketing start *}>
	            <script>
	                window.dataLayer = window.dataLayer || [];
	                window.dataLayer.push({
	                    'event': 'GoogleAdsDynamicRemarketing',
	                    'ecomm_pagetype': 'other'
	                });
	            </script>
	        <{* Google Ads Dynamic Remarketing end *}>
	    <{/if}>
	<{* Blog post dataLayer end *}>

	<{* Search dataLayer start *}>
	    <{if $inc == "search.html"}>
	        <{* Google Ads Dynamic Remarketing start *}>
	            <script>
	                window.dataLayer = window.dataLayer || [];
	                window.dataLayer.push({
	                    'event': 'GoogleAdsDynamicRemarketing',
	                    'ecomm_pagetype': 'searchresults'
	                });
	            </script>
	        <{* Google Ads Dynamic Remarketing end *}>
	    <{/if}>
	<{* Search dataLayer end *}>

	<{* Basket dataLayer start *}>
	    <{if $inc == "basket.html"}>
	        <{* Google Ads Dynamic Remarketing start *}>
	            <script>
	                window.dataLayer = window.dataLayer || [];
	                window.dataLayer.push({
	                    'event': 'GoogleAdsDynamicRemarketing',
	                    'ecomm_prodid': [
							<{strip}>
								<{section name="retargeting" loop=$basket}>
									'<{$basket[retargeting].id}>'
									<{if !$smarty.section.retargeting.last}>,<{/if}>
								<{/section}>
							<{/strip}>
						],
	                    'ecomm_pagetype': 'cart',
	                    'ecomm_totalvalue': <{$price}>
	                });
	            </script>
	        <{* Google Ads Dynamic Remarketing end *}>
	    <{/if}>
	<{* Basket dataLayer end *}>

	<{* Order dataLayer start *}>
	    <{if $inc != "thanks.html" && $order}>
	        <{* Google Ads Dynamic Remarketing start *}>
	            <script>
	                window.dataLayer = window.dataLayer || [];
	                window.dataLayer.push({
	                    'event': 'GoogleAdsDynamicRemarketing',
	                    'ecomm_pagetype': 'other'
	                });
	            </script>
	        <{* Google Ads Dynamic Remarketing end *}>
	    <{/if}>
	<{* Order dataLayer end *}>

	<{* Thanks dataLayer start *}>
	    <{if $inc == "thanks.html" && $order}>
	        <{* Only once start *}>
	            <{if !$order->getTrackingCalled()}>
	                <{assign var=orderproducts value=$order->getProducts()}>

	                <{* Google Ads Dynamic Remarketing start *}>
	                    <script>
	                        window.dataLayer = window.dataLayer || [];
	                        window.dataLayer.push({
	                            'event': 'GoogleAdsDynamicRemarketing',
	                            'ecomm_prodid': [
	                                <{section name=orderproductids loop=$orderproducts}>
	                                    '<{$orderproducts[orderproductids]->getProductId()}>'
	                                    <{if !$smarty.section.orderproductids.last}>,<{/if}>
	                                <{/section}>
	                                ],
	                            'ecomm_pagetype': 'purchase',
	                            'ecomm_totalvalue': <{$order->getPrice()}>,
	                        });
	                    </script>
	                <{* Google Ads Dynamic Remarketing end *}>

	                <{* Google Analytics Enhanced Ecommerce start *}>
	                    <script>
	                        window.dataLayer = window.dataLayer || [];
	                        window.dataLayer.push({
	                            'event': 'eecPurchase',
	                            'ecommerce': {
	                                'currencyCode': '<{$webshop->getCurrency()}>',
	                                'purchase': {
	                                    'actionField': {
	                                        <{if $order->getWebshopOrderId()}>
	                                            'id': '<{$order->getWebshopOrderId()}>',
	                                        <{/if}>
	                                        <{if $order->getPrice()}>
	                                            'revenue': '<{$order->getPrice()}>',
	                                        <{/if}>
	                                        <{if $order->getVat()}>
	                                            'tax':'<{$order->getVat()}>',
	                                        <{/if}>
	                                        <{if $order->getShippingPrice()}>
	                                            'shipping': '<{$order->getShippingPrice()}>',
	                                        <{/if}>
	                                        <{if $order->getVoucherCode() }>
	                                            'coupon': '<{$order->getVoucherCode()}>'
	                                        <{/if}>
	                                    },
	                                    'products': [
	                                        <{strip}>
	                                            <{assign var=orderproducts value=$order->getProducts()}>
	                                            <{section name=orderproducts loop=$orderproducts}>
	                                                {
	                                                    <{if $orderproducts[orderproducts]->getName()}>
	                                                        'name': '<{$orderproducts[orderproducts]->getName()|escape}>',
	                                                    <{/if}>
	                                                    <{if $orderproducts[orderproducts]->getProductId()}>
	                                                        'id': '<{$orderproducts[orderproducts]->getProductId()}>',
	                                                    <{/if}>
	                                                    <{if $orderproducts[orderproducts]->getGtin()}>
	                                                        'gtin': '<{$orderproducts[orderproducts]->getGtin()}>',
	                                                    <{/if}>
	                                                    <{if $orderproducts[orderproducts]->getUnitPrice()}>
	                                                        'price': '<{$orderproducts[orderproducts]->getUnitPrice()}>',
	                                                    <{/if}>
	                                                    <{if $orderproducts[orderproducts]->getBrand()}>
	                                                        <{assign var=productbrand value=$orderproducts[orderproducts]->getBrand()}>
	                                                        'brand': '<{$productbrand->getName()}>',
	                                                    <{/if}>
	                                                    <{if $orderproducts[orderproducts]->getMainCategory()}>
	                                                        <{assign var=prodmaincat value=$orderproducts[orderproducts]->getMainCategory()}>
	                                                        'category': '<{$prodmaincat->getName()}>',
	                                                    <{/if}>
	                                                    <{if $orderproducts[orderproducts]->hasVariants()}>,
	                                                        <{assign var=attributes value=$orderproducts[orderproducts]->getAttributes()}>
	                                                        <{if $attributes}>
	                                                            <{section name=j loop=$attributes}>
	                                                            	'variant': '<{$attributes[j].val}>'
	                                                            <{/section}>
	                                                        <{/if}>
	                                                    <{/if}>
	                                                    <{if $orderproducts[orderproducts]->getAmount()}>
	                                                        'quantity': <{$orderproducts[orderproducts]->getAmount()}>
	                                                    <{/if}>
	                                                }<{if $smarty.section.orderproducts.last}><{else}>,<{/if}><{/section}>
	                                        <{/strip}>
	                                    ]
	                                }
	                            }
	                        });
	                    </script>
	                <{* Google Analytics Enhanced Ecommerce end *}>

	                <{* Google Customer Reviews start *}>
	                    <{if $settings.Google.Merchant_Center_Customer_Reviews == "true"}>
	                        <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"}>",

	                                            <{if $settings.Google.Merchant_Center_Product_Reviews == "true"}>
	                                                "products":
	                                                <{strip}>
	                                                    [
	                                                    <{section name="gtin" loop=$orderproducts}>
	                                                        {
	                                                            <{assign var="prodgtin" value=$orderproducts[gtin]->getGtin()}>
	                                                            <{if $prodgtin}>
	                                                                "gtin":"<{$prodgtin}>"
	                                                            <{/if}>
	                                                        }
	                                                        <{if $smarty.section.gtin.last}><{else}>,<{/if}>
	                                                    <{/section}>
	                                                    ]
	                                                <{/strip}>
	                                            <{/if}>
	                                        });
	                                });
	                            }
	                        </script>
	                    <{/if}>
	                <{* Google Customer Reviews end *}>

	                <{* Customer Information start *}>
	                    <script>
	                        window.dataLayer = window.dataLayer || [];
	                        window.dataLayer.push({
	                            <{if $order->getEmail()}>
	                                'order.email': '<{$order->getEmail()|escape}>',
	                            <{/if}>
	                            <{if $order->getPhone()}>
	                                'order.phone': '<{$order->getPhone()|escape}>',
	                            <{/if}>
	                           <{if $order->getOrderName()}>
	                                'order.name': '<{$order->getOrderName()|escape}>',
	                            <{/if}>
	                            <{if $order->getOrderCompanyName()}>
	                                'order.companyname': '<{$order->getOrderCompanyName()|escape}>',
	                            <{/if}>
	                            <{if $order->getOrderAddress()}>
	                                'order.address': '<{$order->getOrderAddress()|escape}>',
	                            <{/if}>
	                            <{if $order->getOrderZipcode()}>
	                                'order.zipcode': '<{$order->getOrderZipcode()|escape}>',
	                            <{/if}>
	                            <{if $order->getOrderCity()}>
	                                'order.city': '<{$order->getOrderCity()|escape}>',
	                            <{/if}>
	                            <{if $order->getOrderCountry()}>
	                                'order.country': '<{$order->getOrderCountry()|escape}>',
	                            <{/if}>
	                            <{if $order->getDelCountry()}>
	                                'del.country': '<{$order->getDelCountry()|escape}>',
	                            <{/if}>
	                            "del.date": "<{"+"|cat:$webshop->getGoogleMerchantDeliveryDays()|cat:" days"|date_format:"%Y-%m-%d"}>"
	                            }
	                        );
	                    </script>
	                <{* Customer Information end *}>
	            <{/if}>

	            <{$order->setTrackingCalled()}>
	        <{* Only once end *}>

	    <{/if}>
	<{* Thanks dataLayer end *}>

	<{* 404 dataLayer start *}>
	    <{if $inc == "404.html"}>
	        <{* Google Ads Dynamic Remarketing start *}>
	            <script>
	                window.dataLayer = window.dataLayer || [];
	                window.dataLayer.push({
	                    'event': 'GoogleAdsDynamicRemarketing',
	                    'ecomm_pagetype': 'other'
	                });
	            </script>
	        <{* Google Ads Dynamic Remarketing end *}>
	    <{/if}>
	<{* 404 dataLayer end *}>

	<{* 410 dataLayer start *}>
	    <{if $inc == "410.html"}>
	        <{* Google Ads Dynamic Remarketing start *}>
	            <script>
	                window.dataLayer = window.dataLayer || [];
	                window.dataLayer.push({
	                    'event': 'GoogleAdsDynamicRemarketing',
	                    'ecomm_pagetype': 'other'
	                });
	            </script>
	        <{* Google Ads Dynamic Remarketing end *}>
	    <{/if}>
	<{* 410 dataLayer end *}>

	<{* User sign in dataLayer start *}>
	    <{if $inc == "user-sign-in.html" && $customer}>
	        <{* Google Ads Dynamic Remarketing start *}>
	            <script>
	                window.dataLayer = window.dataLayer || [];
	                window.dataLayer.push({
	                    'event': 'GoogleAdsDynamicRemarketing',
	                    'ecomm_pagetype': 'other'
	                });
	            </script>
	        <{* Google Ads Dynamic Remarketing end *}>
	    <{/if}>
	<{* User sign in dataLayer end *}>

	<{* User signup dataLayer start *}>
	    <{if $inc == "user-sign-up.html" && $created}>
	        <{* Google Ads Dynamic Remarketing start *}>
	            <script>
	                window.dataLayer = window.dataLayer || [];
	                window.dataLayer.push({
	                    'event': 'GoogleAdsDynamicRemarketing',
	                    'ecomm_pagetype': 'other'
	                });
	            </script>
	        <{* Google Ads Dynamic Remarketing end *}>
	    <{/if}>
	<{* User signup dataLayer 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}>