Browse code

Use universal website tag and include google ads

Benjamin Roth authored on26/03/2019 17:37:55
Showing3 changed files
... ...
@@ -61,6 +61,7 @@ $aModule = array(
61 61
     ),
62 62
     'settings'    => array(
63 63
         array('group' => 'main', 'name' => 'sOxEsAnalyticsId', 'type' => 'str', 'value' => ''),
64
+        array('group' => 'main', 'name' => 'sOxEsAdsId', 'type' => 'str', 'value' => ''),
64 65
         array('group' => 'esUninstall', 'name' => 'blOxEsAnalyticsSweep', 'type' => 'bool', 'value' => 'false'),
65 66
     )
66 67
 );
... ...
@@ -14,6 +14,7 @@ $aLang = array(
14 14
     'charset'                                    => 'UTF-8',
15 15
     'SHOP_MODULE_GROUP_esUninstall'              => 'Deinstallieren',
16 16
     'SHOP_MODULE_sOxEsAnalyticsId'               => 'Google Analytics ID (UA-XXXXX-X)',
17
+    'SHOP_MODULE_sOxEsAdsId'                     => 'Google Ads ID (UA-XXXXX-X)',
17 18
     'SHOP_MODULE_blOxEsAnalyticsSweep'           => 'Alle zum Modul gehörenden Datenbankfelder löschen<p class="info">ACHTUNG: Bereits eingetragene Daten gehen verloren.</p>',
18 19
 
19 20
 );
... ...
@@ -2,22 +2,41 @@
2 2
 
3 3
 [{assign var="oConfig" value=$oViewConf->getConfig()}]
4 4
 [{assign var=googleTrackingId value=$oConfig->getConfigParam('sOxEsAnalyticsId')}]
5
+[{assign var=googleAdsId value=$oConfig->getConfigParam('sOxEsAdsId')}]
5 6
 [{if $googleTrackingId}]
6
-<script>
7
-  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
8
-    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
9
-    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
10
-  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
7
+  <!-- Global site tag (gtag.js) - Google Analytics -->
8
+  <script async src="https://www.googletagmanager.com/gtag/js?id=[{$googleTrackingId}]"></script>
9
+  <script>
10
+    window.dataLayer = window.dataLayer || [];
11
+    function gtag(){dataLayer.push(arguments);}
12
+    gtag('js', new Date());
11 13
 
12
-  ga('create', '[{$googleTrackingId}]', 'auto');
13
-  ga('set', 'anonymizeIp', true);
14
-  ga('send', 'pageview');
14
+    gtag('config', '[{$googleTrackingId}]', { 'anonymize_ip': true });
15
+</script>
16
+[{/if}]
15 17
 
18
+[{if $googleAdsId}]
19
+  [{if !$googleTrackingId}]
20
+    <!-- Global site tag (gtag.js) - Google Ads -->
21
+    <script async src="https://www.googletagmanager.com/gtag/js?id=[{$googleAdsId}]"></script>
22
+    <script>
23
+      window.dataLayer = window.dataLayer || [];
24
+      function gtag(){dataLayer.push(arguments);}
25
+      gtag('js', new Date());
16 26
 
17
-  [{if $oViewConf->getActiveClassName() == 'thankyou'}][{strip}]
18
-  [{assign var="order" value=$oView->getOrder()}]
27
+      gtag('config', '[{$googleAdsId}]', { 'anonymize_ip': true });
28
+    </script>
29
+  [{else}]
30
+    <script>
31
+      gtag('config', '[{$googleAdsId}]', { 'anonymize_ip': true });
32
+    </script>
33
+  [{/if}]
34
+[{/if}]
19 35
 
20
-  ga('require', 'ecommerce');
36
+[{if $oViewConf->getActiveClassName() == 'thankyou'}][{strip}]
37
+<script>
38
+  // Order infos
39
+  [{assign var="order" value=$oView->getOrder()}]
21 40
 
22 41
   [{assign var="currate" value=$order->oxorder__oxcurrate->value}]
23 42
   [{if $oConfig->getConfigParam('blEnterNetPrice')}]
... ...
@@ -28,34 +47,44 @@
28 47
   [{math equation="sum - net" sum=$order->getTotalOrderSum() net=$order->getOrderNetSum() format="%.2f" assign="sTax"}]
29 48
   [{math equation="sum / rate" sum=$order->oxorder__oxdelcost->value rate=$currate format="%.2f" assign="sShipping"}]
30 49
 
