Set GTM default values

One point in my GTM wishlist was I wanted default values for more variable types. Turns out there is already a way to get that, even if it’s a little (just a little) more convoluted than just setting a field.

The idea behind a default value is that you check if a variable is set at all, and return the set value; if it is not set return a prefined value instead. So you have to return an output based on a variable input, and there is a variable type in GTM that does this: the lookup table.

To be as anticlimactic as possible: the simple trick behind is that the lookup table can return its input variable as output, after is has checked that the value is set. You do so by setting the input variable as default value, so the original value will be returned unless the value is not set – in that case you return your default:

Set a default Value in GTM

“someVariable” is a variable that would not usually have an default value – e.g. a cookie, or a javascript variable. These return “undefined” if they are not set, so you check for that in in a single-row lookup table and return a value of your choice.

If the input variable does not equal undefined you return a default value, which you set to the original input variable.

The cute thing is that this work also for more complex situations – image e.g. you want to return the value for a campaign url query variable with a default value if it isn’t set, but you also want to disregard campaigns from Affiliate A because Affiliate A has been annoying you recently. Simply add his name as a row in the lookup table and have it return the default value, and you have successfully cheated him out of his commission, thus demonstrating the value of default values for GTM variables.

Leave a Reply

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