#GTMtips: Undefined Dimensions Won't Get Sent

By making sure that unneeded variables are resolved to undefined, Google Tag Manager automatically drops the from tags.

This might not sound like a tip to you. You might think, “Dimensions won’t get sent? Sounds like a bug!”. You’re wrong. This is one of the awesome features of the GA API, and it’s key to making your tag setups leaner when sending data to Google Analytics.

Tip 4: Undefined dimensions are left out of GA hits

Note that ‘undefined’ here means the special value undefined in JavaScript. For a refresher, check this post. If you use a macro in a dimension field of Google Tag Manager’s Universal Analytics tags, this dimension will be left out of the hit payload if its return value is undefined.

The hit itself will get sent, but the dimension will just be dropped out.

How is this awesome? Well, you might have thought until now that you need two tags for each version of the dimension reference: one for when it has a value, and one when its value is undefined. The latter version doesn’t have the dimension field populated at all.

You don’t have to go through this duplication of tags if you learn to use the power of undefined in your GTM macros. Just make sure the value is really undefined and not 'undefined', which is a String.

It’s not just Custom Dimensions this works with. Any fields that are translated into dimensions behave the same way, meaning you can use this to send pretty darn efficient virtual pageviews as well, as they use the Document Path field in your tags.