One of the cool things about using a tag management solution is that you can leverage variables like never before. In Google Tag Manager, these variables are referred to as macros, and you can identify a macro with the syntax of {{macro name}}. In this tip I’ll show you how you can actually call macros from other macros, using a Lookup Table as an example.

Tip 5: Chain Macros In Lookup Tables (And Other Macros)

It’s not just Lookup Tables, either. You can pretty much use a macro in any field where there is a script context (because macros are JavaScript functions and require a script context to be run). Valid fields are, for example, Custom HTML Tags, Custom JavaScript Macros, Google Analytics tag fields, and so on.

Leveraging macros like this is a really cool way to make your tag setups more flexible AND leaner at the same time. In the picture above, I use two Lookup Tables, chained together, to achieve the following:

1) If the hostname of the page is A or B, then return the respective Tracking ID 2) If the hostname is C and Debug Mode is on, then return the respective Tracking ID 3) If the hostname is C and Debug Mode is false, then return the respective Tracking ID

So instead of having a bunch of tags to accommodate for all this variations, I can just have a single tag and let macros do the work.

Just remember, chaining too many macros together can quickly become a management nightmare. Only use macros to return a calculated value, never to set or push anything by themselves.

Here’s some further reading for you: