[{$smarty.block.parent}]

[{assign var="oConfig" value=$oViewConf->getConfig()}]
[{assign var=googleTrackingId value=$oConfig->getConfigParam('sOxEsAnalyticsId')}]
[{assign var=googleAdsId value=$oConfig->getConfigParam('sOxEsAdsId')}]
[{assign var=googleAdsConvLabel value=$oConfig->getConfigParam('sOxEsAdsConvLabel')}]
[{if $googleTrackingId}]
  <!-- Global site tag (gtag.js) - Google Analytics -->
  <script async src="https://www.googletagmanager.com/gtag/js?id=[{$googleTrackingId}]"></script>
  <script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());

    gtag('config', '[{$googleTrackingId}]', { 'anonymize_ip': true });
</script>
[{/if}]

[{if $googleAdsId}]
  [{if !$googleTrackingId}]
    <!-- Global site tag (gtag.js) - Google Ads -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=[{$googleAdsId}]"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', '[{$googleAdsId}]', { 'anonymize_ip': true });
    </script>
  [{else}]
    <script>
      gtag('config', '[{$googleAdsId}]', { 'anonymize_ip': true });
    </script>
  [{/if}]
[{/if}]

[{if $oViewConf->getActiveClassName() == 'thankyou'}][{strip}]
<script>
  // Order infos
  [{assign var="order" value=$oView->getOrder()}]

  [{assign var="currate" value=$order->oxorder__oxcurrate->value}]
  [{if $oConfig->getConfigParam('blEnterNetPrice')}]
  [{math equation="sum / rate" sum=$order->getOrderNetSum() rate=$currate format="%.2f" assign="sTotal"}]
  [{else}]
  [{math equation="sum / rate" sum=$order->getTotalOrderSum() rate=$currate format="%.2f" assign="sTotal"}]
  [{/if}]
  [{math equation="sum - net" sum=$order->getTotalOrderSum() net=$order->getOrderNetSum() format="%.2f" assign="sTax"}]
  [{math equation="sum / rate" sum=$order->oxorder__oxdelcost->value rate=$currate format="%.2f" assign="sShipping"}]

  // Items
  var orderitems = [];
  [{foreach from=$order->getOrderArticles() item=oOrderArticle}]
    [{if $oConfig->getConfigParam('blEnterNetPrice')}]
    [{assign var="oPrice" value=$oOrderArticle->getPrice()}]
    [{math equation="sum / rate" sum=$oPrice->getNettoPrice() rate=$currate format="%.2f" assign="sPrice"}]
    [{else}]
    [{assign var="sPrice" value=$oOrderArticle->oxorderarticles__oxprice->value}]
    [{/if}]

    orderitems.push({
      'id': '[{$order->oxorder__oxordernr->value}]',                          [{* Transaction ID *}]
      'name': '[{$oOrderArticle->oxorderarticles__oxtitle->value|escape:"quotes"}][{if $oOrderArticle->oxorderarticles__oxselvariant->value}] [{$oOrderArticle->oxorderarticles__oxselvariant->value}][{/if}]',          [{* Product name *}]
      'sku': '[{$oOrderArticle->oxorderarticles__oxartnum->value|escape:"quotes"}]',          [{* SKU *}]
      'price': '[{$sPrice}]',                                                 [{* Preis pro Einheit *}]
      'quantity': '[{$oOrderArticle->oxorderarticles__oxamount->value}]'      [{* Menge *}]
    });

  [{/foreach}]

  [{if $googleTrackingId}]
    gtag('event', 'purchase' {
      'transaction_id': '[{$order->oxorder__oxordernr->value}]',        [{* Transaction ID *}]
      'affiliation':    '[{$oxcmp_shop->oxshops__oxname->value|escape:"quotes"}]',      [{* Store name *}]
      'value':          '[{$sTotal}]',                                  [{* Grand Total *}]
      'shipping':       '[{$sShipping}]',                               [{* Shipping *}]
      'tax':            '[{$sTax}]'                                     [{* Tax *}]
      'items': orderitems
    });
  [{/if}]

  [{if $googleAdsId}]
    gtag('event', 'conversion', {
      'send_to': '[{$googleAdsId}]/[{$googleAdsConvLabel}]',
      'transaction_id': '[{$order->oxorder__oxordernr->value}]',
      'value':          '[{$sTotal}]',
    });
  [{/if}]

</script>
[{/strip}][{/if}]