1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
<script> window.dataLayer = window.dataLayer || []; var products = []; <?php foreach($order_products as $key => $item): ?> products.push({ 'name': '<?=$item->name?>', 'id': '<?=$item->product_id?>', 'price': '<?=round($item->price, 0)?>', 'brand': 'WIIB', 'category': 'Health', 'quantity': <?=$item->quantity?>, 'coupon': '' }); <?php endforeach; ?> dataLayer.push({ 'ecommerce': { 'purchase': { 'actionField': { 'id': '<?=$order->transaction_id?>', // Transaction ID. Required for purchases and refunds. 'affiliation': 'WIIB', 'revenue': '<?=round($order->amount, 0)?>', // Total transaction value (incl. tax and shipping) 'tax':'<?=$order->amount*0.05?>', 'shipping': '<?=$order->shipping_fee?>' }, 'products': products } }, 'event': 'transactionComplete' }); </script> |
Reference: