{"id":159110,"date":"2025-03-27T05:34:23","date_gmt":"2025-03-27T05:34:23","guid":{"rendered":"https:\/\/peraltafinancing.com\/analytics\/gtmtips-hitcallback-and-eventcallback-simo-ahavas-blog\/"},"modified":"2025-03-27T05:34:23","modified_gmt":"2025-03-27T05:34:23","slug":"gtmtips-hitcallback-and-eventcallback-simo-ahavas-blog","status":"publish","type":"post","link":"https:\/\/fivemor.com\/?p=159110","title":{"rendered":"#GTMtips: hitCallback And eventCallback | Simo Ahava&#8217;s blog"},"content":{"rendered":"<p> <br \/>\n<\/p>\n<div>\n<p>This time we\u2019ll take a look at two different, JavaScript-y features of Google Analytics and Google Tag Manager. <strong>Callback<\/strong> as a concept should be familiar to anyone who\u2019s ever used a programming language. It\u2019s basically a piece of code that is passed as an argument to some function, so that when this second function has completed, the callback is executed.<\/p>\n<p>For web analytics, callbacks are hugely important, since they allow you to impose a firing order for your asynchronous tags. Asynchronous tags, as you might know, abhor order and precision, so sometimes it\u2019s necessary to use a callback to have at least an inkling of predictability in your tag jungle.<\/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=\"tip-6-hitcallback-and-eventcallback\">Tip 6: hitCallback and eventCallback<\/h2>\n<div style=\"aspect-ratio: 1518 \/ 848;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/09\/hitcallback-and-eventcallback.jpg\" title=\"hitCallback and eventCallback in Google Tag Manager\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"848\" width=\"1518\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/09\/hitcallback-and-eventcallback.jpg#ZgotmplZ\" alt=\"hitCallback and eventCallback in Google Tag Manager\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>Here\u2019s the difference:<\/p>\n<p><strong>hitCallback<\/strong> &#8211; hitCallback is a <a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/analyticsjs\/advanced#hitCallback\">feature<\/a> of the <em>analytics.js<\/em> collection library. It lets you provide a callback function for each tag separately. If you want to, for example, fire some tag directly after your pageview has fired, you might want to use hitCallback to push an event into <code>dataLayer<\/code>, and then use <em>that<\/em> event to fire your second tag. Or you might do something really wacky, such as use hitCallback <a href=\"https:\/\/www.simoahava.com\/analytics\/fun-google-tag-manager-part-2\/\">to fire a single tag multiple times<\/a>.<\/p>\n<p>The key thing here is to make sure that the <a href=\"https:\/\/www.simoahava.com\/analytics\/macro-magic-google-tag-manager\/\">Custom JavaScript Macro which holds the callback function<\/a> <em>returns<\/em> a function which does all the work. This is important, since otherwise the function expression in your callback macro would fire TWICE: first when the tag is written and executed, and again when the callback is fired.<\/p>\n<p><strong>eventCallback<\/strong> &#8211; eventCallback is pure GTM. If you push a <code>dataLayer<\/code> event into the message queue, you can also push the <code>eventCallback<\/code> key as well. The value of the key would be the callback function. As soon as <strong>all<\/strong> tags which fire on the event that you pushed have executed, your callback function will fire.<\/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\">dataLayer.push({\n    <span style=\"color:#a50\">'key1'<\/span> : <span style=\"color:#a50\">'value1'<\/span>,\n    <span style=\"color:#a50\">'key2'<\/span> : <span style=\"color:#a50\">'value2'<\/span>,\n    <span style=\"color:#a50\">'event'<\/span> : <span style=\"color:#a50\">'fireTags'<\/span>,\n    <span style=\"color:#a50\">'eventCallback'<\/span> : <span style=\"color:#00a\">function<\/span>() {\n        alert(<span style=\"color:#a50\">'ALL tags which fire on {{event}} equals fireTags have now fired'<\/span>);\n    }\n});\n<\/code><\/pre>\n<\/div>\n<p>So in the code example above, as soon as all tags that have the firing rule <strong>{{event}} equals fireTags<\/strong> have executed, the function in the callback will fire.<\/p>\n<\/p><\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>This time we\u2019ll take a look at two different, JavaScript-y features of Google Analytics and Google Tag Manager. Callback as a concept should be familiar to anyone who\u2019s ever used a programming language. It\u2019s basically a piece of code that is passed as an argument to some function, so that when this second function has [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":159111,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12033],"tags":[27402,3767,49272,14492,65452,27401],"dealstore":[],"offerexpiration":[],"class_list":["post-159110","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-analytics","tag-ahavas","tag-blog","tag-eventcallback","tag-gtmtips","tag-hitcallback","tag-simo"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>#GTMtips: hitCallback And eventCallback | Simo Ahava&#039;s blog - 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=159110\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"#GTMtips: hitCallback And eventCallback | Simo Ahava&#039;s blog - Som2ny Network\" \/>\n<meta property=\"og:description\" content=\"This time we\u2019ll take a look at two different, JavaScript-y features of Google Analytics and Google Tag Manager. Callback as a concept should be familiar to anyone who\u2019s ever used a programming language. It\u2019s basically a piece of code that is passed as an argument to some function, so that when this second function has [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fivemor.com\/?p=159110\" \/>\n<meta property=\"og:site_name\" content=\"Som2ny Network\" \/>\n<meta property=\"article:published_time\" content=\"2025-03-27T05:34:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/hitcallback-and-eventcallback.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1518\" \/>\n\t<meta property=\"og:image:height\" content=\"848\" \/>\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=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/fivemor.com\/?p=159110#article\",\"isPartOf\":{\"@id\":\"https:\/\/fivemor.com\/?p=159110\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371\"},\"headline\":\"#GTMtips: hitCallback And eventCallback | Simo Ahava&#8217;s blog\",\"datePublished\":\"2025-03-27T05:34:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/fivemor.com\/?p=159110\"},\"wordCount\":369,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/fivemor.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/?p=159110#primaryimage\"},\"thumbnailUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/hitcallback-and-eventcallback.jpg\",\"keywords\":[\"Ahavas\",\"Blog\",\"eventCallback\",\"GTMTips\",\"hitCallback\",\"Simo\"],\"articleSection\":[\"Analytics\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/fivemor.com\/?p=159110#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/fivemor.com\/?p=159110\",\"url\":\"https:\/\/fivemor.com\/?p=159110\",\"name\":\"#GTMtips: hitCallback And eventCallback | Simo Ahava's blog - Som2ny Network\",\"isPartOf\":{\"@id\":\"https:\/\/fivemor.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/fivemor.com\/?p=159110#primaryimage\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/?p=159110#primaryimage\"},\"thumbnailUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/hitcallback-and-eventcallback.jpg\",\"datePublished\":\"2025-03-27T05:34:23+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/fivemor.com\/?p=159110#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/fivemor.com\/?p=159110\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/?p=159110#primaryimage\",\"url\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/hitcallback-and-eventcallback.jpg\",\"contentUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/hitcallback-and-eventcallback.jpg\",\"width\":1518,\"height\":848},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/fivemor.com\/?p=159110#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/fivemor.com\/?bp_activities=1\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"#GTMtips: hitCallback And eventCallback | Simo Ahava&#8217;s blog\"}]},{\"@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":"#GTMtips: hitCallback And eventCallback | Simo Ahava's blog - 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=159110","og_locale":"en_US","og_type":"article","og_title":"#GTMtips: hitCallback And eventCallback | Simo Ahava's blog - Som2ny Network","og_description":"This time we\u2019ll take a look at two different, JavaScript-y features of Google Analytics and Google Tag Manager. Callback as a concept should be familiar to anyone who\u2019s ever used a programming language. It\u2019s basically a piece of code that is passed as an argument to some function, so that when this second function has [&hellip;]","og_url":"https:\/\/fivemor.com\/?p=159110","og_site_name":"Som2ny Network","article_published_time":"2025-03-27T05:34:23+00:00","og_image":[{"width":1518,"height":848,"url":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/hitcallback-and-eventcallback.jpg","type":"image\/jpeg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fivemor.com\/?p=159110#article","isPartOf":{"@id":"https:\/\/fivemor.com\/?p=159110"},"author":{"name":"admin","@id":"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371"},"headline":"#GTMtips: hitCallback And eventCallback | Simo Ahava&#8217;s blog","datePublished":"2025-03-27T05:34:23+00:00","mainEntityOfPage":{"@id":"https:\/\/fivemor.com\/?p=159110"},"wordCount":369,"commentCount":0,"publisher":{"@id":"https:\/\/fivemor.com\/#organization"},"image":{"@id":"https:\/\/fivemor.com\/?p=159110#primaryimage"},"thumbnailUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/hitcallback-and-eventcallback.jpg","keywords":["Ahavas","Blog","eventCallback","GTMTips","hitCallback","Simo"],"articleSection":["Analytics"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fivemor.com\/?p=159110#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fivemor.com\/?p=159110","url":"https:\/\/fivemor.com\/?p=159110","name":"#GTMtips: hitCallback And eventCallback | Simo Ahava's blog - Som2ny Network","isPartOf":{"@id":"https:\/\/fivemor.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fivemor.com\/?p=159110#primaryimage"},"image":{"@id":"https:\/\/fivemor.com\/?p=159110#primaryimage"},"thumbnailUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/hitcallback-and-eventcallback.jpg","datePublished":"2025-03-27T05:34:23+00:00","breadcrumb":{"@id":"https:\/\/fivemor.com\/?p=159110#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fivemor.com\/?p=159110"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/?p=159110#primaryimage","url":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/hitcallback-and-eventcallback.jpg","contentUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/hitcallback-and-eventcallback.jpg","width":1518,"height":848},{"@type":"BreadcrumbList","@id":"https:\/\/fivemor.com\/?p=159110#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fivemor.com\/?bp_activities=1"},{"@type":"ListItem","position":2,"name":"#GTMtips: hitCallback And eventCallback | Simo Ahava&#8217;s blog"}]},{"@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\/159110","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=159110"}],"version-history":[{"count":0,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts\/159110\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/media\/159111"}],"wp:attachment":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=159110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=159110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=159110"},{"taxonomy":"dealstore","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fdealstore&post=159110"},{"taxonomy":"offerexpiration","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fofferexpiration&post=159110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}