Using data layer values in your Google Publisher Tag

There are a lot of similarities between the data layer and Google Publisher Tag key-values. They are both ways of passing structured (and often dynamic) data from your website to an external program. Both of them consist of a list of key-value pairs.

Your data layer might even contain exactly the same data values as your Google Publisher Tag. For example, here on Technically Product, I include the post ID in both the data layer and in the Google Publisher Tag. If the data layer has the following:

Then the Google Publisher Tag will have the equivalent:

However while your data layer is most likely to be for the benefit of your tag management system (eg Google Tag Manager), your Google Publisher Tag key-values will be for Google Ad Manager.

In GTM, the data can be used as part of a trigger or a tag; I may want to trigger a tag on a particular post ID, for example. In Google Ad Manager (still often called Google DoubleClick for Publishers, or DFP), it is used for custom ad targeting; I may want to serve an ad on a particular post ID. To summarise:

Structure Used by For use with
Data layer Google Tag Manager Triggers and tags
Google Publisher Tag key-values Google Ad Manager Ad targeting

I've never quite understood why Google Ad Manager cannot just make use of the data layer. Because of this limitation, you may end up sending the same data to two different Google tools in two different but similar ways. Going back to my postid example, this is how I send the postid to the data layer using php:

And the equivalent for the data layer:

This is obviously a simple example - but if I were ever to change how the data layer value was generated, I would need to remember to make the same change for the Google Publisher Tag too. Wouldn't it be nice if I could just pass my data layer values into my Google Publisher Tag? Then, even if I updated my data layer, I wouldn't need to touch my Google Publisher Tag code.

So I was very pleased to discover that websites built with Abacus' Webvision Cloud platform do exactly that. And Abacus has made the code publicly available as a Gist on Github.

In brief, they use a small script like this before the Google Publisher Tag:

And then make use of that function within the Google Publisher Tag as follows:

That passes the data layer value (in this case 'postid') into the Google Publisher Tag. And it removes the need to use php within the Google Publisher Tag code.

Thanks, Abacus - great work!

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright © James Clark
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram