Cem Simsek's Space

cem simsek
Turkish Localization & Online Marketing Specialist


Recent Tweets @cssimsek

If you’ve yet to work with Google Tag Manager, here’s the description provided for the dataLayer object in the API reference:

The dataLayer is a global object of key/value pairs passed to Google Tag Manager. It can be used to describe information that isn’t available as part of a page DOM or other JavaScript variables. The dataLayer object needs to be initialized.

The dataLayer is basically a global JavaScript object used to pass variables and/or events to Google Tag Manager [see Using a Data Layer].

If you’re a third party provider (analytics, retargeting, etc) working with a client who’s using Google Tag Manager you can make use of pre-existing data in the dataLayer object.

Ideally your client’s IT team will have "implemented a data layer as recommended in the developer documentation, rendering data accessible via the Data Layer macro type" [see Macro Types -> Data Layer]. However if they haven’t, you can still make use of information passed to the dataLayer object. Hopefully your client’s IT team will have at least implemented server-side or client-side scripts to dynamically populate the values for each of the keys they’re defining and pushing to the dataLayer object. Assumedly they will have done, passing meaningful keys such as ecomm_prodid or ecomm_totalvalue as defined here —> [AdWords Dynamic Remarketing GTM deployment]

The dataLayer object is in fact an Array object which you can inspect by simply typing dataLayer and hitting Enter in your favourite JavaScript debugger. On a page where the dataLayer object is present —> Array.isArray(dataLayer) will return true. If your client pushed an object with the recommended AdWords Dynamic Remarketing keys to the dataLayer array you’ll find this object in the array. With my client’s site the remarketing keys were in a nested object in index 0 of the dataLayer array. The nested object had the key of google_tag_params. While writing this post I found that this object is actually initially created as a global variable (i.e. window.google_tag_params) and then pushed to the dataLayer array [a related article]. So it turns out that in my script (custom HTML) I could have referred to the global variable rather than dataLayer[0].google_tag_params.

If you’d like to make use of the script I came up with to copy the key/value pairs to my own Conversion object here’s part of it in a GitHub Gist.