google-analyticsgoogle-tag-managerenhanced-ecommerce

Google Tag Manager / Enhanced E-commerce - Purchase tag dataLayer push working only on Tag Assistance


I'm trying to add Enhance Ecommerce but something isn't okay. When I make an order through Google Tag Assistance everything is working and the transaction is showed on the Google Analytics but when I make an order normally like customer nothing is showed.

This is what I've added to thank-you page on the shop

<script type="text/javascript">

dataLayer.push({ ecommerce: null });
dataLayer.push({
    'event': 'transaction',
    'ecommerce': {        
        'purchase': {
            'actionField': {
                'id': '<?php echo $order->get_order_number() ?>',
                'revenue': '<?php echo number_format($order->get_subtotal(), 2, ".", ""); ?>', 
                'number_of_products': '<?php echo $order->get_item_count(); ?>'
            },
            'products': [
                
                <?php foreach ($order->get_items() as $key => $item): ?>
                {
                    'name': '<?php echo $item['name']; ?>',
                    'id': '<?php echo $item['product_id']; ?>',
                    'price': '<?php echo number_format($item->get_total(), 2, ".", ""); ?>',
                    'quantity': '<?php echo $item['qty']; ?>'
                },
                <?php endforeach; 
                ?>
            ]
        }
    }
});

</script> 

And this is my setup in Google Tag Manager

tag enter image description here

The trigger enter image description here

Few variables - order_id enter image description here

Product name enter image description here

Tried google, tried tutorials and still nothing helped.

When I run from Tag Assistant everything is go to analytic. When doesn't go through Tag Assistant nothing is showed.

Any ideas?

UPDATE: GTM Workspace preview

enter image description here


Solution

  • In order to enter preview, you have to first open GTM. In GTM, you have workspaces. Or at least, the default one. open GTM, go to the overview tab of the workspace that you're previewing (since you don't know what worspaces are, you probably use the default one) and make sure there are no Workspace Changes in it. Here is a screenshot of a workspace WITH changes:

    enter image description here

    And here is another workspace with NO changes:

    enter image description here

    If you have changes in your workspace, try publishing them and see if your tags start firing in prod.