Browse code

Minor Updates for GA4

Benjamin Roth authored on26/06/2023 16:36:54
Showing1 changed files
... ...
@@ -1,9 +1,9 @@
1 1
 [{$smarty.block.parent}]
2 2
 
3 3
 [{assign var="oConfig" value=$oViewConf->getConfig()}]
4
-[{assign var=googleTrackingId value=$oConfig->getConfigParam('sOxEsAnalyticsId')}]
5
-[{assign var=googleAdsId value=$oConfig->getConfigParam('sOxEsAdsId')}]
6
-[{assign var=googleAdsConvLabel value=$oConfig->getConfigParam('sOxEsAdsConvLabel')}]
4
+[{assign var=googleTrackingId value=$oConfig->getConfigParam('sOxEsGA4AnalyticsId')}]
5
+[{assign var=googleAdsId value=$oConfig->getConfigParam('sOxEsGA4AdsId')}]
6
+[{assign var=googleAdsConvLabel value=$oConfig->getConfigParam('sOxEsGA4AdsConvLabel')}]
7 7
 [{if $googleTrackingId}]
8 8
   <!-- Global site tag (gtag.js) - Google Analytics -->
9 9
   <script async src="https://www.googletagmanager.com/gtag/js?id=[{$googleTrackingId}]"></script>
Browse code

Minor Updates for GA4

Benjamin Roth authored on26/06/2023 16:19:11
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,93 @@
1
+[{$smarty.block.parent}]
2
+
3
+[{assign var="oConfig" value=$oViewConf->getConfig()}]
4
+[{assign var=googleTrackingId value=$oConfig->getConfigParam('sOxEsAnalyticsId')}]
5
+[{assign var=googleAdsId value=$oConfig->getConfigParam('sOxEsAdsId')}]
6
+[{assign var=googleAdsConvLabel value=$oConfig->getConfigParam('sOxEsAdsConvLabel')}]
7
+[{if $googleTrackingId}]
8
+  <!-- Global site tag (gtag.js) - Google Analytics -->
9
+  <script async src="https://www.googletagmanager.com/gtag/js?id=[{$googleTrackingId}]"></script>
10
+  <script>
11
+    window.dataLayer = window.dataLayer || [];
12
+    function gtag(){dataLayer.push(arguments);}
13
+    gtag('js', new Date());
14
+
15
+    gtag('config', '[{$googleTrackingId}]', { 'anonymize_ip': true });
16
+[{/if}]
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());
26
+
27
+      gtag('config', '[{$googleAdsId}]', { 'anonymize_ip': true });
28
+    </script>
29
+  [{else}]
30
+      gtag('config', '[{$googleAdsId}]', { 'anonymize_ip': true });
31
+    </script>
32
+  [{/if}]
33
+[{else}]
34
+  [{if $googleTrackingId}]
35
+    </script>
36
+  [{/if}]
37
+[{/if}]
38
+
39
+[{if $oViewConf->getActiveClassName() == 'thankyou'}]
40
+<script>
41
+  // Order infos
42
+  [{assign var="order" value=$oView->getOrder()}]
43
+
44
+  [{assign var="currate" value=$order->oxorder__oxcurrate->value}]
45
+  [{if $oConfig->getConfigParam('blEnterNetPrice')}]
46
+  [{math equation="sum / rate" sum=$order->getOrderNetSum() rate=$currate format="%.2f" assign="sTotal"}]
47
+  [{else}]
48
+  [{math equation="sum / rate" sum=$order->getTotalOrderSum() rate=$currate format="%.2f" assign="sTotal"}]
49
+  [{/if}]
50
+  [{math equation="sum - net" sum=$order->getTotalOrderSum() net=$order->getOrderNetSum() format="%.2f" assign="sTax"}]
51
+  [{math equation="sum / rate" sum=$order->oxorder__oxdelcost->value rate=$currate format="%.2f" assign="sShipping"}]
52
+
53
+  // Items
54
+  var orderitems = [];
55
+  [{foreach from=$order->getOrderArticles() item=oOrderArticle}]
56
+    [{if $oConfig->getConfigParam('blEnterNetPrice')}]
57
+    [{assign var="oPrice" value=$oOrderArticle->getPrice()}]
58
+    [{math equation="sum / rate" sum=$oPrice->getNettoPrice() rate=$currate format="%.2f" assign="sPrice"}]
59
+    [{else}]
60
+    [{assign var="sPrice" value=$oOrderArticle->oxorderarticles__oxprice->value}]
61
+    [{/if}]
62
+
63
+    orderitems.push({
64
+      'id': '[{$order->oxorder__oxordernr->value}]',                          [{* Transaction ID *}]
65
+      'name': '[{$oOrderArticle->oxorderarticles__oxtitle->value|escape:"quotes"}][{if $oOrderArticle->oxorderarticles__oxselvariant->value}] [{$oOrderArticle->oxorderarticles__oxselvariant->value}][{/if}]',          [{* Product name *}]
66
+      'sku': '[{$oOrderArticle->oxorderarticles__oxartnum->value|escape:"quotes"}]',          [{* SKU *}]
67
+      'price': '[{$sPrice}]',                                                 [{* Preis pro Einheit *}]
68
+      'quantity': '[{$oOrderArticle->oxorderarticles__oxamount->value}]'      [{* Menge *}]
69
+    });
70
+
71
+  [{/foreach}]
72
+
73
+  [{if $googleTrackingId}]
74
+    gtag('event', 'purchase', {
75
+      'transaction_id': '[{$order->oxorder__oxordernr->value}]',        [{* Transaction ID *}]
76
+      'affiliation':    '[{$oxcmp_shop->oxshops__oxname->value|escape:"quotes"}]',      [{* Store name *}]
77
+      'value':          '[{$sTotal}]',                                  [{* Grand Total *}]
78
+      'shipping':       '[{$sShipping}]',                               [{* Shipping *}]
79
+      'tax':            '[{$sTax}]',                                     [{* Tax *}]
80
+      'items': orderitems
81
+    });
82
+  [{/if}]
83
+
84
+  [{if $googleAdsId}]
85
+    gtag('event', 'conversion', {
86
+      'send_to': '[{$googleAdsId}]/[{$googleAdsConvLabel}]',
87
+      'transaction_id': '[{$order->oxorder__oxordernr->value}]',
88
+      'value':          '[{$sTotal}]'
89
+    });
90
+  [{/if}]
91
+
92
+</script>
93
+[{/if}]
0 94
\ No newline at end of file