[{$smarty.block.parent}]

[{assign var="oConfig" value=$oViewConf->getConfig()}]
[{assign var=googleTrackingId value=$oConfig->getConfigParam('sOxEsAnalyticsId')}]
[{if $googleTrackingId}]
<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', '[{$googleTrackingId}]', 'auto');
  ga('set', 'anonymizeIp', true);
  ga('send', 'pageview');


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

  ga('require', 'ecommerce');

  [{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"}]

  ga('ecommerce:addTransaction', {
    'id':           '[{$order->oxorder__oxordernr->value}]',        [{* Transaction ID *}]
    'affiliation':  '[{$oxcmp_shop->oxshops__oxname->value|escape:"quotes"}]',      [{* Store name *}]
    'revenue':      '[{$sTotal}]',                                  [{* Grand Total *}]
    'shipping':     '[{$sShipping}]',                               [{* Shipping *}]
    'tax':          '[{$sTax}]'                                     [{* Tax *}]
  });

  [{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}]


  ga('ecommerce:addItem', {
    '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}]

  ga('ecommerce:send');
  [{/strip}][{/if}]
</script>
[{/if}]