Google Tag Manager: Lookup table and DRY Principle

By default Google Tag Manager (GTM) provides several handy macros and lookup table macro is one of them. In GTM, by using lookup table macro you can reduce number of deployed tags as well as the number of rules you need to load the tags. When implementing tags in GTM always follow famous DRY principle (don't repeat yourself). Use of lookup table avoids duplication and enables reusability. One common use case of lookup table macro is to separate Google Analytics (GA) tracking IDs for different environments - Test vs UAT vs production, etc.

Lookup table macro is also useful when there are multiple properties. For instance a global retailer with multiple ecommerce website each with different GA tracking IDs but under the hood same tracking implementation. This makes tracking implementation more manageable - implement once for all properties.

Recently I was asked to add 15 or so Sizmek (formerly MediaMind) activity tags in one of our GTM containers. An image or noscript version of Sizmek activity tag looks like following snippet. Basically each tag has its own unique activityIDand corresponding activity page URL.

<img width="1" height="1" style="border:0" src="HTTP://"/>

In my case I had 15 of these tags. One option was to create 15 GTM tags and corresponding 15 GTM rules - easy but less manageable. A better alternative will be to use lookup table macro. Let me show you how.

Tag Template

Lets first create the custom HTML tag sizmekActivityTag using following template. Template is using a custom GTM macro sizmekActivityID.

<img width="1" height="1" style="border:0" src="HTTP://{{sizmekActivityID}}&ns=1"/>

GTM Sizmek Activity Tag - noscript version

Lookup Macro

Then we will create a lookup table macro sizmekActivityID used in above templates. As you can see in following image, we have added rows of URL path and corresponding activity IDs in the table. Basically GTM will lookup this mapping table to use appropriate activity ID depending on URL path. Let also set a default value NA for this macro which will come handy for firing rule.

GTM lookup table macro for Sizmek activity tag

Firing Rule

Now last bit, use sizmekActivityID macro for the tag firing rule - load sizmekActivityTag tag only when sizmekActivityID not equals to NA.

GTM Sizmek activity tag firing rule

End result, we have a single tag - not 15 tags in our GTM container.


DRY principle (don't repeat yourself) is one of the key rules for effective tag management. Using GTM lookup macro smartly you can not only avoid tag duplication but also reduce number of tags drastically.