31
-  ga('ecommerce:addTransaction', {
32
-    'id':           '[{$order->oxorder__oxordernr->value}]',        [{* Transaction ID *}]
33
-    'affiliation':  '[{$oxcmp_shop->oxshops__oxname->value|escape:"quotes"}]',      [{* Store name *}]
34
-    'revenue':      '[{$sTotal}]',                                  [{* Grand Total *}]
35
-    'shipping':     '[{$sShipping}]',                               [{* Shipping *}]
36
-    'tax':          '[{$sTax}]'                                     [{* Tax *}]
37
-  });
38
-
50
+  // Items
51
+  var orderitems = [];
39 52
   [{foreach from=$order->getOrderArticles() item=oOrderArticle}]
53
+    [{if $oConfig->getConfigParam('blEnterNetPrice')}]
54
+    [{assign var="oPrice" value=$oOrderArticle->getPrice()}]
55
+    [{math equation="sum / rate" sum=$oPrice->getNettoPrice() rate=$currate format="%.2f" assign="sPrice"}]
56
+    [{else}]
57
+    [{assign var="sPrice" value=$oOrderArticle->oxorderarticles__oxprice->value}]
58
+    [{/if}]
40 59
 
41
-  [{if $oConfig->getConfigParam('blEnterNetPrice')}]
42
-  [{assign var="oPrice" value=$oOrderArticle->getPrice()}]
43
-  [{math equation="sum / rate" sum=$oPrice->getNettoPrice() rate=$currate format="%.2f" assign="sPrice"}]
44
-  [{else}]
45
-  [{assign var="sPrice" value=$oOrderArticle->oxorderarticles__oxprice->value}]
46
-  [{/if}]
47
-
60
+    orderitems.push({
61
+      'id': '[{$order->oxorder__oxordernr->value}]',                          [{* Transaction ID *}]
62
+      'name': '[{$oOrderArticle->oxorderarticles__oxtitle->value|escape:"quotes"}][{if $oOrderArticle->oxorderarticles__oxselvariant->value}] [{$oOrderArticle->oxorderarticles__oxselvariant->value}][{/if}]',          [{* Product name *}]
63
+      'sku': '[{$oOrderArticle->oxorderarticles__oxartnum->value|escape:"quotes"}]',          [{* SKU *}]
64
+      'price': '[{$sPrice}]',                                                 [{* Preis pro Einheit *}]
65
+      'quantity': '[{$oOrderArticle->oxorderarticles__oxamount->value}]'      [{* Menge *}]
66
+    });
48 67
 
49
-  ga('ecommerce:addItem', {
50
-    'id': '[{$order->oxorder__oxordernr->value}]',                          [{* Transaction ID *}]
51
-    'name': '[{$oOrderArticle->oxorderarticles__oxtitle->value|escape:"quotes"}][{if $oOrderArticle->oxorderarticles__oxselvariant->value}] [{$oOrderArticle->oxorderarticles__oxselvariant->value}][{/if}]',          [{* Product name *}]
52
-    'sku': '[{$oOrderArticle->oxorderarticles__oxartnum->value|escape:"quotes"}]',          [{* SKU *}]
53
-    'price': '[{$sPrice}]',                                                 [{* Preis pro Einheit *}]
54
-    'quantity': '[{$oOrderArticle->oxorderarticles__oxamount->value}]'      [{* Menge *}]
55
-  });
56 68
   [{/foreach}]
57 69
 
58
-  ga('ecommerce:send');
59
-  [{/strip}][{/if}]
70
+  [{if $googleTrackingId}]
71
+    gtag('event', 'purchase' {
72
+      'transaction_id': '[{$order->oxorder__oxordernr->value}]',        [{* Transaction ID *}]
73
+      'affiliation':    '[{$oxcmp_shop->oxshops__oxname->value|escape:"quotes"}]',      [{* Store name *}]
74
+      'value':          '[{$sTotal}]',                                  [{* Grand Total *}]
75
+      'shipping':       '[{$sShipping}]',                               [{* Shipping *}]
76
+      'tax':            '[{$sTax}]'                                     [{* Tax *}]
77
+      'items': orderitems
78
+    });
79
+  [{/if}]
80
+
81
+  [{if $googleAdsId}]
82
+    gtag('event', 'conversion', {
83
+      'send_to': '[{$googleAdsId}]/5c0rCMbkt5EBEMOv59YD',
84
+      'transaction_id': '[{$order->oxorder__oxordernr->value}]',
85
+      'value':          '[{$sTotal}]',
86
+    });
87
+  [{/if}]
88
+
60 89
 </script>
61
-[{/if}]
62 90
\ No newline at end of file
91
+[{/strip}][{/if}]
63 92
\ No newline at end of file