What we think

Using GTM to avoid (not set) in Google Analytics

If you use a Google Tag Manager variable whose type is “number” to send data to Google Analytics, you may notice that some of your data comes through as (not set), rather than the value you wanted.

Google Analytics data

The example above shows an event label which is pulled in from the score on a quiz with 5 questions. This is pulled when the quiz is completed. There is one score missing – 0.

Using Google Tag Manager debugger, I can tell that the variable fires from the data layer as 0. It doesn’t appear as (not set) or undefined.

Variables in Google Tag Manager

Above: score – Data Layer Variable – number – 0

As well as this, if I look at the event firing, the label it is pulling in is 0.

Tags in Google Tag Manager

Above: Label – 0

From this information, it seems that the event label in Google Analytics will be 0. However, along the way 0 is transformed to (not set). This is not the first time I’ve noticed Google Tag Manager debugger reading unreliably.

TIP: When debugging, make sure to check the real-time data in Google Analytics after your tag is live, to ensure the data appears as expected.

I managed to rewrite (not set) to 0 by creating a new look-up table variable which maps 0 to itself. Because all the other scores were working I set the default value as the original score, so they would remain unchanged. I then used this new variable as the label for the event tag.Event tagging in Google Tag Manager

What this new variable does is transform 0 from a number to a string. For some reason Google Analytics parses the number 0 as (not set) but the string ‘0’ as 0.

Reviewing what Google Tag Manager Debugger shows you can see the slight difference in using score (number) and score string (string) as a variable.

Variables in Google Tag Manager Debugger

In Google Analytics we can now read the event label as 0 instead of (not set).

Event labels in Google Tag Manager

There are some other solutions that I haven’t personally tried, such as ensuring the data layer variable is coded as a string to begin with (unless you’re using this variable as a metric or for some other calculations) or using a custom JavaScript variable to transform numbers to strings. There may be other scenarios where this occurs, but the number 0 is the only instance I’ve noticed this occurring.

Related posts