{"id":171283,"date":"2025-04-04T19:00:18","date_gmt":"2025-04-04T19:00:18","guid":{"rendered":"https:\/\/som2nynetwork.com\/analytics\/macro-magic-for-google-tag-manager\/"},"modified":"2025-04-04T19:00:18","modified_gmt":"2025-04-04T19:00:18","slug":"macro-magic-for-google-tag-manager","status":"publish","type":"post","link":"https:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/","title":{"rendered":"Macro Magic For Google Tag Manager"},"content":{"rendered":"<p> <br \/>\n<\/p>\n<div>\n<p>(Last updated June 2014) This post is an attempt at a whole new level of interaction. These words will transcend the barriers of time and space, bridging together the physical world and its digital counterpart. You see, in an undisclosed number of hours after the publishing of this blog post, I will be talking at the <a href=\"http:\/\/www.measurecamp.org\">MeasureCamp<\/a> unconference on this very subject. Or, I hope I will. The whole unconference thing is somewhat confusing, and it involves lighting-fast reflexes and street smarts for slot selection; traits which I sadly lack.<\/p>\n<div style=\"aspect-ratio: 634 \/ 528;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/03\/measurecamp.jpg\" title=\"Simo at MeasureCamp\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"528\" width=\"634\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/03\/measurecamp.jpg#ZgotmplZ\" alt=\"Simo at MeasureCamp\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>However, if you DO see me speak at MeasureCamp, this post is meant as a companion to that talk. And if you do not (or did not, this transcendental approach is really confusing), perhaps this post will inspire you with some ideas for your own day-to-day <a href=\"https:\/\/www.google.com\/tagmanager\">Google Tag Manager<\/a> use.<\/p>\n<p>In this post, my fair friends, I\u2019ve outlined a number of cool ways in which you can use macros to make your data collection woes a thing of the past. If you don\u2019t know what macros are or how they operate, be sure to check my <a href=\"https:\/\/www.simoahava.com\/analytics\/macro-guide-google-tag-manager\/\">macro guide<\/a>. Almost all of my Google Tag Manager posts in this blog revolve around macros in one way or another, so while you\u2019re at it, check out some of my <a href=\"https:\/\/www.simoahava.com\/tags\/google-tag-manager\/\">other GTM articles<\/a> as well. And sorry for this shameless self-promotion, I can\u2019t help it.<\/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=\"introducing-macro-magic\">Introducing Macro Magic<\/h2>\n<div style=\"aspect-ratio: 300 \/ 300;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/03\/macro-magic.jpg\" title=\"Macro Magic in Google Tag Manager\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"300\" width=\"300\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/03\/macro-magic.jpg#ZgotmplZ\" alt=\"Macro Magic in Google Tag Manager\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>So what is Macro Magic? Well, to put it simply, it\u2019s what follows when you accept that macros, not tags, are what make GTM the time- and effort-saver that it is. Sometimes macros make your tag setups a lot sleeker and leaner, since the flexibility that they introduce to tags greatly reduces the need to capture every single variation of tracking in its own, unique tag. Sometimes they open doors to data collection methods you didn\u2019t think were possible with traditional, on-page tracking. And sometimes they\u2019re just little helper functions, which make operating GTM so much easier.<\/p>\n<p>The examples below fall into these categories nicely, and I\u2019m sure there\u2019s something for everyone.<\/p>\n<p>By the way, I am really, <strong>really<\/strong> looking forward to a Google Tag Manager which is accompanied by a resource library similar to <a href=\"https:\/\/www.google.com\/analytics\/gallery\/\">Google Analytics\u2019 solution gallery<\/a>. Just imagine how cool it would be to have a library of tags and macros you can just download and insert into your container? Well, as long as it\u2019s just a utopian dream of mine, posts like this will probably be in demand.<\/p>\n<p>Note that not all of these are my own inventions. It would be ridiculous to claim intellectual property for some of the macros, but where prudent, I\u2019ve added a link to the source of the macro. If you feel like I\u2019ve stolen your ideas, please let me know and I\u2019ll see if I can pass credit where it is due.<\/p>\n<h2 id=\"1-client-time\">1. Client time<\/h2>\n<p><strong>Macro Type<\/strong>: <a href=\"https:\/\/www.simoahava.com\/analytics\/macro-guide-google-tag-manager\/#6-custom-javascript\">Custom JavaScript<\/a><br \/><strong>Use for<\/strong>: To get local time of <em>client<\/em> as opposed to the the time of the web server hosting the site.<br \/><strong>Example return value<\/strong>: 11<\/p>\n<p><em>Instructions and description<\/em>:<\/p>\n<ol>\n<li>\n<p>Create new Custom JavaScript Macro<\/p>\n<\/li>\n<li>\n<p>Add the following code:<\/p>\n<\/li>\n<\/ol>\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\">var<\/span> now = <span style=\"color:#00a\">new<\/span> <span style=\"color:#0aa\">Date<\/span>();\n  <span style=\"color:#00a\">return<\/span> now.getHours();\n}\n<\/code><\/pre>\n<\/div>\n<p>Well it\u2019s easy to credit where I got the idea for this one. Google uses a version of this as an example of the Custom JavaScript Macro:<\/p>\n<div style=\"aspect-ratio: 713 \/ 279;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/03\/client-time.jpg\" title=\"Client time in JavaScript\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"279\" width=\"713\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/03\/client-time.jpg#ZgotmplZ\" alt=\"Client time in JavaScript\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>The idea behind this macro is that it returns the time (hours) of <em>the client<\/em> as opposed to the time of the website (i.e. server), which is what\u2019s measured by default.<\/p>\n<p>So if you\u2019re interested in what the local time (in hours) is of the visitor, use this macro and store it as a custom dimension, for example.<\/p>\n<h2 id=\"2-random-number-for-sampling\">2. Random number for sampling<\/h2>\n<p><strong>Macro Type<\/strong>: <a href=\"https:\/\/www.simoahava.com\/analytics\/macro-guide-google-tag-manager\/#13-random-number\">Random Number<\/a><br \/><strong>Use for<\/strong>: To fire a tag only for every 10th visitor, for example<br \/><strong>Example return value<\/strong>: 647156<\/p>\n<p><em>Instructions and description<\/em>:<\/p>\n<ol>\n<li>Create Random Number Macro<\/li>\n<\/ol>\n<p>OK, so the macro isn\u2019t difficult at all to create, nor is it anything magical (YET!). But this is a beautiful scenario for something as simple as the Random Number macro (which, I\u2019m sure, is often very neglected). This idea comes directly from Dan Russell, and you can read about this in his original blog post<\/p>\n<p><a href=\"http:\/\/dan-russell.com\/2013\/03\/sampling-a-percentage-of-your-users-with-google-tag-manager\/\">Sampling a percentage of your users with Google Tag Manager<\/a>.<\/p>\n<p>The sweetness is not in the macro but in the rule which you\u2019ll use to fire your tags. If you want to fire a tag for every 10th visitor, you\u2019d add a rule with the following condition:<\/p>\n<p><strong>{{Random Number Macro}} ends with 3<\/strong><\/p>\n<p>If you want to fire a tag for every 100th visitor, you\u2019d edit the rule so that it\u2019s:<\/p>\n<p><strong>{{Random Number Macro}} ends with 01<\/strong><\/p>\n<p>It\u2019s so simple and beautiful. Because the Random Number macro returns a random number, you can assume that there\u2019s roughly a 1\/10 chance that the number will end in 3, and roughly a 1\/100 chance that it will end in 01.<\/p>\n<p>How\u2019s that for pre-sampling your data before Google Analytics gets to work on it with its <a href=\"https:\/\/plus.google.com\/100296234920140190649\/posts\/UAKPqCdpLE7\">brutal thresholds<\/a>?<\/p>\n<h2 id=\"3-return-file-extension-of-clicked-link\">3. Return file extension of clicked link<\/h2>\n<p><strong>Macro Type<\/strong>: <a href=\"https:\/\/www.simoahava.com\/analytics\/macro-guide-google-tag-manager\/#6-custom-javascript\">Custom JavaScript<\/a><br \/><strong>Other requirements<\/strong>: Macro for <a href=\"https:\/\/www.simoahava.com\/analytics\/macro-guide-google-tag-manager\/#2-auto-event-variable\">Auto-Event Variable<\/a> of type Element (named {{element}} in this example)<br \/><strong>Use for<\/strong>: Rules, event fields<br \/><strong>Example return value<\/strong>: pdf<\/p>\n<p><em>Instructions and description<\/em>:<\/p>\n<ol>\n<li>\n<p>Create Custom JavaScript Macro<\/p>\n<\/li>\n<li>\n<p>Add following code:<\/p>\n<\/li>\n<\/ol>\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\">var<\/span> ext = {{element}}.pathname.split(<span style=\"color:#a50\">\".\"<\/span>);\n  <span style=\"color:#00a\">return<\/span> ext.length &gt; <span style=\"color:#099\">1<\/span>?ext.pop():<span style=\"color:#a50\">'html'<\/span>;\n}\n<\/code><\/pre>\n<\/div>\n<p>This macro came from St\u00e9phane Hamel, in another inspiring, \u201ccrowd-sourced\u201d <a href=\"https:\/\/plus.google.com\/109635181158374226872\/posts\/AuVjXieWx7J\">Google+ discussion<\/a>. The idea is that when a Link Click Listener is activated, this macro will return the file extension of the clicked link, and if one doesn\u2019t exist, it returns just <strong>html<\/strong>. So if the link was to <code>http:\/\/www.mydomain.com\/brochure.pdf<\/code>, this macro will return <strong>pdf<\/strong>.<\/p>\n<p>You can use this in your tags either as a rule or as a value for a specific field. For example, here\u2019s an event tag which sends the extension of the clicked link as one of the parameters:<\/p>\n<div style=\"aspect-ratio: 522 \/ 340;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/03\/event-filetype.jpg\" title=\"Filetype in Event tag\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"340\" width=\"522\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/03\/event-filetype.jpg#ZgotmplZ\" alt=\"Filetype in Event tag\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>If the link were to <a href=\"http:\/\/www.mydomain.com\/brochure.pdf,\">http:\/\/www.mydomain.com\/brochure.pdf,<\/a> this tag would fire with:<\/p>\n<p>Event Category \u201cpdf link click\u201d<br \/>Event Action \u201cbrochure.pdf\u201d (more on this in the next chapter)<br \/>Event Label \u201c<em>url of page where brochure.pdf was downloaded from<\/em>\u201d<\/p>\n<h2 id=\"4-return-file-name-of-clicked-link\">4. Return file name of clicked link<\/h2>\n<p><strong>Macro Type<\/strong>: <a href=\"https:\/\/www.simoahava.com\/analytics\/macro-guide-google-tag-manager\/#6-custom-javascript\">Custom JavaScript<\/a><br \/>\n<strong>Other requirements<\/strong>: Macro for <a href=\"https:\/\/www.simoahava.com\/analytics\/macro-guide-google-tag-manager\/#2-auto-event-variable\">Auto-Event Variable<\/a> of type Element (named {{element}} in this example)<br \/><strong>Use for<\/strong>: Event fields<br \/><strong>Example return value<\/strong>: brochure.pdf<\/p>\n<p><em>Instructions and description<\/em>:<\/p>\n<ol>\n<li>\n<p>Create Custom JavaScript Macro<\/p>\n<\/li>\n<li>\n<p>Add following code:<\/p>\n<\/li>\n<\/ol>\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\">var<\/span> filepath = {{element}}.pathname.split(<span style=\"color:#a50\">\"\/\"<\/span>);\n  <span style=\"color:#00a\">var<\/span> filename = filepath.pop();\n  <span style=\"color:#00a\">return<\/span> filename.indexOf(<span style=\"color:#a50\">\".\"<\/span>) &gt; -<span style=\"color:#099\">1<\/span>?filename:<span style=\"color:#a50\">'n\/a'<\/span>;\n}\n<\/code><\/pre>\n<\/div>\n<p>This macro is very similar to the previous one, except now it returns the whole file name. If the downloaded link is not an asset with a file extension, the script returns the ambiguous \u201cn\/a\u201d string, which can be used in blocking rules, for example.<\/p>\n<p>Use this macro to make your link click event tags more dynamic. In the best case scenario, you\u2019ll just need one event tag for all your link clicks, because variable value macros like this are what make your tags the dynamic vessels they should be.<\/p>\n<h2 id=\"5-check-if-clicked-link-is-internal\">5. Check if clicked link is internal<\/h2>\n<p><strong>Macro Type<\/strong>: <a href=\"https:\/\/www.simoahava.com\/analytics\/macro-guide-google-tag-manager\/#6-custom-javascript\">Custom JavaScript<\/a><br \/><strong>Other requirements<\/strong>: Macro for <a href=\"https:\/\/www.simoahava.com\/analytics\/macro-guide-google-tag-manager\/#2-auto-event-variable\">Auto-Event Variable<\/a> of type Element URL (named {{element url}} in this example), macro for <a href=\"https:\/\/www.simoahava.com\/analytics\/macro-guide-google-tag-manager\/#14-url\">URL<\/a> of type URL Hostname (named {{url hostname}} in this example)<br \/><strong>Use for<\/strong>: Firing rules<br \/><strong>Example return value<\/strong>: true<\/p>\n<p><em>Instructions and description<\/em>:<\/p>\n<ol>\n<li>\n<p>Create Custom JavaScript macro<\/p>\n<\/li>\n<li>\n<p>Add following code within:<\/p>\n<\/li>\n<\/ol>\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\">return<\/span> {{element url}}.indexOf({{url hostname}}) &gt; -<span style=\"color:#099\">1<\/span>;\n}\n<\/code><\/pre>\n<\/div>\n<p>This returns <strong>true<\/strong> if the clicked element URL contains the hostname of the current page, and <strong>false<\/strong>, if the clicked element URL contains some other hostname.<\/p>\n<p>You can use this in your firing rules, e.g. fire an \u201cOutbound link\u201d event only when the clicked link is not internal:<\/p>\n<div style=\"aspect-ratio: 561 \/ 317;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/03\/outbound-link.jpg\" title=\"Outbound link rule\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"317\" width=\"561\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/03\/outbound-link.jpg#ZgotmplZ\" alt=\"Outbound link rule\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<h2 id=\"6-get-clientid-using-_ga-cookie\">6. Get clientID using _ga cookie<\/h2>\n<p><strong>Macro Type<\/strong>: <a href=\"https:\/\/www.simoahava.com\/analytics\/macro-guide-google-tag-manager\/#1-1st-party-cookie\">1st Party Cookie<\/a>, <a href=\"https:\/\/www.simoahava.com\/analytics\/macro-guide-google-tag-manager\/#6-custom-javascript\">Custom JavaScript<\/a><br \/><strong>Other requirements<\/strong>: Universal Analytics property<br \/><strong>Use for<\/strong>: Offline measurement, stitching client data<br \/><strong>Example return value<\/strong>: 475226310.1380715146<\/p>\n<p><em>Instructions and description<\/em>:<\/p>\n<ol>\n<li>\n<p>Create 1st Party Cookie macro<\/p>\n<\/li>\n<li>\n<p>Set cookie name to <strong>_ga<\/strong><\/p>\n<\/li>\n<li>\n<p>Create Custom JavaScript macro<\/p>\n<\/li>\n<li>\n<p>Add following code within:<\/p>\n<\/li>\n<\/ol>\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\">try<\/span> {\n    <span style=\"color:#00a\">var<\/span> cookie = {{ga cookie}}.split(<span style=\"color:#a50\">\".\"<\/span>);\n    <span style=\"color:#00a\">return<\/span> cookie[<span style=\"color:#099\">2<\/span>] + <span style=\"color:#a50\">\".\"<\/span> + cookie[<span style=\"color:#099\">3<\/span>];\n  } <span style=\"color:#00a\">catch<\/span>(e) {\n    console.log(<span style=\"color:#a50\">\"No Universal Analytics cookie found\"<\/span>);\n  }\n}\n<\/code><\/pre>\n<\/div>\n<p>First you create a new 1st Party Cookie macro, which returns the value of the _ga cookie. It might be something like <strong>GA1.2.475226310.1380715146<\/strong>. Next, the Custom JavaScript macro parses this string, and returns the third (client ID) and fourth (timestamp) elements of the cookie value (<strong>475226310.1380715146<\/strong>), which combine to make the complete clientID of the user.<\/p>\n<p>You can then add this as a session-level custom dimension, for example, to identify which clientID committed to what actions on your site during their session. You could then use the <a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/protocol\/v1\/\">Measurement Protocol<\/a> to work all sorts of offline-online data stitching magic with your database tools!<\/p>\n<p>Note that I use a very rudimentary try-catch block for error handling. Feel free to handle errors in any way you want (as long as you do handle them!).<\/p>\n<h2 id=\"7-get-clientid-using-gagetall\">7. Get clientID using ga.getAll()<\/h2>\n<p><strong>Macro Type<\/strong>: <a href=\"https:\/\/www.simoahava.com\/analytics\/macro-guide-google-tag-manager\/#6-custom-javascript\">Custom JavaScript<\/a><br \/><strong>Other requirements<\/strong>: Universal Analytics property<br \/><strong>Use for<\/strong>: Offline measurement, stitching client data<br \/><strong>Example return value<\/strong>: 475226310.1380715146<\/p>\n<p><em>Instructions and description<\/em>:<\/p>\n<ol>\n<li>\n<p>Create Custom JavaScript macro<\/p>\n<\/li>\n<li>\n<p>Add following code within:<\/p>\n<\/li>\n<\/ol>\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\">try<\/span> {\n    <span style=\"color:#00a\">var<\/span> tracker = ga.getAll()[<span style=\"color:#099\">0<\/span>];\n    <span style=\"color:#00a\">return<\/span> tracker.get(<span style=\"color:#a50\">'clientId'<\/span>);\n  } <span style=\"color:#00a\">catch<\/span>(e) {\n    console.log(<span style=\"color:#a50\">\"Error fetching clientId\"<\/span>);\n  }\n}\n<\/code><\/pre>\n<\/div>\n<p>This is Google\u2019s recommendation for fetching the client ID (rather than parsing the cookie). You basically access the <strong>ga<\/strong> object using the function <em>getAll()<\/em>. This would normally retrieve all named trackers, but you\u2019re only interested in the first one (which is the one GTM sets). Finally, it uses the <em>get<\/em> method of the tracker object to retrieve the value of the property <em>clientId<\/em>, which is, coincidentally, the clientId.<\/p>\n<p><strong>NOTE!<\/strong> This macro will not work if it fires before a page view is sent. The tracker is created during the page view call, so you\u2019ll either have to use a callback function (see the next section) or have the tag which fetches the client ID fire upon <strong>{{event}} equals gtm.load<\/strong>.<\/p>\n<h2 id=\"8-hitcallback-with-a-universal-analytics-tag\">8. hitCallback with a Universal Analytics tag<\/h2>\n<p><strong>Macro Type<\/strong>: <a href=\"https:\/\/www.simoahava.com\/analytics\/macro-guide-google-tag-manager\/#6-custom-javascript\">Custom JavaScript<\/a><br \/><strong>Use for<\/strong>: Imposing a tag firing order<\/p>\n<p><em>Instructions and description<\/em>:<\/p>\n<ol>\n<li>\n<p>Create Custom JavaScript macro<\/p>\n<\/li>\n<li>\n<p>Add following code within:<\/p>\n<\/li>\n<\/ol>\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\">return<\/span> <span style=\"color:#00a\">function<\/span>(){dataLayer.push({<span style=\"color:#a50\">'event'<\/span>: <span style=\"color:#a50\">'pageViewFired'<\/span>});}\n}\n<\/code><\/pre>\n<\/div>\n<p>The Universal Analytics tag doesn\u2019t have a callback field that you can use (yet). So you\u2019ll have to resort to the \u201cFields to set\u201d option, and add the callback function manually.<\/p>\n<p>Anyway, the idea with hitCallback is to do something as soon as the tag has fired. In my example, I push an event called \u2018pageViewFired\u2019, which I can then use in some other tag to make sure it fires only after the page view has been sent. You\u2019d need to add the macro to your tag like this:<\/p>\n<div style=\"aspect-ratio: 657 \/ 254;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/03\/hitcallback.jpg\" title=\"hitCallback in your tag\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"254\" width=\"657\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/03\/hitcallback.jpg#ZgotmplZ\" alt=\"hitCallback in your tag\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>The field to set is called <strong>hitCallback<\/strong> and its value should be the macro you just created.<\/p>\n<p>If you look at the code, you\u2019ll see a funny thing. You\u2019re <em>returning<\/em> the function which does all the work. Why, you wonder? Simple. When the event tag is fired, it will go through all the fields that have been set for the tag, performing all the actions within. If you didn\u2019t have the function returning another function, the callback would fire <strong>twice<\/strong>: first when the event tag\u2019s firing begins, and again when the tag has completed (when the callback function is actually called).<\/p>\n<p>This might be a bit difficult to fathom, but it\u2019s just how GTM and JavaScript work. hitCallback is expecting a function, so the function in your callback tag has to <em>return<\/em> a function, because macros need to always return something.<\/p>\n<p>Messy. But it works!<\/p>\n<h2 id=\"9-return-url-path--query-string\">9. Return URL path + query string<\/h2>\n<p><strong>Macro Type<\/strong>: <a href=\"https:\/\/www.simoahava.com\/analytics\/macro-guide-google-tag-manager\/#6-custom-javascript\">Custom JavaScript<\/a><br \/><strong>Use for<\/strong>: Working with the query string<br \/><strong>Example return value<\/strong>: \/analytics\/?internal=true<\/p>\n<p><em>Instructions and description<\/em>:<\/p>\n<ol>\n<li>\n<p>Create Custom JavaScript macro<\/p>\n<\/li>\n<li>\n<p>Add following code within:<\/p>\n<\/li>\n<\/ol>\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\">return<\/span> location.pathname+location.search;\n}\n<\/code><\/pre>\n<\/div>\n<p>This is a very simple macro. There\u2019s no predefined macro for you to use if you want to return the url pathname with query parameters. This macro does just that.<\/p>\n<h2 id=\"10-property-id-lookup-with-hostname\">10. Property ID lookup with hostname<\/h2>\n<p><strong>Macro Type<\/strong>: <a href=\"https:\/\/www.simoahava.com\/analytics\/macro-guide-google-tag-manager\/#12-lookup-table\">Lookup Table<\/a><br \/><strong>Other requirements<\/strong>: Macro for <a href=\"https:\/\/www.simoahava.com\/analytics\/macro-guide-google-tag-manager\/#14-url\">URL<\/a> of type URL Hostname (named {{url hostname}} in this example)<br \/><strong>Use for<\/strong>: To have the same tracking tag for different property IDs on different domains<br \/><strong>Example return value<\/strong>: UA-12345-1<\/p>\n<p><em>Instructions and description<\/em>:<\/p>\n<ol>\n<li>\n<p>Create a Lookup Table macro<\/p>\n<\/li>\n<li>\n<p>Add some tracking code as the Default Value (optional)<\/p>\n<\/li>\n<li>\n<p>In the first column, choose {{url hostname}} as the macro that is evaluated<\/p>\n<\/li>\n<li>\n<p>In the first column, add all the different hostnames you want to assign a property ID to<\/p>\n<\/li>\n<li>\n<p>In the second column, add the respective property ID for each hostname<\/p>\n<\/li>\n<\/ol>\n<p>This is a very useful macro if you have multiple domains with different property IDs tracked by the same container. Whenever you have the same tags running on all the different domains, using a lookup like this means you don\u2019t have to create a separate tag for each ID.<\/p>\n<p>The macro should look like this:<\/p>\n<div style=\"aspect-ratio: 616 \/ 414;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/03\/lookup-hostname.jpg\" title=\"Lookup with hostname\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"414\" width=\"616\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/03\/lookup-hostname.jpg#ZgotmplZ\" alt=\"Lookup with hostname\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>This macro will return the correct property ID depending on which domain the user is browsing on.<\/p>\n<h2 id=\"11-track-debug-hits-to-different-property-id\">11. Track debug hits to different property ID<\/h2>\n<p><strong>Macro Type<\/strong>: <a href=\"https:\/\/www.simoahava.com\/analytics\/macro-guide-google-tag-manager\/#12-lookup-table\">Lookup Table<\/a>, <a href=\"https:\/\/www.simoahava.com\/analytics\/macro-guide-google-tag-manager\/#8-debug-mode\">Debug Mode<\/a><br \/><strong>Use for<\/strong>: When using GTM\u2019s debug mode, track your hits to a different property ID (e.g. test account)<br \/><strong>Example return value<\/strong>: UA-12345-1<\/p>\n<p><em>Instructions and description<\/em>:<\/p>\n<ol>\n<li>\n<p>Create a Debug Mode macro (named {{debug mode}} in this example)<\/p>\n<\/li>\n<li>\n<p>Create a Lookup Table macro<\/p>\n<\/li>\n<li>\n<p>Add some tracking code as the Default Value (optional)<\/p>\n<\/li>\n<li>\n<p>In the first column, choose {{debug mode}} as the macro that is evaluated<\/p>\n<\/li>\n<li>\n<p>In the first column, add rows for <strong>true<\/strong> and <strong>false<\/strong><\/p>\n<\/li>\n<li>\n<p>In the second column, add the respective property ID for when debug mode is <strong>true<\/strong> and when it is <strong>false<\/strong><\/p>\n<\/li>\n<\/ol>\n<p>This is very similar to the previous macro, but it uses the Debug Mode macro as well. Sometimes you\u2019ll notice yourself doing so much debug work that you\u2019ll want to track these hits on a different account altogether. This is a really simple way to do it.<\/p>\n<div style=\"aspect-ratio: 610 \/ 407;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/03\/debug-lookup.jpg\" title=\"Lookup table macro for debug mode\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"407\" width=\"610\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/03\/debug-lookup.jpg#ZgotmplZ\" alt=\"Lookup table macro for debug mode\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>The Debug Mode macro returns \u201ctrue\u201d if debug mode is on, and \u201cfalse\u201d if it\u2019s off. Use these values to assign a different property ID as the return value of the Lookup Table macro.<\/p>\n<h2 id=\"12-get-title-attribute-of-document\">12. Get title attribute of document<\/h2>\n<p><strong>Macro Type<\/strong>: <a href=\"https:\/\/www.simoahava.com\/analytics\/macro-guide-google-tag-manager\/#11-javascript-variable\">JavaScript Variable<\/a><br \/><strong>Use for<\/strong>: Retrieving and using the document title attribute<br \/><strong>Example return value<\/strong>: Macro Magic For Google Tag Manager &#8211; Simo Ahava\u2019s Blog<\/p>\n<p><em>Instructions and description<\/em>:<\/p>\n<ol>\n<li>\n<p>Create JavaScript Variable macro<\/p>\n<\/li>\n<li>\n<p>Set field Global Variable Name to <strong>document.title<\/strong><\/p>\n<\/li>\n<\/ol>\n<p>This macro retrieves the HTML title attribute of your document. A great use case for this is if you want to process tags on a 404 page differently. You\u2019d then create a rule like this:<\/p>\n<div style=\"aspect-ratio: 567 \/ 214;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/03\/404-page.jpg\" title=\"Rule for 404 pages\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"214\" width=\"567\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/03\/404-page.jpg#ZgotmplZ\" alt=\"Rule for 404 pages\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>Another use case could be for <a href=\"https:\/\/www.simoahava.com\/analytics\/google-tag-manager-content-grouping\/\">content grouping<\/a>. Use the title macro to group your content logically in your tags.<\/p>\n<h2 id=\"13-check-if-browser-has-cookies-enabled\">13. Check if browser has cookies enabled<\/h2>\n<p><strong>Macro Type<\/strong>: <a href=\"https:\/\/www.simoahava.com\/analytics\/macro-guide-google-tag-manager\/#11-javascript-variable\">JavaScript Variable<\/a><br \/><strong>Use for<\/strong>: Checking if user has cookies enabled, filter some bot traffic<br \/><strong>Example return value<\/strong>: true<\/p>\n<p><em>Instructions and description<\/em>:<\/p>\n<ol>\n<li>\n<p>Create JavaScript Variable macro<\/p>\n<\/li>\n<li>\n<p>Set field Global Variable Name to <strong>navigator.cookieEnabled<\/strong><\/p>\n<\/li>\n<\/ol>\n<p>The <strong>navigator.cookieEnabled<\/strong> property returns a boolean value (true\/false) determined by whether or not the browser allows websites to write cookies. You can use this in your rules to make sure tags only fire for browsers with cookies, or to filter non-cookie data to a different view.<\/p>\n<p>You could also use this to block tags from firing for search engine bots, since there\u2019s some consensus that a majority of them do not accept or use cookies (see <a href=\"http:\/\/www.davekz.com\/googlebot-and-cookies\/\">this test for Googlebot<\/a> from February 2013).<\/p>\n<h2 id=\"14-a-bunch-of-useful-auto-event-variable-extensions\">14. A bunch of useful Auto-Event Variable extensions<\/h2>\n<p><strong>Macro Type<\/strong>: <a href=\"https:\/\/www.simoahava.com\/analytics\/macro-guide-google-tag-manager\/#7-data-layer-variable\">Data Layer Variable<\/a><br \/>\n<strong>Use for<\/strong>: Making the most of <a href=\"https:\/\/www.simoahava.com\/analytics\/auto-event-tracking-google-tag-manager\/\">auto-event tracking<\/a><\/p>\n<p>Here\u2019s a list of extensions for your auto-event tracking. By creating Data Layer Variable macros, you can use them in your rules to make your event tracking and whatnot even more detailed. In the \u201cWhat it does\u201d sections, <em>the element<\/em> refers always to the element which was clicked \/ submitted and thus stored in dataLayer as <strong>gtm.element<\/strong>.<\/p>\n<p><strong>Data Layer Variable Name<\/strong>: gtm.element.nodeName<br \/><strong>Example return value<\/strong>: IMG<br \/><strong>What it does<\/strong>: Returns the tag name of the element (well, strictly node name but in most cases it\u2019s the same thing)<\/p>\n<p><strong>Data Layer Variable Name<\/strong>: gtm.element.value<br \/><strong>Example return value<\/strong>: Simo Ahava<br \/><strong>What it does<\/strong>: Returns the value of the element. This is useful if you\u2019re tracking input elements on your forms (with e.g. blur, focus, or change), and you want to send an event every time a form field has been filled.<\/p>\n<p><strong>Data Layer Variable Name<\/strong>: gtm.element.hash<br \/><strong>Example return value<\/strong>: #chapter1<br \/><strong>What it does<\/strong>: Returns the hash (if any) of the element href. So if the link was to \/this-page\/?internal=true#chapter1, gtm.element.hash would return #chapter1<\/p>\n<p><strong>Data Layer Variable Name<\/strong>: gtm.element.pathname<br \/><strong>Example return value<\/strong>: \/this-page\/<br \/><strong>What it does<\/strong>: Returns the path in the element href. If the link was to \/this-page\/?internal=true#chapter1, gtm.element.pathname would return \/this-page\/<\/p>\n<p><strong>Data Layer Variable Name<\/strong>: gtm.element.search<br \/><strong>Example return value<\/strong>: ?internal=true<br \/><strong>What it does<\/strong>: Returns the full query string of the element. If the link was to \/this-page\/?internal=true#chapter1, gtm.element.search would return ?internal=true<\/p>\n<p><strong>Data Layer Variable Name<\/strong>: gtm.element.parentElement<br \/><strong>Example return value<\/strong>: (object), extend further with some property of the parent element<br \/><strong>What it does<\/strong>: Returns the direct parent of the element, and you should extend this macro further to access its properties (e.g. gtm.element.parentElement.id returns the value stored in the ID attribute of the parent tag)<\/p>\n<p><strong>Data Layer Variable Name<\/strong>: gtm.element.firstChild<br \/><strong>Example return value<\/strong>: (object), extend further with some property of the child element<br \/><strong>What it does<\/strong>: Returns the first direct descendant of the element, and you should extend this macro further to access its properties (e.g. gtm.element.firstChild.className returns value stored in the CLASS attribute of the child tag)<\/p>\n<p><strong>Data Layer Variable Name<\/strong>: gtm.element.nextSibling<br \/><strong>Example return value<\/strong>: (object), extend further with some property of the sibling element<br \/><strong>What it does<\/strong>: Returns the next element in the DOM tree which is on the same hierarchical level as the element, and you should extend this macro further to access its properties (e.g. gtm.element.nextSibling.nodeName returns the tag name of the sibling tag)<\/p>\n<p>So here\u2019s a bunch of extensions for you to play with. There\u2019s still a huge amount of stuff out there you can try, especially with forms, so I suggest that you set up a click listener on your site and play around with the DOM.<\/p>\n<h2 id=\"15-detect-mobile-browser\">15. Detect mobile browser<\/h2>\n<p><strong>Macro Type<\/strong>: <a href=\"https:\/\/www.simoahava.com\/analytics\/macro-guide-google-tag-manager\/#6-custom-javascript\">Custom JavaScript<\/a><br \/><strong>Use for<\/strong>: Mobile-specific tracking<br \/><strong>Example return value<\/strong>: true<\/p>\n<p><em>Instructions and description<\/em>:<\/p>\n<ol>\n<li>\n<p>Create Custom JavaScript macro<\/p>\n<\/li>\n<li>\n<p>Copy-paste the code from <a href=\"https:\/\/www.simoahava.com\/images\/2014\/03\/mobile-detection-gtm.txt\">the attached TXT file<\/a><\/p>\n<\/li>\n<\/ol>\n<p>I had to add the code in an attachment, because it\u2019s such a long and ugly piece of RegEx that it makes my eyes water. Sorry about that.<\/p>\n<div style=\"aspect-ratio: 633 \/ 179;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/03\/mobile-browser.jpg\" title=\"Mobile Browser detection script\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"179\" width=\"633\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/03\/mobile-browser.jpg#ZgotmplZ\" alt=\"Mobile Browser detection script\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>It\u2019s dirty, I know. This script checks the browser user agent string and returns true if it matches a mobile device user agent. If it doesn\u2019t, the script returns false.<\/p>\n<p>This script is provided by (with slight modifications to fit GTM infrastructure) <a href=\"http:\/\/detectmobilebrowsers.com\/\">detectmobilebrowsers.com<\/a>.<\/p>\n<h2 id=\"conclusions\">Conclusions<\/h2>\n<p>There\u2019s so much you can do with macros. I truly believe that the goal of all GTM implementations should be to achieve the elusive compromise between complexity and eye candy. It\u2019s important to keep a clean house when tag management is concerned, especially since Google Tag Manager doesn\u2019t, as of yet, provide us with too much to work with in terms of taxonomies, hierarchies and categories.<\/p>\n<p>I wasn\u2019t kidding when I wrote in the beginning how I really want to see a solution gallery for GTM. I appreciate the fact that it will make posts like this obsolete (unless you enjoy my banter or the educational twist I hopefully succeed in conveying). Nevertheless, being able to share, store, and search for the amazing tags and macros that our vibrant community has produced would be the best thing since sliced bread.<\/p>\n<\/p><\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>(Last updated June 2014) This post is an attempt at a whole new level of interaction. These words will transcend the barriers of time and space, bridging together the physical world and its digital counterpart. You see, in an undisclosed number of hours after the publishing of this blog post, I will be talking at [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":171285,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12033],"tags":[1531,33546,840,14495,1791],"dealstore":[],"offerexpiration":[],"class_list":["post-171283","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-analytics","tag-google","tag-macro","tag-magic","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 Magic 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:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Macro Magic For Google Tag Manager - Som2ny Network\" \/>\n<meta property=\"og:description\" content=\"(Last updated June 2014) This post is an attempt at a whole new level of interaction. These words will transcend the barriers of time and space, bridging together the physical world and its digital counterpart. You see, in an undisclosed number of hours after the publishing of this blog post, I will be talking at [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/\" \/>\n<meta property=\"og:site_name\" content=\"Som2ny Network\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-04T19:00:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/accountants4yourbusiness.co.uk\/wp-content\/uploads\/2025\/04\/measurecamp.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"634\" \/>\n\t<meta property=\"og:image:height\" content=\"528\" \/>\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=\"17 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\/\/accountants4yourbusiness.co.uk\/#\/schema\/person\/a87f5103e8aaad88546f5aecb86f6d2e\"},\"headline\":\"Macro Magic For Google Tag Manager\",\"datePublished\":\"2025-04-04T19:00:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/\"},\"wordCount\":3329,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/accountants4yourbusiness.co.uk\/#organization\"},\"image\":{\"@id\":\"https:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/accountants4yourbusiness.co.uk\/wp-content\/uploads\/2025\/04\/measurecamp.jpg\",\"keywords\":[\"Google\",\"Macro\",\"Magic\",\"Manager\",\"TAG\"],\"articleSection\":[\"Analytics\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/\",\"url\":\"https:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/\",\"name\":\"Macro Magic For Google Tag Manager - Som2ny Network\",\"isPartOf\":{\"@id\":\"https:\/\/accountants4yourbusiness.co.uk\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/accountants4yourbusiness.co.uk\/wp-content\/uploads\/2025\/04\/measurecamp.jpg\",\"datePublished\":\"2025-04-04T19:00:18+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/#primaryimage\",\"url\":\"https:\/\/accountants4yourbusiness.co.uk\/wp-content\/uploads\/2025\/04\/measurecamp.jpg\",\"contentUrl\":\"https:\/\/accountants4yourbusiness.co.uk\/wp-content\/uploads\/2025\/04\/measurecamp.jpg\",\"width\":634,\"height\":528},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/accountants4yourbusiness.co.uk\/activity\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Macro Magic For Google Tag Manager\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/accountants4yourbusiness.co.uk\/#website\",\"url\":\"https:\/\/accountants4yourbusiness.co.uk\/\",\"name\":\"Som2ny Network\",\"description\":\"Daily Deals\",\"publisher\":{\"@id\":\"https:\/\/accountants4yourbusiness.co.uk\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/accountants4yourbusiness.co.uk\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/accountants4yourbusiness.co.uk\/#organization\",\"name\":\"Som2ny Network\",\"url\":\"https:\/\/accountants4yourbusiness.co.uk\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/accountants4yourbusiness.co.uk\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/accountants4yourbusiness.co.uk\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png\",\"contentUrl\":\"https:\/\/accountants4yourbusiness.co.uk\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png\",\"width\":300,\"height\":86,\"caption\":\"Som2ny Network\"},\"image\":{\"@id\":\"https:\/\/accountants4yourbusiness.co.uk\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/accountants4yourbusiness.co.uk\/#\/schema\/person\/a87f5103e8aaad88546f5aecb86f6d2e\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/accountants4yourbusiness.co.uk\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Faccountants4yourbusiness.co.uk%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%2Faccountants4yourbusiness.co.uk%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png\",\"caption\":\"admin\"},\"sameAs\":[\"https:\/\/som2nynetwork.com\"],\"url\":\"https:\/\/accountants4yourbusiness.co.uk\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Macro Magic 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:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/","og_locale":"en_US","og_type":"article","og_title":"Macro Magic For Google Tag Manager - Som2ny Network","og_description":"(Last updated June 2014) This post is an attempt at a whole new level of interaction. These words will transcend the barriers of time and space, bridging together the physical world and its digital counterpart. You see, in an undisclosed number of hours after the publishing of this blog post, I will be talking at [&hellip;]","og_url":"https:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/","og_site_name":"Som2ny Network","article_published_time":"2025-04-04T19:00:18+00:00","og_image":[{"width":634,"height":528,"url":"https:\/\/accountants4yourbusiness.co.uk\/wp-content\/uploads\/2025\/04\/measurecamp.jpg","type":"image\/jpeg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"17 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/#article","isPartOf":{"@id":"https:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/"},"author":{"name":"admin","@id":"https:\/\/accountants4yourbusiness.co.uk\/#\/schema\/person\/a87f5103e8aaad88546f5aecb86f6d2e"},"headline":"Macro Magic For Google Tag Manager","datePublished":"2025-04-04T19:00:18+00:00","mainEntityOfPage":{"@id":"https:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/"},"wordCount":3329,"commentCount":0,"publisher":{"@id":"https:\/\/accountants4yourbusiness.co.uk\/#organization"},"image":{"@id":"https:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/#primaryimage"},"thumbnailUrl":"https:\/\/accountants4yourbusiness.co.uk\/wp-content\/uploads\/2025\/04\/measurecamp.jpg","keywords":["Google","Macro","Magic","Manager","TAG"],"articleSection":["Analytics"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/","url":"https:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/","name":"Macro Magic For Google Tag Manager - Som2ny Network","isPartOf":{"@id":"https:\/\/accountants4yourbusiness.co.uk\/#website"},"primaryImageOfPage":{"@id":"https:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/#primaryimage"},"image":{"@id":"https:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/#primaryimage"},"thumbnailUrl":"https:\/\/accountants4yourbusiness.co.uk\/wp-content\/uploads\/2025\/04\/measurecamp.jpg","datePublished":"2025-04-04T19:00:18+00:00","breadcrumb":{"@id":"https:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/#primaryimage","url":"https:\/\/accountants4yourbusiness.co.uk\/wp-content\/uploads\/2025\/04\/measurecamp.jpg","contentUrl":"https:\/\/accountants4yourbusiness.co.uk\/wp-content\/uploads\/2025\/04\/measurecamp.jpg","width":634,"height":528},{"@type":"BreadcrumbList","@id":"https:\/\/accountants4yourbusiness.co.uk\/analytics\/macro-magic-for-google-tag-manager\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/accountants4yourbusiness.co.uk\/activity\/"},{"@type":"ListItem","position":2,"name":"Macro Magic For Google Tag Manager"}]},{"@type":"WebSite","@id":"https:\/\/accountants4yourbusiness.co.uk\/#website","url":"https:\/\/accountants4yourbusiness.co.uk\/","name":"Som2ny Network","description":"Daily Deals","publisher":{"@id":"https:\/\/accountants4yourbusiness.co.uk\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/accountants4yourbusiness.co.uk\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/accountants4yourbusiness.co.uk\/#organization","name":"Som2ny Network","url":"https:\/\/accountants4yourbusiness.co.uk\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/accountants4yourbusiness.co.uk\/#\/schema\/logo\/image\/","url":"https:\/\/accountants4yourbusiness.co.uk\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png","contentUrl":"https:\/\/accountants4yourbusiness.co.uk\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png","width":300,"height":86,"caption":"Som2ny Network"},"image":{"@id":"https:\/\/accountants4yourbusiness.co.uk\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/accountants4yourbusiness.co.uk\/#\/schema\/person\/a87f5103e8aaad88546f5aecb86f6d2e","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/accountants4yourbusiness.co.uk\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Faccountants4yourbusiness.co.uk%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%2Faccountants4yourbusiness.co.uk%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png","caption":"admin"},"sameAs":["https:\/\/som2nynetwork.com"],"url":"https:\/\/accountants4yourbusiness.co.uk\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/accountants4yourbusiness.co.uk\/wp-json\/wp\/v2\/posts\/171283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/accountants4yourbusiness.co.uk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/accountants4yourbusiness.co.uk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/accountants4yourbusiness.co.uk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/accountants4yourbusiness.co.uk\/wp-json\/wp\/v2\/comments?post=171283"}],"version-history":[{"count":0,"href":"https:\/\/accountants4yourbusiness.co.uk\/wp-json\/wp\/v2\/posts\/171283\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/accountants4yourbusiness.co.uk\/wp-json\/wp\/v2\/media\/171285"}],"wp:attachment":[{"href":"https:\/\/accountants4yourbusiness.co.uk\/wp-json\/wp\/v2\/media?parent=171283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/accountants4yourbusiness.co.uk\/wp-json\/wp\/v2\/categories?post=171283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/accountants4yourbusiness.co.uk\/wp-json\/wp\/v2\/tags?post=171283"},{"taxonomy":"dealstore","embeddable":true,"href":"https:\/\/accountants4yourbusiness.co.uk\/wp-json\/wp\/v2\/dealstore?post=171283"},{"taxonomy":"offerexpiration","embeddable":true,"href":"https:\/\/accountants4yourbusiness.co.uk\/wp-json\/wp\/v2\/offerexpiration?post=171283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}