{"id":171654,"date":"2025-04-05T03:33:30","date_gmt":"2025-04-05T03:33:30","guid":{"rendered":"https:\/\/peraltafinancing.com\/analytics\/the-container-snippet-gtm-secrets-revealed\/"},"modified":"2025-04-05T03:33:30","modified_gmt":"2025-04-05T03:33:30","slug":"the-container-snippet-gtm-secrets-revealed","status":"publish","type":"post","link":"https:\/\/fivemor.com\/?p=171654","title":{"rendered":"The Container Snippet: GTM Secrets Revealed"},"content":{"rendered":"<p> <br \/>\n<\/p>\n<div>\n<div class=\"main-content-wrap\">\n<p>First of all, I\u2019m sorry for the wacky title. Sometimes I just want to amuse myself. Nevertheless, this post <em>is<\/em> about the <a href=\"https:\/\/www.google.com\/tagmanager\">Google Tag Manager<\/a> container snippet. There\u2019s nothing secretive about it, but I\u2019m betting many people have no clue what the snippet really does. That\u2019s the revelatory part.<\/p>\n<p>If you\u2019ve never wondered what the snippet does, then shame on you! Remember, you own your page template. It\u2019s yours. Any code that you write there is your responsibility. You wouldn\u2019t let a complete stranger come to your house and paint your walls without permission, would you? So why copy-paste some code that you have no idea what it does? Because Google told you to?<\/p>\n<div style=\"aspect-ratio: 698 \/ 73;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/03\/google-instructions.jpg\" title=\"Google's Instructions for Container Snippet\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"73\" width=\"698\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/03\/google-instructions.jpg#ZgotmplZ\" alt=\"Google's Instructions for Container Snippet\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>Well, you can trust Google (stop laughing!). There\u2019s nothing nefarious about the container snippet. Regardless, I wrote this post to tell you what it does, so that you can sleep better at night. Or you might learn something new about JavaScript (never a bad thing).<\/p>\n<p>Note that this text should be understandable to JavaScript novices as well, but if you feel daunted at any time, you can just skip ahead to the last chapter. Within is a short recap of what the container snippet does.<\/p>\n<p>So sit back (but lean forward), and enjoy another one of life\u2019s great mysteries unravelled.<\/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=\"the-container-snippet\">The container snippet<\/h2>\n<p>You should know what the container snippet is by now. It\u2019s the piece of code that Google Tag Manager <a href=\"https:\/\/developers.google.com\/tag-manager\/quickstart\">requires that you add to your page template<\/a>, right after the opening <code\/> tag. You know, this (from my site):<\/p>\n<div style=\"aspect-ratio: 615 \/ 78;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/03\/container-snippet.jpg\" title=\"Container snippet\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"78\" width=\"615\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/03\/container-snippet.jpg#ZgotmplZ\" alt=\"Container snippet\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>(I left out the <code><noscript\/><\/code> part, because this post is just about the JavaScript snippet.)<\/p>\n<p>Let\u2019s face it, the snippet code looks gibberish. This is because the JavaScript (that\u2019s right, it\u2019s JavaScript) is <em>minified<\/em>. Minification is the process of truncating the script to the smallest possible size without losing any data. This means removing whitespace (spaces and line breaks), and reducing variable and function names to single- or double-character length. Minification is done because every single character adds to the page size, and thus to the page load time. The benefit with something as small as the container snippet is negligible, but it is still observed as a best practice.<\/p>\n<p>Because I want this post to add some value, allow me to perform a little makeover to the snippet.<\/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-html\" data-lang=\"html\">script <span style=\"color:#1e90ff\">type<\/span>=<span style=\"color:#a50\">\"text\/javascript\"<\/span>&gt;\n(<span style=\"color:#00a\">function<\/span> (w, d, s, l, i) {\n    w[l] = w[l] || [];\n    w[l].push({\n        <span style=\"color:#a50\">'gtm.start'<\/span>: <span style=\"color:#00a\">new<\/span> <span style=\"color:#0aa\">Date<\/span>().getTime(),\n        event: <span style=\"color:#a50\">'gtm.js'<\/span>\n    });\n    <span style=\"color:#00a\">var<\/span> f = d.getElementsByTagName(s)[<span style=\"color:#099\">0<\/span>],\n        j = d.createElement(s),\n        dl = l != <span style=\"color:#a50\">'dataLayer'<\/span> ? <span style=\"color:#a50\">'&amp;l='<\/span> + l : <span style=\"color:#a50\">''<\/span>;\n    j.async = <span style=\"color:#00a\">true<\/span>;\n    j.src =\n        <span style=\"color:#a50\">'\/\/www.googletagmanager.com\/gtm.js?id='<\/span> + i + dl;\n    f.parentNode.insertBefore(j, f);\n})(<span style=\"color:#0aa\">window<\/span>, <span style=\"color:#0aa\">document<\/span>, <span style=\"color:#a50\">'script'<\/span>, <span style=\"color:#a50\">'dataLayer'<\/span>, <span style=\"color:#a50\">'GTM-P8XR'<\/span>);\n<span style=\"color:#1e90ff;font-weight:bold\">script<\/span>&gt;<\/code><\/pre>\n<\/div>\n<p>That\u2019s better! It\u2019s the same code but with some basic formatting. Much easier to read and understand, right?<\/p>\n<h2 id=\"positioning-the-container-snippet\">Positioning the container snippet<\/h2>\n<p>You might have wondered why Google so forcefully recommends that you place the container snippet just after the opening <code\/> tag. There are two good reasons to do so.<\/p>\n<p>First, if you add the <code><noscript\/><\/code> tag as well (as you should), this should always be in the body of the document. The tag (which is shown for browsers without JavaScript enabled) contains an iFrame which loads the GTM library. If you add the <code><noscript\/><\/code> tag into the head of your document, it can perform pretty wildly with some browsers. You <em>could<\/em> experiment with leaving the <code><noscript\/><\/code> in the body, and placing the JavaScript in the <\/p>\n<\/div>\n<p>, but I haven\u2019t tested it and certainly don\u2019t recommend it.<\/p>\n<p>The second reason is simple: to maximize data collection, the snippet should be the first thing loaded when the body of the page is rendered. Because the library is loaded asynchronously, there\u2019s no reason to delay it at all. So have it load as the first thing when the body is rendered, so that you don\u2019t risk losing any data due to sluggish DOM elements delaying the page load.<\/p>\n<h3 id=\"lines-2-and-15\">Lines 2 and 15<\/h3>\n<p>We can skip lines 1 and 16, since they\u2019re just the HTML SCRIPT tag, wrapping the JavaScript block.<\/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> (w, d, s, l, i) {\n...\n})(<span style=\"color:#0aa\">window<\/span>, <span style=\"color:#0aa\">document<\/span>, <span style=\"color:#a50\">'script'<\/span>, <span style=\"color:#a50\">'dataLayer'<\/span>, <span style=\"color:#a50\">'GTM-P8XR'<\/span>);\n<\/code><\/pre>\n<\/div>\n<p>To understand the first line, we have to look at the last line as well. This is an example of a <em>self-invoking \/ self-executing anonymous function<\/em>, or <em>immediately-invoked function expression<\/em>. There\u2019s <a href=\"http:\/\/benalman.com\/news\/2010\/11\/immediately-invoked-function-expression\/\">some debate on the semantics<\/a> of which term you should choose, but for this purpose it\u2019s just that: semantics.<\/p>\n<p>Basically, line 2 of the snippet declares an anonymous function (it has no name) with <em>five parameters<\/em>. These parameters are served via the function call at the end of the function block, which has, as it should, <em>five arguments<\/em>.<\/p>\n<p>The whole idea behind an immediately-invoked function expression is to <strong>call the function as soon as it has been declared<\/strong>. That\u2019s what lines 2 and 15 of the snippet are about. Line 2 declares a function which is called in line 15, as soon as the function code has been parsed by your browser.<\/p>\n<p>The arguments that are sent with the function call, and turned into parameters in the declaration (the parameters are in parentheses), are as follows:<\/p>\n<ul>\n<li>\n<p><strong>window (w)<\/strong> &#8211; the <em>window<\/em> object represents the open window in the user\u2019s browser and everything in it (the document object model, or DOM, for example)<\/p>\n<\/li>\n<li>\n<p><strong>document (d)<\/strong> &#8211; the <em>document<\/em> object is the top node in the DOM tree; it contains the entire HTML document<\/p>\n<\/li>\n<li>\n<p><strong>\u2018script\u2019 (s)<\/strong> &#8211; this string is used to load the <strong>gtm.js<\/strong> library (more on this later)<\/p>\n<\/li>\n<li>\n<p><strong>\u2018dataLayer\u2019 (l)<\/strong> &#8211; this string is used to give a name to the dataLayer object; you can rename the object used by GTM by changing this value<\/p>\n<\/li>\n<li>\n<p><strong>\u2018GTM-P8XR\u2019 (i)<\/strong> &#8211; this is your container ID, which you\u2019ll get from Google Tag Manager<\/p>\n<\/li>\n<\/ul>\n<h3 id=\"line-3\">Line 3<\/h3>\n<p>If you remember what the parameters and arguments were, this line translates to:<\/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:#0aa\">window<\/span>[<span style=\"color:#a50\">'dataLayer'<\/span>] = <span style=\"color:#0aa\">window<\/span>[<span style=\"color:#a50\">'dataLayer'<\/span>] || [];\n<\/code><\/pre>\n<\/div>\n<p>Here, the function looks for an object named <strong>dataLayer<\/strong> (or something else if you renamed it in the function arguments) in the window object, which contains all the objects on the page. If it finds one, it leaves it be. If it doesn\u2019t find one, it declares it as an empty <em>array<\/em>.<\/p>\n<p>This is important, because sometimes you\u2019ll see this <em>explicit declaration<\/em> of the dataLayer object in the page template before the container snippet:<\/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-html\" data-lang=\"html\">script <span style=\"color:#1e90ff\">type<\/span>=<span style=\"color:#a50\">\"text\/javascript\"<\/span>&gt;\n    dataLayer = [];\n<span style=\"color:#1e90ff;font-weight:bold\">script<\/span>&gt;<\/code><\/pre>\n<\/div>\n<p>Explicit declaration of dataLayer is useful if you need some dataLayer variables to be available at the earliest possible moment in your GTM tags. For example, if your page view tag requires some dataLayer variable to exist (for a custom dimension, perhaps), it\u2019s better to declare it in the page template <em>before<\/em> the container snippet:<\/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-html\" data-lang=\"html\">script&gt;\n    dataLayer = [{<span style=\"color:#a50\">'author'<\/span>: <span style=\"color:#a50\">'Simo Ahava'<\/span>}];\n<span style=\"color:#1e90ff;font-weight:bold\">script<\/span>&gt;<\/code><\/pre>\n<\/div>\n<p>This explicit declaration is what the code on line 3 of the container snippet is looking for. If the explicit declaration is found, it is left as it is. If it hasn\u2019t been declared, the <strong>container snippet creates the dataLayer object for you<\/strong>.<\/p>\n<p>This brings me to an important point.<\/p>\n<p>If you do not declare the dataLayer object explicitly, do <strong>NOT<\/strong> declare it in your GTM tags or after the container snippet. The container creates the dataLayer array for you, and if you try to declare it later on, you\u2019ll end up <strong>erasing the original dataLayer, created and used by GTM<\/strong>. After dataLayer has been created, your only interaction with it should be by using the <a href=\"https:\/\/developers.google.com\/tag-manager\/devguide#events\"><strong>push()<\/strong> method<\/a> of the array (<em>dataLayer.push({\u2018property\u2019: \u2018value\u2019});<\/em>).<\/p>\n<h3 id=\"lines-4-through-7\">Lines 4 through 7<\/h3>\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\">w[l].push({\n    <span style=\"color:#a50\">'gtm.start'<\/span>: <span style=\"color:#00a\">new<\/span> <span style=\"color:#0aa\">Date<\/span>().getTime(),\n    event: <span style=\"color:#a50\">'gtm.js'<\/span>\n});\n<\/code><\/pre>\n<\/div>\n<p>This is a very important part of the container snippet functionality.<\/p>\n<p>When the code reaches this point, a <strong>dataLayer.push()<\/strong> call is done. Within the curly brackets is an <em>object literal<\/em>. Object literals are JavaScript objects, which contain any number of key-value (or property-value or variable-value) pairs, often in JSON (JavaScript Object Notation). These objects are wrapped in curly brackets, and pushed to the end of the dataLayer array.<\/p>\n<p>If most of the previous paragraph is gibberish to you, I don\u2019t blame you.<\/p>\n<p>To put it simply, with a <strong>dataLayer.push()<\/strong>, you\u2019re <em>pushing<\/em> an object with properties to the end of the dataLayer queue. These properties can then be accessed in GTM.<\/p>\n<p>This first push, on lines 4 through 7 of the container snippet, contains an object with the following properties:<\/p>\n<p>So <a href=\"https:\/\/www.simoahava.com\/analytics\/google-tag-manager-playing-rules\/\">if you\u2019ve ever wondered<\/a> when tags with <strong>{{event}} equals gtm.js<\/strong> or <strong>{{url}} matches regex .<\/strong>* get fired, it\u2019s at this point.<\/p>\n<p>The <strong>gtm.start<\/strong> property receives the current time (in milliseconds since Jan 1, 1970) as its value. Brian Kuhn of Google explained that this is used for calculating gtm.js load time and the cache hit rate of the request, so don\u2019t worry about it.<\/p>\n<h3 id=\"lines-8-through-10\">Lines 8 through 10<\/h3>\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\">var<\/span> f = d.getElementsByTagName(s)[<span style=\"color:#099\">0<\/span>],\n    j = d.createElement(s),\n    dl = l != <span style=\"color:#a50\">'dataLayer'<\/span> ? <span style=\"color:#a50\">'&amp;ampamp;l='<\/span> + l : <span style=\"color:#a50\">''<\/span>;\n<\/code><\/pre>\n<\/div>\n<p>Let\u2019s open this up again, using the parameters and arguments we\u2019re already familiar with:<\/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\">var<\/span> f = <span style=\"color:#0aa\">document<\/span>.getElementsByTagName(<span style=\"color:#a50\">'script'<\/span>)[<span style=\"color:#099\">0<\/span>],\n    j = <span style=\"color:#0aa\">document<\/span>.createElement(<span style=\"color:#a50\">'script'<\/span>),\n    dl = <span style=\"color:#a50\">'dataLayer'<\/span> != <span style=\"color:#a50\">'dataLayer'<\/span> ? <span style=\"color:#a50\">'&amp;ampamp;l='<\/span> + <span style=\"color:#a50\">'newDataLayer'<\/span> : <span style=\"color:#a50\">''<\/span>;\n<\/code><\/pre>\n<\/div>\n<p>The first line stores the first SCRIPT element on the page in variable <strong>f<\/strong>.<\/p>\n<p>The second line creates a new SCRIPT element, and stores it in variable <strong>j<\/strong>.<\/p>\n<p>The third line does one of two possible things. If you haven\u2019t touched the default name of the dataLayer object (i.e. \u2018dataLayer\u2019), just an empty string is stored in variable <strong>dl<\/strong>. However, if you\u2019ve chosen to rename the dataLayer (e.g. \u2018newDataLayer\u2019), the string \u2018&amp;ampamp;l=newDataLayer\u2019 is stored in variable <strong>dl<\/strong>. &amp;ampamp; is the same as the ampersand (&amp;), but it has been encoded because some platforms can\u2019t process non-encoded ASCII characters.<\/p>\n<p>These variables will be used in the next lines.<\/p>\n<h3 id=\"lines-11-through-13\">Lines 11 through 13<\/h3>\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\">j.async = <span style=\"color:#00a\">true<\/span>;\nj.src =\n    <span style=\"color:#a50\">'\/\/www.googletagmanager.com\/gtm.js?id='<\/span> + i + dl;\n<\/code><\/pre>\n<\/div>\n<p>And let\u2019s beautify this one as well:<\/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\">j.async = <span style=\"color:#00a\">true<\/span>;\nj.src = <span style=\"color:#a50\">'\/\/www.googletagmanager.com\/gtm.js?id=GTM-P8XR'<\/span>;\n<\/code><\/pre>\n<\/div>\n<p>Remember, in the last chapter you just created a new SCRIPT element and stored it in variable <strong>j<\/strong>? In these lines you add some attributes to it. The container ID is retrieved from function parameter <strong>i<\/strong>, and it was originally passed as an argument in the self-invoking function call (you remember this!). Go look if you don\u2019t believe me.<\/p>\n<p>Note that the last line might look different if you chose to rename your dataLayer. In that case, it would actually be the equivalent of 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\">j.src = <span style=\"color:#a50\">'\/\/www.googletagmanager.com\/gtm.js?id=GTM-P8XR&amp;l=newDataLayer'<\/span>;\n<\/code><\/pre>\n<\/div>\n<p>This means that if you renamed your dataLayer object, this new name is passed as the value of query parameter <strong>l<\/strong> with the request to load the gtm.js library from GTM servers.<\/p>\n<p>Anyway, the whole point of these lines is to make the SCRIPT element you stored into variable <strong>j<\/strong> look something 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-html\" data-lang=\"html\">script <span style=\"color:#1e90ff\">type<\/span>=<span style=\"color:#a50\">\"text\/javascript\"<\/span> <span style=\"color:#1e90ff\">async<\/span> <span style=\"color:#1e90ff\">src<\/span>=<span style=\"color:#a50\">\"\/\/www.googletagmanager.com\/gtm.js?id=GTM-P8XR\"<\/span>&gt;<span style=\"color:#1e90ff;font-weight:bold\">script<\/span>&gt;<\/code><\/pre>\n<\/div>\n<p>So basically you\u2019ve just created a SCRIPT tag which loads the external <strong>gtm.js<\/strong> library with your container ID (and your renamed dataLayer, if you did so) as query parameters.<\/p>\n<h3 id=\"line-14\">Line 14<\/h3>\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\">f.parentNode.insertBefore(j, f);\n<\/code><\/pre>\n<\/div>\n<p>Remember a few chapters back when variable <strong>f<\/strong> was defined as the first SCRIPT tag of the document? This line does the following:<\/p>\n<ul>\n<li>\n<p>Look for the first SCRIPT tag on the page<\/p>\n<\/li>\n<li>\n<p>Just before that, insert the new SCRIPT tag which loads <strong>gtm.js<\/strong> (from the previous chapter)<\/p>\n<\/li>\n<\/ul>\n<p>So the code on line 14 of the container snippet makes sure that the GTM loader is the first SCRIPT tag on the page.<\/p>\n<p>And there you go! Read ahead for a short summary of what just happened.<\/p>\n<h2 id=\"conclusions\">Conclusions<\/h2>\n<p>Here\u2019s a short recap of what the container snippet does:<\/p>\n<ol>\n<li>\n<p>Declares an anonymous function with five parameters (the name of the dataLayer object and your container ID, among others)<\/p>\n<\/li>\n<li>\n<p>Creates the dataLayer array, if you didn\u2019t do so explicitly before the container snippet<\/p>\n<\/li>\n<li>\n<p>Pushes the first event, <strong>gtm.js<\/strong>, into dataLayer, along with the time the push was done<\/p>\n<\/li>\n<li>\n<p>Creates a new SCRIPT tag, which loads the external <strong>gtm.js<\/strong> JavaScript library with your container ID (and custom dataLayer object name) as parameters<\/p>\n<\/li>\n<li>\n<p>Adds this new SCRIPT to the page template, so that it\u2019s the first SCRIPT tag on the page<\/p>\n<\/li>\n<li>\n<p>After the function is declared, the function is automatically executed<\/p>\n<\/li>\n<\/ol>\n<p>In the end, it\u2019s a pretty simple piece of code. All it actually does is create (or verify) the dataLayer object, push the first event (named \u2018gtm.js\u2019) into dataLayer, and load the external gtm.js library which processes your container.<\/p>\n<p>And that\u2019s the story of the container snippet.<\/p>\n<p>Next up: reverse engineering the entire gtm.js library (JUST KIDDING!).<\/p>\n<\/p><\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>First of all, I\u2019m sorry for the wacky title. Sometimes I just want to amuse myself. Nevertheless, this post is about the Google Tag Manager container snippet. There\u2019s nothing secretive about it, but I\u2019m betting many people have no clue what the snippet really does. That\u2019s the revelatory part. If you\u2019ve never wondered what the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":171655,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12033],"tags":[1498,32680,19444,6075,43155],"dealstore":[],"offerexpiration":[],"class_list":["post-171654","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-analytics","tag-container","tag-gtm","tag-revealed","tag-secrets","tag-snippet"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>The Container Snippet: GTM Secrets Revealed - 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=171654\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The Container Snippet: GTM Secrets Revealed - Som2ny Network\" \/>\n<meta property=\"og:description\" content=\"First of all, I\u2019m sorry for the wacky title. Sometimes I just want to amuse myself. Nevertheless, this post is about the Google Tag Manager container snippet. There\u2019s nothing secretive about it, but I\u2019m betting many people have no clue what the snippet really does. That\u2019s the revelatory part. If you\u2019ve never wondered what the [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fivemor.com\/?p=171654\" \/>\n<meta property=\"og:site_name\" content=\"Som2ny Network\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-05T03:33:30+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/04\/google-instructions.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"698\" \/>\n\t<meta property=\"og:image:height\" content=\"73\" \/>\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=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/fivemor.com\/?p=171654#article\",\"isPartOf\":{\"@id\":\"https:\/\/fivemor.com\/?p=171654\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371\"},\"headline\":\"The Container Snippet: GTM Secrets Revealed\",\"datePublished\":\"2025-04-05T03:33:30+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/fivemor.com\/?p=171654\"},\"wordCount\":1953,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/fivemor.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/?p=171654#primaryimage\"},\"thumbnailUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/04\/google-instructions.jpg\",\"keywords\":[\"Container\",\"GTM\",\"Revealed\",\"Secrets\",\"Snippet\"],\"articleSection\":[\"Analytics\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/fivemor.com\/?p=171654#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/fivemor.com\/?p=171654\",\"url\":\"https:\/\/fivemor.com\/?p=171654\",\"name\":\"The Container Snippet: GTM Secrets Revealed - Som2ny Network\",\"isPartOf\":{\"@id\":\"https:\/\/fivemor.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/fivemor.com\/?p=171654#primaryimage\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/?p=171654#primaryimage\"},\"thumbnailUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/04\/google-instructions.jpg\",\"datePublished\":\"2025-04-05T03:33:30+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/fivemor.com\/?p=171654#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/fivemor.com\/?p=171654\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/?p=171654#primaryimage\",\"url\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/04\/google-instructions.jpg\",\"contentUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/04\/google-instructions.jpg\",\"width\":698,\"height\":73},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/fivemor.com\/?p=171654#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/fivemor.com\/?bp_activities=1\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"The Container Snippet: GTM Secrets Revealed\"}]},{\"@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":"The Container Snippet: GTM Secrets Revealed - 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=171654","og_locale":"en_US","og_type":"article","og_title":"The Container Snippet: GTM Secrets Revealed - Som2ny Network","og_description":"First of all, I\u2019m sorry for the wacky title. Sometimes I just want to amuse myself. Nevertheless, this post is about the Google Tag Manager container snippet. There\u2019s nothing secretive about it, but I\u2019m betting many people have no clue what the snippet really does. That\u2019s the revelatory part. If you\u2019ve never wondered what the [&hellip;]","og_url":"https:\/\/fivemor.com\/?p=171654","og_site_name":"Som2ny Network","article_published_time":"2025-04-05T03:33:30+00:00","og_image":[{"width":698,"height":73,"url":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/04\/google-instructions.jpg","type":"image\/jpeg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fivemor.com\/?p=171654#article","isPartOf":{"@id":"https:\/\/fivemor.com\/?p=171654"},"author":{"name":"admin","@id":"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371"},"headline":"The Container Snippet: GTM Secrets Revealed","datePublished":"2025-04-05T03:33:30+00:00","mainEntityOfPage":{"@id":"https:\/\/fivemor.com\/?p=171654"},"wordCount":1953,"commentCount":0,"publisher":{"@id":"https:\/\/fivemor.com\/#organization"},"image":{"@id":"https:\/\/fivemor.com\/?p=171654#primaryimage"},"thumbnailUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/04\/google-instructions.jpg","keywords":["Container","GTM","Revealed","Secrets","Snippet"],"articleSection":["Analytics"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fivemor.com\/?p=171654#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fivemor.com\/?p=171654","url":"https:\/\/fivemor.com\/?p=171654","name":"The Container Snippet: GTM Secrets Revealed - Som2ny Network","isPartOf":{"@id":"https:\/\/fivemor.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fivemor.com\/?p=171654#primaryimage"},"image":{"@id":"https:\/\/fivemor.com\/?p=171654#primaryimage"},"thumbnailUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/04\/google-instructions.jpg","datePublished":"2025-04-05T03:33:30+00:00","breadcrumb":{"@id":"https:\/\/fivemor.com\/?p=171654#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fivemor.com\/?p=171654"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/?p=171654#primaryimage","url":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/04\/google-instructions.jpg","contentUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/04\/google-instructions.jpg","width":698,"height":73},{"@type":"BreadcrumbList","@id":"https:\/\/fivemor.com\/?p=171654#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fivemor.com\/?bp_activities=1"},{"@type":"ListItem","position":2,"name":"The Container Snippet: GTM Secrets Revealed"}]},{"@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\/171654","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=171654"}],"version-history":[{"count":0,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts\/171654\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/media\/171655"}],"wp:attachment":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=171654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=171654"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=171654"},{"taxonomy":"dealstore","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fdealstore&post=171654"},{"taxonomy":"offerexpiration","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fofferexpiration&post=171654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}