Hi all,
I'm supporting www.premierrange.co.uk where we run a heavily modified ZC 1.5.5 with mods like CEON URI Mapping, password verification on signup etc. Our own modifications are probably far more significant than the changes made by these mods.
My question is about how to integrate the Google Ads Remarketing Tag with the way Zen Cart builds its pages, specifically the flow from html_header, to main_template_vars, to the product page etc. and what is known at each point in time.
For some years we've been using Google Remarketing which involves us calling a Javascript 'gtag' function, passing in some data about the event, the product SKU, price, GTIN, etc. I believe this used to be a simple javascript function that immediately (or shortly after) made an XHR call to Google to pass over the data. This was a simple case of loading the library via a '<script>' tag in html_header in the '<head>' and later calling gtag() from any javascript block.
Recently they seem to have re-implemented their library and are advising people to not use 'gtag' and more, but instead use some kind of 'dataLayer' variable, which seems to be a simple array. There is a migration guide at https://support.google.com/google-ad..._topic=3122875 where you can see the 'Event Snippet' shows the old fashioned call we would make:
gtag('event', 'add_to_cart', { .. lots of data .. });
Just below there you'll see the code that allows the new 'dataLayer' array to be used via the same gtag() calling mechanism:
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
So now the 'gtag' function simply pushes onto an array called dataLayer.
Google says that you must push data onto the dataLayer _before_ loading the remarketing library, which means it has to be done while '<head>' is being generated and before the script tag for the library is output. From the look of the code, unless they are overloading the Array.push prototype to do something clever, I can see that simply pushing onto the array isn't going to achieve any code execution. So, if we declare dataLayer and load the remarketing library in html_header.php (or somewhere similarly early in page execution to be within '<head>') then pushing onto dataLayer some time later, for example during tpl_product_default.php, it's not going to be sent to Google.
While ZC is outputting a product page, it seems the first time the products_id query parameter is used to retrieve any useful information about the product being viewed is in the main_template_vars.php script of the product page, which is after the '<body>' of the page has been output, it's far too late then to start pushing onto dataLayer.
Has anyone else experience of the recent changes to the Google Remarketing library and can comment on how to weave it into Zen Cart?
It looks like I'm going to have to move, or duplicate, some of our fairly complex logic from main_template_vars where the system figures out which product is being requested, its price and so on, into html_header so that I can push onto dataLayer, but I don't like hacking ZC for the sake of Google's changed implementation.
Just some background, we implement a 'variations' system a bit like eBay's variations, where a single Zen Cart product represents tens or hundreds of physical products, so the products_id is constant but some other query parameters indicate the exact product that is being viewed or ordered, it works with the ZC 'attributes' system to apply attribute values like Colour, Size etc that result in different SKUs and GTINs for the product being ordered. This is the lookup that's done in main_template_vars.php for our custom product, which is too late to pass to Google's Remarketing Library.
Sorry for the rant :) Not sure if this belongs in the 'Search Engines' forum. Any advice appreciated before I bite off more of this work :)
Nick
Bookmarks