Trigger ecomm dataLayer push and access dataLayer contents stored in another variable

I’m working with a Google Tag Manager extension which uses PHP to output dataLayer content for Enhanced Ecommerce. I’m trying to figure out the cleanest way to prevent this from being automatically pushed on the checkout event on page load, as I want instead to be able to trigger this dynamically via JS (for each checkout step loaded via AJAX). So I have something like the following dumped in the HTML on page load:

dataLayer.push({  
"event":"checkout",
"ecommerce":{  
    "checkout":{  
        "actionField":{  
            "step":""
        },
        "products":[  
            {  
                "sku":"99999",
                "name":"Bue Jacket",
                "price":"99.0000",
                "priceexcludingtax":"79.20",
                "tax":"19.80",
                "taxrate":20,
                "type":"configurable",
                "category":"1841",
                "quantity":1
            }
        ]
    }
}

});

Then, in my JS which handles the AJAX progression between steps, I have this:

// Push checkout step info
            window.dataLayer.push({
                event: 'checkout',
                checkout: {
                    actionField: {
                        step: checkoutStep
                    }
                }
            });

What I’m trying to do here is push the step and the rest of the checkout dataLayer data at the same time. Should I just store the data in a different variable on the page and just access it when doing my dataLayer push with the step number? Or is there a neater way to handle this?

Many thanks

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.