Set Up Ecommerce Tracking with Google Tag Manager:

https://www.analyticsmania.com/post/ecommerce-tracking-with-google-tag-manager/

1. add "public $order" to /vendor/fancyecommerce/fecshop/app/appfront/modules/Payment/controllers/SuccessContorller.php to make variable visible in main layout.

2. insert code int header before gtm code:

<?php if(Yii::$app->controller->id=='success') : 















    ?>  







    <?php if(!empty($this->params['order'])) : 







        $order = $this->params['order'];







        ?>







       <script>







        window.dataLayer = window.dataLayer || [];







        dataLayer.push({







         'transactionId': '<?=$order['order_id']?>',







         'transactionTotal': <?=$order['grand_total']?>, 







         /*'transactionTax': 1.29,*/







         'transactionShipping': <?=$order['base_shipping_total']?>,







         'transactionProducts': [







         <?php 







        $lastElement = end($order['items']);







         foreach($order['items'] as $item): ?>







         {







           'sku': '<?=$item['sku']?>',







           'name': '<?=$item['name']?>',







          /* 'category': 'Apparel',*/







           'price': <?=$item['price']?>,  







           'quantity': <?=$item['qty']?> 







         }







         <?php if($item != $lastElement) : ?>







         ,







          <?php endif; ?>







         <?php endforeach; ?>







         ]







        });







    </script>







    







    <?php   endif; ?>







<?php   endif; ?>  







3. nastavit gtm dle navodu, trigerring pageview je "/payment/success"

 

Rate this FAQ

0 (0 Votes)