Ad

What's Wrong With My Variable Definition In Google Tag Manager?

I have pushed some values into the dataLayer as you can see below, I have them on google tag manager debugging console:

enter image description here

I have defined a custom javascript variable like this:

function() {
    var dest;
    dest = google_tag_manager[{{Container 
    ID}}].dataLayer.get("DestinationLocation").fromLocation;
    return dest;
 }

but still, it's undefined in the variable list.

enter image description here

Ad

Answer

You are trying to get a reference to the tag manager object, and while this works in tags it does not work in variables.

There is no reason why this should work - if the value is on the dataLayer (either via a push, or via the datalayer.set method) you can just create a dataLayer variable that will return the value. No need for any custom scripting.

Ad
source: stackoverflow.com
Ad