{"id":174397,"date":"2025-04-06T22:02:59","date_gmt":"2025-04-06T22:02:59","guid":{"rendered":"https:\/\/peraltafinancing.com\/analytics\/macro-guide-for-google-tag-manager\/"},"modified":"2025-04-06T22:02:59","modified_gmt":"2025-04-06T22:02:59","slug":"macro-guide-for-google-tag-manager","status":"publish","type":"post","link":"https:\/\/fivemor.com\/?p=174397","title":{"rendered":"Macro Guide For Google Tag Manager"},"content":{"rendered":"<p> <br \/>\n<\/p>\n<div>\n<p><em>I\u2019ve written a new <a href=\"https:\/\/www.simoahava.com\/analytics\/variable-guide-google-tag-manager\/\">Variable Guide for Google Tag Manager<\/a>, which covers the new GTM UI. This guide is for the old UI.<\/em><\/p>\n<p>You might be vaguely familiar with macros if you\u2019ve ever used a computer. Basically, whenever you perform a complicated task with a simple gesture, or reuse complex code with a simple input mechanism, you\u2019re using macros. Think keyboard shortcuts.<\/p>\n<p>In <a href=\"https:\/\/www.google.com\/tagmanager\">Google Tag Manager<\/a>, this is the essence of macros. You can do away with a lot of complexity by resorting to macros, especially if you ever find that you need the same piece of code or the same operation over and over again.<\/p>\n<p>This guide will first take a cursory look at what macros really are, before going through the (current) list of available macros. I\u2019ll add short examples and use cases for each, but there\u2019s a whole lot more to be found online.<\/p>\n<p>                <span class=\"simmer\"><br \/>\n  <span class=\"close\">X<\/span><\/p>\n<p>\n    <span class=\"fa fa-md fa-bell\"\/><br \/>\n    <strong>The Simmer Newsletter<\/strong>\n  <\/p>\n<p>\n    Subscribe to the <a href=\"https:\/\/www.simoahava.com\/newsletter\/\">Simmer newsletter<\/a> to get the latest news and content from Simo Ahava into your email inbox!\n  <\/p>\n<p>  <\/span><\/p>\n<h2 id=\"what-is-a-macro\">What is a macro<\/h2>\n<p>In Google Tag Manager, a macro is a construct that you can set up in the UI. However, it\u2019s not a tag in the sense that it would be something you\u2019d <em>tag<\/em> your page with. Rather, macros are turned into a function of the <em>google_tag_manager<\/em> object (more on this later), and they return a value when called.<\/p>\n<div style=\"aspect-ratio: 630 \/ 228;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/02\/macro-in-ui.jpg\" title=\"Macros in GTM\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"228\" width=\"630\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/02\/macro-in-ui.jpg#ZgotmplZ\" alt=\"Macros in GTM\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>So a macro is, in essence, a placeholder for some value that you might need in your tags. Most common uses for macros would be to:<\/p>\n<ul>\n<li>\n<p>Retrieve a constant string (e.g. your tracking code)<\/p>\n<\/li>\n<li>\n<p>Retrieve a variable string (e.g. the <strong>href<\/strong> attribute of a clicked element)<\/p>\n<\/li>\n<li>\n<p>Retrieve the result of some simple function (e.g. the date and time of the current visit)<\/p>\n<\/li>\n<\/ul>\n<p>Macros are thus used to call for and to retrieve certain values. You can surely see how they facilitate your day-to-day GTM use, can\u2019t you? It\u2019s much easier to just refer to a macro name rather than having to write the value-retrieving function over and over again.<\/p>\n<div style=\"aspect-ratio: 613 \/ 175;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/02\/macro-example.jpg\" title=\"An example of a GTM macro\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"175\" width=\"613\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/02\/macro-example.jpg#ZgotmplZ\" alt=\"An example of a GTM macro\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>Without macros, whenever you rewrite your hard-coded functions or variables, you have to remember to change them wherever they were used. It\u2019s much easier to just have a macro refer to the original location.<\/p>\n<h2 id=\"technical-details\">Technical details<\/h2>\n<blockquote><p>DISCLAIMER: Note that the following analysis is my own and only for illustrative purposes. Don&#8217;t attempt to use the DOM functions uncovered here in your own code, since they are liable to change without notice. Use macros only via the GTM UI using the syntax required by the tool.<\/p><\/blockquote>\n<p>Well my skills at reverse engineering minified JavaScript code are pretty sparse, but you can uncover a lot just by going through the DOM (Document Object Model) tree of a page where macros are active. You can do this by using a JavaScript console in your browser\u2019s developer tools. Just type <strong>window<\/strong> and click enter.<\/p>\n<p>For example, if you go through the DOM, you\u2019ll find an object called <strong>google_tag_manager<\/strong>:<\/p>\n<div style=\"aspect-ratio: 808 \/ 62;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/02\/google-tag-manager-macro.jpg\" title=\"Google Tag Manager object with macro function\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"62\" width=\"808\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/02\/google-tag-manager-macro.jpg#ZgotmplZ\" alt=\"Google Tag Manager object with macro function\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>Here you can see the google_tag_manager array and its contents. There\u2019s an index for your container ID (GTM-XXXX), under which you\u2019ll find the macro function. The function is actually defined in gtm.js, which you load in the GTM container snippet.<\/p>\n<p>The <strong>macro<\/strong> function accepts a single parameter and returns something else.<\/p>\n<p>It appears that the parameter is a numeral value which refers to a certain macro that you\u2019ve set up in GTM. I didn\u2019t find any way to actually identify which number returns which macro value, but just by testing you can find a lot of stuff. For example, I have a macro which stores the number of images on the page. Twiddling around with the macro function I finally found the correct index:<\/p>\n<div style=\"aspect-ratio: 298 \/ 32;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/02\/macro-test.jpg\" title=\"Testing a macro index via JavaScript console\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"32\" width=\"298\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/02\/macro-test.jpg#ZgotmplZ\" alt=\"Testing a macro index via JavaScript console\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>So as you can see, when you refer to a macro in your tag setup, e.g. {{number_of_images}}, it actually translates to a JavaScript function call that returns the value.<\/p>\n<p>This is also the reason why your macros don\u2019t accept parameters. The macro itself is a function call which only takes the index number of the macro as its parameter. Runtime evaluation is done on the spot with only elements found in the Document Object Model to work with.<\/p>\n<p>This is why you\u2019ll see <em>undefined<\/em> for those indices which expect a value in the data layer that hasn\u2019t been pushed yet. As soon as the value is pushed into the data layer, you\u2019ll find that the macro index returns the appropriate value.<\/p>\n<h2 id=\"how-to-use-macros\">How to use macros<\/h2>\n<p>To use a macro, you refer to it in GTM with its name between two sets of curly brackets:<\/p>\n<p><strong>{{macro name}}<\/strong><\/p>\n<p>Note that this is case-sensitive, so {{macro name}} and {{Macro name}} refer to different things.<\/p>\n<p>You can use macros in any GTM fields which accept a text string, e.g.:<\/p>\n<div style=\"aspect-ratio: 446 \/ 496;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/02\/macros-in-fields.jpg\" title=\"Macros in GTM tag fields\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"496\" width=\"446\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/02\/macros-in-fields.jpg#ZgotmplZ\" alt=\"Macros in GTM tag fields\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>On top of that (and this is really cool), you can refer to macros in your custom HTML tags:<\/p>\n<div style=\"aspect-ratio: 313 \/ 118;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/02\/custom-html-macro.jpg\" title=\"Macro in Custom HTML tag\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"118\" width=\"313\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/02\/custom-html-macro.jpg#ZgotmplZ\" alt=\"Macro in Custom HTML tag\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>Here, I check whether or not the clicked link <strong>href<\/strong> contained the text \u201c.pdf\u201d. Since it\u2019s an <a href=\"https:\/\/www.simoahava.com\/analytics\/auto-event-tracking-google-tag-manager\/\">auto-event macro<\/a> I\u2019m using, the macro won\u2019t return a proper value until the auto-event variable is pushed into the data layer. So upon page load the macro {{element url}} would return <em>undefined<\/em>, but after I click a link, it would return the href attribute of the link. This means that in order for this tag to work like it should, I need a firing rule which prevents it from firing until after the auto-event variable is pushed into the data layer. Runtime evaluation, remember?<\/p>\n<p>You can also, and this is really REALLY cool, refer to macros in other macros!<\/p>\n<div style=\"aspect-ratio: 313 \/ 100;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/02\/custom-javascript-macro.jpg\" title=\"Macro in a custom JavaScript macro\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"100\" width=\"313\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/02\/custom-javascript-macro.jpg#ZgotmplZ\" alt=\"Macro in a custom JavaScript macro\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>This returns the tag name of the first child of the clicked element.<\/p>\n<p>There\u2019s a small point to make about using macros and JavaScript. You can only treat a macro as a JavaScript object in the <strong>context of a script<\/strong>. This means that you can freely access macro properties with dot notion, e.g. <strong>{{element}}.innerText<\/strong>, in Custom HTML tags and Custom JavaScript macros. However, this won\u2019t work in other GTM fields where you can use macros (e.g. Event Category), because these fields do not run JavaScript functions. So if you want to access a property of a macro in a tag field, for example, <strong>you will need to create a separate macro for this property<\/strong>.<\/p>\n<div style=\"aspect-ratio: 304 \/ 292;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/02\/macro-in-fields.jpg\" title=\"Macro in script vs. field\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"292\" width=\"304\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/02\/macro-in-fields.jpg#ZgotmplZ\" alt=\"Macro in script vs. field\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>You\u2019ll also use macros a lot in your firing and blocking rules:<\/p>\n<div style=\"aspect-ratio: 513 \/ 224;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/02\/fire-only-debug.jpg\" title=\"Firing rule for debug mode\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"224\" width=\"513\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/02\/fire-only-debug.jpg#ZgotmplZ\" alt=\"Firing rule for debug mode\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>This rule would fire only when visits are tracked to my GA debug account.<\/p>\n<p>Here\u2019s the key takeaway:<\/p>\n<p><strong>Use a macro whenever you need to reuse a certain value or value-returning function.<\/strong><\/p>\n<p>I won\u2019t add a separate section for when <strong>not<\/strong> to use a macro, but suffice to say, if you only need a certain value once or you have a function which you know won\u2019t be reused, don\u2019t bother creating a macro for it. Just hard-code it into your custom HTML tag or use the value directly in your tags. A macro is always, after all, another function call, which does increase the complexity of your code.<\/p>\n<p>Rules are a bit different, since you <strong>must<\/strong> use macros in rules. You can\u2019t write an ad hoc function into your rule; you must have a macro which you evaluate on runtime.<\/p>\n<h2 id=\"the-different-macro-types-in-gtm\">The different macro types in GTM<\/h2>\n<p>Here, I\u2019ve listed all the different macro types you can create in Google Tag Manager (at the time of writing). I\u2019ve added a short description, and an example use case for each.<\/p>\n<p>All macros need a name, which you refer to (case-sensitive) using two sets of curly brackets, e.g. {{macro name}}.<\/p>\n<p>Also, you can give a <strong>default value<\/strong> to some of the macros. It\u2019s a good practice to use a default value, because you can use that as a blocking rule (e.g. {{macro}} equals \u201cdefault\u201d) in your tags, and you can avoid getting the pesky <em>undefined<\/em> as a return value.<\/p>\n<p>Note also that there\u2019s a difference between <strong>macro type<\/strong> and <strong>macro instance<\/strong>. Below, I list all the different macro <em>types<\/em> you can use to create different macro <em>instances<\/em>. You can have as many instances of a macro type as you want (as long as they have different names). Macro types are provided by GTM, and you can\u2019t edit or create new macro types.<\/p>\n<div style=\"aspect-ratio: 736 \/ 265;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/02\/macro-instance-type.jpg\" title=\"Macro instance and macro type\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"265\" width=\"736\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/02\/macro-instance-type.jpg#ZgotmplZ\" alt=\"Macro instance and macro type\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>When you create a new container, you get the following pre-populated <strong>macro instances<\/strong>. Encased in brackets is the type of macro the pre-populated macro is an instance of:<\/p>\n<ul>\n<li>\n<p>element (Auto-Event Variable \/ Element)<\/p>\n<\/li>\n<li>\n<p>element classes (Auto-Event Variable \/ Element Classes)<\/p>\n<\/li>\n<li>\n<p>element id (Auto-Event Variable \/ Element ID)<\/p>\n<\/li>\n<li>\n<p>element target (Auto-Event Variable \/ Element Target)<\/p>\n<\/li>\n<li>\n<p>element url (Auto-Event Variable \/ Element URL)<\/p>\n<\/li>\n<li>\n<p>event (Custom Event)<\/p>\n<\/li>\n<li>\n<p>referrer (HTTP Referrer)<\/p>\n<\/li>\n<li>\n<p>url (URL \/ URL)<\/p>\n<\/li>\n<li>\n<p>url hostname (URL \/ Host Name)<\/p>\n<\/li>\n<li>\n<p>url path (URL \/ Path)<\/p>\n<\/li>\n<\/ul>\n<p>So you might be a bit confused at first, since you have these pre-populated macros which are named the same as the macro types they are instances of. But you\u2019ll get the hang of it soon enough, don\u2019t worry.<\/p>\n<h3 id=\"1-1st-party-cookie\">1. 1st Party Cookie<\/h3>\n<div style=\"aspect-ratio: 487 \/ 260;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/02\/1st-party-cookie.jpg\" title=\"1st Party Cookie\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"260\" width=\"487\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/02\/1st-party-cookie.jpg#ZgotmplZ\" alt=\"1st Party Cookie\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>DESCRIPTION<\/strong><\/p>\n<p>The 1st Party Cookie macro returns the value of the cookie whose name you indicate in the Cookie Name field. For example, if you set up a cookie named \u201cfront-page-visits\u201d which increases by one every time the visitor visits your front page, you can set up this macro to return the value (i.e. number of visits) every time the macro is used.<\/p>\n<p><strong>USE CASE<\/strong><\/p>\n<p>Check my previous article on <a href=\"https:\/\/www.simoahava.com\/analytics\/universal-analytics-fire-script-just-per-session\/\">the session cookie<\/a> for a nice use case for this macro.<\/p>\n<p>Basically this macro can be used to replace any code you used to have for retrieving cookie values.<\/p>\n<h3 id=\"2-auto-event-variable\">2. Auto-Event Variable<\/h3>\n<div style=\"aspect-ratio: 602 \/ 381;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/02\/auto-event-variable.jpg\" title=\"Auto-Event Variable\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"381\" width=\"602\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/02\/auto-event-variable.jpg#ZgotmplZ\" alt=\"Auto-Event Variable\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>DESCRIPTION<\/strong><\/p>\n<p>When you <a href=\"https:\/\/www.simoahava.com\/analytics\/auto-event-tracking-google-tag-manager\/\">set up an event listener<\/a> using GTM, you can use the auto-event variable macros to return the value of various attributes of the element you were listening to.<\/p>\n<p>You need to specify the variable type of the auto-event variable you want to use. Here are the different types.<\/p>\n<p><em>Element<\/em>: This returns the element that was clicked. Note that the macro returns an object, not a string, so the best use of it is for traversing the DOM tree of the clicked element (e.g. <strong>{{Element}}.children[0].tagName<\/strong> returns the tag name of the first child of the clicked element).<\/p>\n<p><em>Element classes<\/em>: This returns the class attribute of the element that was clicked. For example, if the element was <code><\/p>\n<div class=\"&quot;mainBanner&quot;\">, you\u2019d get \u201cmainBanner\u201d as the return value.<\/p>\n<p><em>Element ID<\/em>: This returns the ID attribute of the element that was clicked. For example, if the element was <code><a href=\"&quot;\/home&quot;\" id=\"&quot;home-link&quot;\/\"\/><\/code>, the macro would return \u201chome-link\u201d.<\/p>\n<p><em>Element target<\/em>: This returns the target attribute of the element that was clicked. For example, if the element was <code><a href=\"&quot;\/home&quot;\" target=\"&quot;blank&quot;\/\"\/><\/code>, the macro would return \u201cblank\u201d.<\/p>\n<p><em>Element text<\/em>: This returns the text content (if any) of the element that was clicked. It returns either the innerText or the textContent property (depending on what browser the visitor uses).<\/p>\n<p><em>Element URL<\/em>: This returns the href (in e.g. links) or action (in e.g. forms) attribute of the clicked (or submitted) element. For example, if the element was <code\/>, the macro would return \u201c\/process-form\u201d. You can also choose which URL component is returned by the Element URL macro (see the chapter on URL macros for a description of component types).<\/p>\n<p><em>History New URL Fragment<\/em>: The <em>History<\/em> macros are populated by the History Listener. History New URL Fragment returns the URL fragment set in the current history state. You can use this to fire your tags (e.g. pageview) when a certain URL fragment is in the URL.<\/p>\n<p><em>History Old URL Fragment<\/em>: Returns the URL fragment set in the previous history change event. For example, if you first navigate to <strong>#aboutus<\/strong> then to <strong>#contact<\/strong>, History New URL Fragment will return \u201caboutus\u201d and History Old URL Fragment will return \u201ccontact\u201d.<\/p>\n<p><em>History New State<\/em>: History New State returns the state object stored in the current history entry (if any). You can access the properties of this object to set up your content and fire your dynamic tags. Note that it\u2019s an <em>object<\/em> that is returned, so you can\u2019t use it directly in any GTM fields. You\u2019ll need to use some programming logic to access the properties of this object if you want to send them as strings with your tags.<\/p>\n<p><em>History Old State<\/em>: The previous state stored in browser history (if any). You can use this to determine what the previous browser history state was, for example if navigation patterns determine the tags you want to fire.<\/p>\n<p><strong>USE CASE<\/strong><\/p>\n<p>There\u2019s a million different things you can use auto-event variables for. The variables are most frequently used to refer to certain aspects of the element in event descriptions. You could, for example, add {{element url}} as the action of a GA event which measures link clicks on your different pages.<\/p>\n<p>Check my tutorial on <a href=\"https:\/\/www.simoahava.com\/analytics\/auto-event-tracking-google-tag-manager\/\">auto-event tracking<\/a> to see how the different auto-event variables can be used to improve your site measurement.<\/p>\n<h3 id=\"3-constant-string\">3. Constant String<\/h3>\n<div style=\"aspect-ratio: 446 \/ 265;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/02\/custom-string.jpg\" title=\"GA tracking code as macro\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"265\" width=\"446\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/02\/custom-string.jpg#ZgotmplZ\" alt=\"GA tracking code as macro\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>DESCRIPTION<\/strong><\/p>\n<p>This macro can be used to store a string you\u2019d use over and over again. In other words, it\u2019s a time-saver.<\/p>\n<p><strong>USE CASE<\/strong><\/p>\n<p>Store your GA tracking code in this, so you don\u2019t have to remember it in every single tag. Just add the UA-XXXXXXX-X into the \u201cValue\u201d field, and name the macro \u201cGA Tracking Code\u201d or something similar. After that, whenever your tracking code is required (e.g. in tags), you can just use the macro {{GA Tracking Code}}.<\/p>\n<h3 id=\"4-container-version-number\">4. Container Version Number<\/h3>\n<div style=\"aspect-ratio: 593 \/ 214;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/02\/container-version-number.jpg\" title=\"Container version number\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"214\" width=\"593\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/02\/container-version-number.jpg#ZgotmplZ\" alt=\"Container version number\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>DESCRIPTION<\/strong><\/p>\n<p>This returns your GTM container version number. If you\u2019re in the Preview mode (as you should be whenever you\u2019re testing), this returns the preview container version number.<\/p>\n<p><strong>USE CASE<\/strong><\/p>\n<p>A nice way to use it is to output the version number into the console using <strong>console.log({{container version}});<\/strong> in your Custom HTML tag. This way you can always check the console if you\u2019re unsure which version you\u2019re currently running. It\u2019s a good way to debug your live implementation.<\/p>\n<h3 id=\"5-custom-event\">5. Custom Event<\/h3>\n<div style=\"aspect-ratio: 542 \/ 212;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/02\/event.jpg\" title=\"Event macro\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"212\" width=\"542\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/02\/event.jpg#ZgotmplZ\" alt=\"Event macro\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>DESCRIPTION<\/strong><\/p>\n<p>This macro returns the data layer \u201cevent\u201d value of the last event that was pushed into the array. So if you\u2019ve just executed <strong>dataLayer.push({\u201cevent\u201d: \u201cmyEvent\u201d});<\/strong>, this macro will return \u201cmyEvent\u201d.<\/p>\n<p><strong>USE CASE<\/strong><\/p>\n<p>This should be one of your most familiar macros. It comes with every container setup under the name {{event}}. There are about a zillion use cases for this, most notably in firing and blocking rules. For example, if you only want a tag to fire when the event \u201cfireNow\u201d has been pushed into the data layer, you can add the rule <strong>{{event}} equals fireNow<\/strong> to your tag. Then, as soon as you execute <strong>dataLayer.push({\u201cevent\u201d: \u201cfireNow\u201d});<\/strong> the event macro will be populated with the value \u201cfireNow\u201d and your firing rule will trigger.<\/p>\n<h3 id=\"6-custom-javascript\">6. Custom JavaScript<\/h3>\n<div style=\"aspect-ratio: 578 \/ 371;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/02\/custom-javascript-macro.jpg\" title=\"Custom JavaScript Macro\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"371\" width=\"578\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/02\/custom-javascript-macro.jpg#ZgotmplZ\" alt=\"Custom JavaScript Macro\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>DESCRIPTION<\/strong><\/p>\n<p>Use this macro to perform a simple JavaScript function using either ad hoc values or elements in the DOM tree. The JavaScript function <strong>has<\/strong> to be encased in a function structure, it <strong>has<\/strong> to return a value and it <strong>can\u2019t<\/strong> take parameters of its own.<\/p>\n<p><strong>USE CASE<\/strong><\/p>\n<p>You could use it with auto-event tracking to return the value \u201cOutbound link\u201d for all outbound links and \u201cIn-site link\u201d for all in-site links. You can then use these as your Event Category in the event where you send information about the link that was clicked. The function would look like this:<\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-javascript\" data-lang=\"javascript\"><span style=\"color:#00a\">function<\/span>() {\n  <span style=\"color:#00a\">if<\/span>({{element url}}.indexOf(<span style=\"color:#a50\">\"http:\/\/www.my-domain.com\"<\/span>) &gt;= <span style=\"color:#099\">0<\/span>) {\n    <span style=\"color:#00a\">return<\/span> <span style=\"color:#a50\">\"In-site link\"<\/span>;\n  } <span style=\"color:#00a\">else<\/span> {\n    <span style=\"color:#00a\">return<\/span> <span style=\"color:#a50\">\"Outbound link\"<\/span>;\n  }\n}\n<\/code><\/pre>\n<\/div>\n<p>See how I\u2019m referring to another macro within this macro? \ud83d\ude42 \u201c<a href=\"http:\/\/www.my-domain.com\/%22\">www.my-domain.com\/\"<\/a> would naturally need to be replaced with your hostname.<\/p>\n<p>Another neat trick is to use a Custom JavaScript macro to retrieve the file extension of the link that was clicked. You can use this to create more dynamic tags. Check out the tip on <a href=\"https:\/\/plus.google.com\/109635181158374226872\/posts\/AuVjXieWx7J\">this Google+ post<\/a>.<\/p>\n<h3 id=\"7-data-layer-variable\">7. Data Layer Variable<\/h3>\n<div style=\"aspect-ratio: 603 \/ 439;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/02\/data-layer-variable.jpg\" title=\"Data Layer Variable\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"439\" width=\"603\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/02\/data-layer-variable.jpg#ZgotmplZ\" alt=\"Data Layer Variable\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>DESCRIPTION<\/strong><\/p>\n<p>Use this macro to refer to the variables you push into the data layer. Remember, you do the push with <strong>dataLayer.push({\u201cVariable_Name\u201d: \u201cSome value\u201d});<\/strong>. If you set this macro to look for \u201cVariable Name\u201d, the return value will be \u201cSome value\u201d.<\/p>\n<p>With \u201cversion 2\u201d (now default), you can refer to nested values using dot notation. For example, if you\u2019ve pushed <strong>dataLayer.push({\u201cProducts\u201d: {\u201cProduct_1\u201d: \u201cLawn mower\u201d}});<\/strong>, by referring to Data Layer Variable Name <strong>Products.Product_1<\/strong>, you\u2019ll get \u201cLawn mower\u201d as the return value.<\/p>\n<p><strong>USE CASE<\/strong><\/p>\n<p>You can use it nicely in conjunction with auto-event tracking. When you click an element, the data layer is updated with the object <strong>gtm.element<\/strong>, which can be traversed like any DOM object. For example, to get the tag name of the object that was clicked, you\u2019d create a data layer variable macro for <strong>gtm.element.tagName<\/strong>. Clicking an image would then return \u201cIMG\u201d.<\/p>\n<h3 id=\"8-debug-mode\">8. Debug Mode<\/h3>\n<div style=\"aspect-ratio: 426 \/ 143;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/02\/debug-mode.jpg\" title=\"Debug Mode\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"143\" width=\"426\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/02\/debug-mode.jpg#ZgotmplZ\" alt=\"Debug Mode\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>DESCRIPTION<\/strong><\/p>\n<p>This returns \u201ctrue\u201d if you\u2019re in Google Tag Manager Debug mode, and \u201cfalse\u201d if you aren\u2019t.<\/p>\n<p><strong>USE CASE<\/strong><\/p>\n<p>See Lookup Table Macro below for a nice use case.<\/p>\n<h3 id=\"9-dom-element\">9. DOM Element<\/h3>\n<div style=\"aspect-ratio: 603 \/ 304;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/02\/dom-element.jpg\" title=\"DOM Element\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"304\" width=\"603\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/02\/dom-element.jpg#ZgotmplZ\" alt=\"DOM Element\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>DESCRIPTION<\/strong><\/p>\n<p>Use this macro to refer to any element that can be found in the Document Object Model. The element needs a unique ID identifier. You can even specify the attribute whose value you want to get in return. If you don\u2019t specify an attribute, you get the text content of the element (if any).<\/p>\n<p><strong>USE CASE<\/strong><\/p>\n<p>Let\u2019s say I want a certain tag to only fire on pages where the text \u201cBy Simo Ahava\u201d can be found in the <code><\/p>\n<div id=\"&quot;author&quot;\"> element. A good use case for just my article pages. For this to work, I\u2019d create a DOM Element macro called \u201cAuthor\u201d with Element ID \u201cauthor\u201d. After that, I can create a firing rule <strong>{{Author}} contains \u201cBy Simo Ahava\u201d<\/strong> for the tag that only fires on my article pages.<\/p>\n<h3 id=\"10-http-referrer\">10. HTTP Referrer<\/h3>\n<div style=\"aspect-ratio: 288 \/ 153;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/02\/http-referrer.jpg\" title=\"HTTP Referrer\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"153\" width=\"288\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/02\/http-referrer.jpg#ZgotmplZ\" alt=\"HTTP Referrer\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>DESCRIPTION<\/strong><\/p>\n<p>This returns the HTTP referrer (i.e. the previous page URL). You can also choose which URL component is returned by the HTTP Referrer macro (see the chapter on URL macros for a description of component types).<\/p>\n<p><strong>USE CASE<\/strong><\/p>\n<p>You can use it to check if this is the first page of the visit or not. Create the macro and then use it like:<\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-javascript\" data-lang=\"javascript\"><span style=\"color:#00a\">if<\/span> ({{referrer}}.indexOf(<span style=\"color:#a50\">\"http:\/\/www.mydomain.com\"<\/span>) &gt;= <span style=\"color:#099\">0<\/span>) { \n  alert(<span style=\"color:#a50\">\"Yay, not the landing page!\"<\/span>); \n} <span style=\"color:#00a\">else<\/span> { \n  alert(<span style=\"color:#a50\">\"Aww, this is the landing page\"<\/span>); \n}\n<\/code><\/pre>\n<\/div>\n<h3 id=\"11-javascript-variable\">11. JavaScript Variable<\/h3>\n<div style=\"aspect-ratio: 443 \/ 220;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/02\/javascript-variable.jpg\" title=\"JavaScript Variable\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"220\" width=\"443\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/02\/javascript-variable.jpg#ZgotmplZ\" alt=\"JavaScript Variable\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>DESCRIPTION<\/strong><\/p>\n<p>This returns the value of a globally defined JavaScript variable.<\/p>\n<p>You can use dot notation to refer to nested variables, e.g. <strong>document.doctype<\/strong> to get the doctype declaration of the current document. (Thanks <a href=\"https:\/\/plus.google.com\/+BrianKuhn\">+Brian Kuhn<\/a> for pointing this out).<\/p>\n<p><strong>USE CASE<\/strong><\/p>\n<p>If you haven\u2019t (or can\u2019t) push the value into the data layer (preferred), or if you can\u2019t find the variable in the DOM, you can use this macro to refer to it. A simple use case would be if you define a global variable (e.g. <strong>var myName=\"Simo\u201d;<\/strong>) in a Custom HTML Tag, you can use this macro to get the content of this variable in other tags as well. Sure, you could just use \u201cmyName\u201d to refer to the global variable, but reusability is the key here. If you find that you need to change the variable reference, you just need to change it once in the variable definition and once in the macro, rather than many times in all the tags where you refer to the variable.<\/p>\n<h3 id=\"12-lookup-table\">12. Lookup Table<\/h3>\n<p><strong>DESCRIPTION<\/strong><\/p>\n<p>My favorite macro, by far. Check my five-star <a href=\"https:\/\/www.simoahava.com\/analytics\/google-tag-manager-lookup-table-macro\/\">review of the lookup table macro<\/a> for specifics. The lookup table macro is basically a simple runtime evaluation, where you assign value Y to variable Z if X is something.<\/p>\n<p><strong>USE CASE<\/strong><\/p>\n<p>Here\u2019s a really nice use case (<a href=\"https:\/\/plus.google.com\/109635181158374226872\/posts\/U7kBb4p33yd\">originally on Google+<\/a>). If you use GTM Preview &amp; Debug mode a lot (AND YOU SHOULD!), you might be annoyed at all the debug hits in your GA account (unless, of course, you filter yourself out). You can use a combination of Lookup Table and Debug Mode macros to make sure that debug mode hits are sent to your test account:<\/p>\n<div style=\"aspect-ratio: 550 \/ 398;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/02\/lookup-table-macro.jpg\" title=\"The Lookup Table macro for debug mode\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"398\" width=\"550\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/02\/lookup-table-macro.jpg#ZgotmplZ\" alt=\"The Lookup Table macro for debug mode\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>Here the macro {{GA Tracking Code}} is assigned a variable value depending on the value returned by the {{Debug Mode}} macro.<\/p>\n<p>Remember that lookup tables only accept simple runtime evaluation of \u201cwhen X equals Y\u201d, so you can\u2019t do calculations (e.g. \u201cwhen X\n<\/p>\n<h3 id=\"13-random-number\">13. Random Number<\/h3>\n<div style=\"aspect-ratio: 398 \/ 191;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/02\/random-number.jpg\" title=\"random-number\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"191\" width=\"398\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/02\/random-number.jpg#ZgotmplZ\" alt=\"random-number\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>DESCRIPTION<\/strong><\/p>\n<p>Returns a random number between 0 and 2147483647.<\/p>\n<p><strong>USE CASE<\/strong><\/p>\n<p>You can use it to create a random hash for your URLs (for cache-busting) OR you can <a href=\"http:\/\/dan-russell.com\/2013\/03\/sampling-a-percentage-of-your-users-with-google-tag-manager\/\">follow this example<\/a> of using the random number to fire a tag for only a certain percentage of your visitors.<\/p>\n<h3 id=\"14-url\">14. URL<\/h3>\n<div style=\"aspect-ratio: 602 \/ 327;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/02\/url.jpg\" title=\"URL\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"327\" width=\"602\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/02\/url.jpg#ZgotmplZ\" alt=\"URL\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>DESCRIPTION<\/strong><\/p>\n<p>Returns the URL or a specific component thereof. The various component types are:<\/p>\n<p><em>URL<\/em>: Returns the entire URL minus fragment (fragment begins with a #).<\/p>\n<p><em>Protocol<\/em>: Returns the protocol of the URL address (i.e. http or https).<\/p>\n<p><em>Host Name<\/em>: Returns the full hostname of the URL (e.g. <a href=\"https:\/\/www.google.com\">www.google.com<\/a>) or you can choose to strip the www-prefix.<\/p>\n<p><em>Port<\/em>: Returns the port number of the hostname. If no port number is specified, the return value is either 80 or 443 (for http and https, respectively).<\/p>\n<p><em>Path<\/em>: Returns the URI of the URL address, i.e. the structure immediately following the hostname. You can also specify \u201cdefault pages\u201d, which are stripped out of the return value if found.<\/p>\n<p><em>Query<\/em>: Returns the query string of the URL address (without leading question mark and possible fragment). You can also specify a query key for the macro, after which only the value of the key is returned if found in the URL.<\/p>\n<p><em>Fragment<\/em>: Returns the fragment of the URL without the leading #.<\/p>\n<p><strong>USE CASE<\/strong><\/p>\n<p>You could query for only email campaign traffic by creating a URL of component type Query. Set \u201cutm_medium\u201d as the Query Key. Then you can employ a firing rule for only those visits which came via email with <strong>{{URL Query}} equals email<\/strong>.<\/p>\n<h2 id=\"conclusions\">Conclusions<\/h2>\n<p>Macros are a really powerful way of making a complicated setup simple. You can use macros to dramatically reduce the amount of code AND separate tags in your Google Tag Manager container.<\/p>\n<p>When using macros, a bunch of <a href=\"http:\/\/online-behavior.com\/analytics\/tag-manager-conventions\">best practices<\/a> should be observed:<\/p>\n<ul>\n<li>\n<p>Name your macros so that you\u2019ll instantly identify them (e.g. \u201cName - Macro Type\u201d)<\/p>\n<\/li>\n<li>\n<p>Only use macros when they facilitate either coding or maintenance; don\u2019t use them as replacements for one-off functions or variables<\/p>\n<\/li>\n<li>\n<p>Document your macro use somewhere so that you\u2019ll know what repercussions changes might have<\/p>\n<\/li>\n<\/ul>\n<p>The last is especially important in large implementations, where dozens and dozens of macros are used in dozens and dozens of tags.<\/p>\n<p>Do you have any questions about macros? Drop a comment on this post if you didn\u2019t find what you were looking for above.<\/p>\n<\/p><\/div>\n<p>          <\/code><\/p>\n<\/div>\n<footer id=\"footer\" class=\"main-content-wrap\">\n  <span class=\"copyrights\"><br \/>\n    \u00a9 2025 Simo Ahava. All Rights Reserved<br \/>\n  <\/span><br \/>\n<\/footer>\n<p>      <\/code><\/p>\n<\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>I\u2019ve written a new Variable Guide for Google Tag Manager, which covers the new GTM UI. This guide is for the old UI. You might be vaguely familiar with macros if you\u2019ve ever used a computer. Basically, whenever you perform a complicated task with a simple gesture, or reuse complex code with a simple input [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":174398,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12033],"tags":[1531,2059,33546,14495,1791],"dealstore":[],"offerexpiration":[],"class_list":["post-174397","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-analytics","tag-google","tag-guide","tag-macro","tag-manager","tag-tag"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Macro Guide For Google Tag Manager - Som2ny Network<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/fivemor.com\/?p=174397\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Macro Guide For Google Tag Manager - Som2ny Network\" \/>\n<meta property=\"og:description\" content=\"I\u2019ve written a new Variable Guide for Google Tag Manager, which covers the new GTM UI. This guide is for the old UI. You might be vaguely familiar with macros if you\u2019ve ever used a computer. Basically, whenever you perform a complicated task with a simple gesture, or reuse complex code with a simple input [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fivemor.com\/?p=174397\" \/>\n<meta property=\"og:site_name\" content=\"Som2ny Network\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-06T22:02:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/04\/macro-in-ui.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"630\" \/>\n\t<meta property=\"og:image:height\" content=\"228\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"19 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/fivemor.com\/?p=174397#article\",\"isPartOf\":{\"@id\":\"https:\/\/fivemor.com\/?p=174397\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371\"},\"headline\":\"Macro Guide For Google Tag Manager\",\"datePublished\":\"2025-04-06T22:02:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/fivemor.com\/?p=174397\"},\"wordCount\":2935,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/fivemor.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/?p=174397#primaryimage\"},\"thumbnailUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/04\/macro-in-ui.jpg\",\"keywords\":[\"Google\",\"Guide\",\"Macro\",\"Manager\",\"TAG\"],\"articleSection\":[\"Analytics\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/fivemor.com\/?p=174397#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/fivemor.com\/?p=174397\",\"url\":\"https:\/\/fivemor.com\/?p=174397\",\"name\":\"Macro Guide For Google Tag Manager - Som2ny Network\",\"isPartOf\":{\"@id\":\"https:\/\/fivemor.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/fivemor.com\/?p=174397#primaryimage\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/?p=174397#primaryimage\"},\"thumbnailUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/04\/macro-in-ui.jpg\",\"datePublished\":\"2025-04-06T22:02:59+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/fivemor.com\/?p=174397#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/fivemor.com\/?p=174397\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/?p=174397#primaryimage\",\"url\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/04\/macro-in-ui.jpg\",\"contentUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/04\/macro-in-ui.jpg\",\"width\":630,\"height\":228},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/fivemor.com\/?p=174397#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/fivemor.com\/?bp_activities=1\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Macro Guide For Google Tag Manager\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/fivemor.com\/#website\",\"url\":\"https:\/\/fivemor.com\/\",\"name\":\"Som2ny Network\",\"description\":\"Daily Deals\",\"publisher\":{\"@id\":\"https:\/\/fivemor.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/fivemor.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/fivemor.com\/#organization\",\"name\":\"Som2ny Network\",\"url\":\"https:\/\/fivemor.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png\",\"contentUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png\",\"width\":300,\"height\":86,\"caption\":\"Som2ny Network\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png\",\"caption\":\"admin\"},\"sameAs\":[\"https:\/\/fivemor.com\"],\"url\":\"https:\/\/fivemor.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Macro Guide For Google Tag Manager - Som2ny Network","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/fivemor.com\/?p=174397","og_locale":"en_US","og_type":"article","og_title":"Macro Guide For Google Tag Manager - Som2ny Network","og_description":"I\u2019ve written a new Variable Guide for Google Tag Manager, which covers the new GTM UI. This guide is for the old UI. You might be vaguely familiar with macros if you\u2019ve ever used a computer. Basically, whenever you perform a complicated task with a simple gesture, or reuse complex code with a simple input [&hellip;]","og_url":"https:\/\/fivemor.com\/?p=174397","og_site_name":"Som2ny Network","article_published_time":"2025-04-06T22:02:59+00:00","og_image":[{"width":630,"height":228,"url":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/04\/macro-in-ui.jpg","type":"image\/jpeg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"19 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fivemor.com\/?p=174397#article","isPartOf":{"@id":"https:\/\/fivemor.com\/?p=174397"},"author":{"name":"admin","@id":"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371"},"headline":"Macro Guide For Google Tag Manager","datePublished":"2025-04-06T22:02:59+00:00","mainEntityOfPage":{"@id":"https:\/\/fivemor.com\/?p=174397"},"wordCount":2935,"commentCount":0,"publisher":{"@id":"https:\/\/fivemor.com\/#organization"},"image":{"@id":"https:\/\/fivemor.com\/?p=174397#primaryimage"},"thumbnailUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/04\/macro-in-ui.jpg","keywords":["Google","Guide","Macro","Manager","TAG"],"articleSection":["Analytics"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fivemor.com\/?p=174397#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fivemor.com\/?p=174397","url":"https:\/\/fivemor.com\/?p=174397","name":"Macro Guide For Google Tag Manager - Som2ny Network","isPartOf":{"@id":"https:\/\/fivemor.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fivemor.com\/?p=174397#primaryimage"},"image":{"@id":"https:\/\/fivemor.com\/?p=174397#primaryimage"},"thumbnailUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/04\/macro-in-ui.jpg","datePublished":"2025-04-06T22:02:59+00:00","breadcrumb":{"@id":"https:\/\/fivemor.com\/?p=174397#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fivemor.com\/?p=174397"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/?p=174397#primaryimage","url":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/04\/macro-in-ui.jpg","contentUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/04\/macro-in-ui.jpg","width":630,"height":228},{"@type":"BreadcrumbList","@id":"https:\/\/fivemor.com\/?p=174397#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fivemor.com\/?bp_activities=1"},{"@type":"ListItem","position":2,"name":"Macro Guide For Google Tag Manager"}]},{"@type":"WebSite","@id":"https:\/\/fivemor.com\/#website","url":"https:\/\/fivemor.com\/","name":"Som2ny Network","description":"Daily Deals","publisher":{"@id":"https:\/\/fivemor.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/fivemor.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/fivemor.com\/#organization","name":"Som2ny Network","url":"https:\/\/fivemor.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/#\/schema\/logo\/image\/","url":"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png","contentUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png","width":300,"height":86,"caption":"Som2ny Network"},"image":{"@id":"https:\/\/fivemor.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png","caption":"admin"},"sameAs":["https:\/\/fivemor.com"],"url":"https:\/\/fivemor.com\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts\/174397","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=174397"}],"version-history":[{"count":0,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts\/174397\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/media\/174398"}],"wp:attachment":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=174397"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=174397"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=174397"},{"taxonomy":"dealstore","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fdealstore&post=174397"},{"taxonomy":"offerexpiration","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fofferexpiration&post=174397"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}