Saturday, December 21

Undefined Variable in Google Tag Manager

In the middle of October 2018, Google Tag Manager silently introduced a new feature that caused some questions in the GTM community (including me), an Undefined variable.

In this quick guide, I’ll shed some light on what an Undefined variable in Google Tag Manager is and where you can use it.

 

First of all, you can find this variable among other User-defined variables in your GTM container:

It is simple to configure. In fact, it has no settings at all ? (if we ignore the standard “Format Value” feature).

And all this variable does is just return an undefined value. So why is it useful?

The answer: you can use it in your GTM stack to keep the data cleaner. Let me explain.

In September, GTM introduced Format Value option in variables’ settings that allows you to format the output of your variables thus make it more standardized and cleaner. The next step GTM took in data cleaning was the introduction of the Undefined variable.

In case you did not know, Google Analytics tags (in GTM) drop a parameter from the payload (read request sent to Google Analytics) if that parameter’s value is undefined. And that’s where the Undefined Variable might become useful.

Example use case of the Undefined Variable

So if you have a lookup or regex table with multiple rows, you might sometimes want that table to return an undefined value instead of a string. Let me illustrate.

Disclaimer: I could not come up with a solid example here so don’t be too hard about it.

Say that I run a website with multiple categories (total number of categories is 6). Those categories are visible in the Page URL, e.g. www.example.com/category/loremipsum. Now, for some reason, you want to see 5 out of 6 categories in your GA reports as a custom dimension, while one (not-so-important) should remain untouched. What should you do?

You could use a Regex Variable (or Lookup) here. It could check the Page Path (or Page URL) of the current page, parse it and if a certain condition is met, it would output the name of the Category. Later that output could be sent over to Google Analytics as a custom dimension.

Here’s a screenshot of the sample Regex Variable where I also use the new Undefined Variable.

If the {{Page URL}} variable matches one of the first 5 rules, it will return a particular output value (e.g. Category 1, etc.). If the URL of the current page matches the 6th rule, then its value will be returned as undefined. Not the string (text) “undefined” but the actual undefined value (read no value at all).

***

Quick sidenote: you might say that an Undefined variable is obsolete here because you just can use certain Regular Expression patterns to exclude the 6th category. You are right. But as I have mentioned several paragraphs ago, I could not come up with a solid example for this case, therefore, I’m playing soft here. End of a sidenote.

***

Why can’t you just enter a plain word “undefined” in the output value of the lookup/regex table? Because if you do so, “undefined” will be passed as a text to GA and you’ll see “undefined” in your GA reports. However, if you passed the undefined value (not as a text/string but as an actual undefined value), then GA tag in GTM would drop this parameter from the request and your GA reports would stay cleaner.

The difference between undefined and “undefined”

If you feel confused regarding the difference between undefined and “undefined” values, take a look at the screenshot below. Here I have created a sample Regex table with two possible outputs, “undefined” or undefined.

In the Output A, you can see a string “undefined”, which is a text that consists of one adjective, “undefined”. Output B, on the other hand, has no value, therefore, it is undefined.

If you pass a string “undefined” to GA, you’ll see that very exact text in your GA reports (for example, if you pass it as a Custom Dimension). But if you pass a parameter with no value (undefined), then it will be dropped before being sent to GA. So if you insert an Undefined Variable to a Lookup/Regex table, you could keep your GA reports slightly cleaner.

Another side note: Keep in mind that Regex and Lookup tables default to undefined value anyway, therefore, the screenshot above is just for demonstration purposes and, in fact, the 2nd row in the table (related to “blog”) is obsolete because it would not make any difference. If {{Page URL}} does not contain”post”, it would always output the undefined value. Why did I show it then? I just wanted to show you how a string and undefined values look in the Preview and Debug mode.

Undefined Variable in Google Tag Manager: Conclusion

This little neat GTM upgrade can be helpful when you need a variable with an actual undefined value. In this blog post, I shared an example where you can use an Undefined Variable in Regex or Lookup table.

However, it’s not an innovation that was impossible before. Prior to this feature, you were still able to create an Undefined Variable in GTM, but with a Custom JavaScript Variable.

So you can treat the new Undefined Variable as a more elegant solution for non-developers who are allergic (?) to code ?

If you noticed that I missed something or have some other related questions, feel free to drop a comment below.

 

Source: analyticsmania

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x