{"id":75538,"date":"2025-02-08T09:56:27","date_gmt":"2025-02-08T09:56:27","guid":{"rendered":"https:\/\/peraltafinancing.com\/analytics\/gtag-get-api-custom-tag-template\/"},"modified":"2025-02-08T09:56:27","modified_gmt":"2025-02-08T09:56:27","slug":"gtag-get-api-custom-tag-template","status":"publish","type":"post","link":"https:\/\/fivemor.com\/?p=75538","title":{"rendered":"GTAG GET API &#8211; Custom Tag Template"},"content":{"rendered":"<p> <br \/>\n<\/p>\n<div>\n<div style=\"aspect-ratio: 1782 \/ 1024;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2020\/12\/gtag-get-api.jpg\" title=\"GTAG GET API\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"1024\" width=\"1782\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2020\/12\/gtag-get-api.jpg#ZgotmplZ\" alt=\"GTAG GET API\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>The <strong>GTAG GET API<\/strong> <a href=\"https:\/\/www.simoahava.com\/analytics\/custom-templates-guide-for-google-tag-manager\/\">custom tag template<\/a> is a tag template for <a href=\"https:\/\/tagmanager.google.com\/\">Google Tag Manager\u2019s<\/a> <a href=\"https:\/\/tagmanager.google.com\/gallery\/\">community template gallery<\/a>.<\/p>\n<h3 id=\"description\">Description<\/h3>\n<p>This tag writes the values for the selected <strong>default<\/strong> fields (Client ID, Session ID, GCLID) as well as any custom fields set with the Google Analytics 4 template into <code>dataLayer<\/code>.<\/p>\n<p>It utilizes the asynchronous <code>.get()<\/code> API of Google Site Tag.<\/p>\n<p>See the <a href=\"https:\/\/developers.google.com\/gtagjs\/reference\/api#get\">official documentation<\/a> for a summary of the API.<\/p>\n<h3 id=\"instructions\">Instructions<\/h3>\n<p>Create a tag with the GTAG GET API template, and choose all the fields you want it to write into <code>dataLayer<\/code>.<\/p>\n<p>Then, <strong>and this is important<\/strong>, you have to set the tag in a <a href=\"https:\/\/www.simoahava.com\/analytics\/understanding-tag-sequencing-in-google-tag-manager\/\">tag sequence<\/a> to fire <strong>after<\/strong> (as a <strong>Cleanup Tag<\/strong>) the <strong>Google Analytics 4: Configuration<\/strong> tag (or an Event tag if you don\u2019t use a Configuration tag).<\/p>\n<blockquote>\n<p>This tag <em>must<\/em> fire after a Google Analytics 4 tag has completely fired, or else the <code>gtag()<\/code> GET API will not do anything.<\/p>\n<\/blockquote>\n<div style=\"aspect-ratio: 1142 \/ 456;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2020\/12\/tag-sequencing.jpg\" title=\"Tag Sequencing\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"456\" width=\"1142\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2020\/12\/tag-sequencing.jpg#ZgotmplZ\" alt=\"Tag Sequencing\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>When the tag fires, it launches a number of calls to <code>gtag()<\/code> GET API &#8211; one for each field it has to resolve. Once all the fields have been resolved, a <code>dataLayer.push()<\/code> is done with the following contents:<\/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-json\" data-lang=\"json\">{\n  <span style=\"color:#1e90ff;font-weight:bold\">\"event\"<\/span>: <span style=\"color:#a50\">\"gtagApiGet\"<\/span>,\n  <span style=\"color:#1e90ff;font-weight:bold\">\"gtagApiResult\"<\/span>: {\n    <span style=\"color:#1e90ff;font-weight:bold\">\"client_id\"<\/span>: <span style=\"color:#a50\">\"123123123.123123123\"<\/span>,\n    <span style=\"color:#1e90ff;font-weight:bold\">\"session_id\"<\/span>: <span style=\"color:#a50\">\"1608578585\"<\/span>,\n    <span style=\"color:#f00;background-color:#faa\">...<\/span>\n  }\n}<\/code><\/pre>\n<\/div>\n<p>After this, you can create a Custom Event trigger for the <code>gtagApiGet<\/code> event and Data Layer variables for the individual field values in the <code>gtagApiResult<\/code> object.<\/p>\n<div style=\"aspect-ratio: 914 \/ 426;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2020\/12\/event-trigger-gtagapiget.jpg\" title=\"Custom event trigger\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"426\" width=\"914\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2020\/12\/event-trigger-gtagapiget.jpg#ZgotmplZ\" alt=\"Custom event trigger\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<div style=\"aspect-ratio: 900 \/ 632;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2020\/12\/data-layer-variable-client-id.jpg\" title=\"Data Layer Variable client_id\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"632\" width=\"900\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2020\/12\/data-layer-variable-client-id.jpg#ZgotmplZ\" alt=\"Data Layer Variable client_id\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<h3 id=\"release-notes\">Release notes<\/h3>\n<table>\n<thead>\n<tr>\n<th>Date<\/th>\n<th>Changeset<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>21 December 2020<\/td>\n<td>Remove console logging.<\/td>\n<\/tr>\n<tr>\n<td>21 December 2020<\/td>\n<td>Initial release.<\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>The GTAG GET API custom tag template is a tag template for Google Tag Manager\u2019s community template gallery. Description This tag writes the values for the selected default fields (Client ID, Session ID, GCLID) as well as any custom fields set with the Google Analytics 4 template into dataLayer. It utilizes the asynchronous .get() API [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":75539,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12033],"tags":[13966,834,38539,1791,4196],"dealstore":[],"offerexpiration":[],"class_list":["post-75538","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-analytics","tag-api","tag-custom","tag-gtag","tag-tag","tag-template"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>GTAG GET API - Custom Tag Template - 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=75538\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"GTAG GET API - Custom Tag Template - Som2ny Network\" \/>\n<meta property=\"og:description\" content=\"The GTAG GET API custom tag template is a tag template for Google Tag Manager\u2019s community template gallery. Description This tag writes the values for the selected default fields (Client ID, Session ID, GCLID) as well as any custom fields set with the Google Analytics 4 template into dataLayer. It utilizes the asynchronous .get() API [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fivemor.com\/?p=75538\" \/>\n<meta property=\"og:site_name\" content=\"Som2ny Network\" \/>\n<meta property=\"article:published_time\" content=\"2025-02-08T09:56:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/gtag-get-api.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1782\" \/>\n\t<meta property=\"og:image:height\" content=\"1024\" \/>\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=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/fivemor.com\/?p=75538#article\",\"isPartOf\":{\"@id\":\"https:\/\/fivemor.com\/?p=75538\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371\"},\"headline\":\"GTAG GET API &#8211; Custom Tag Template\",\"datePublished\":\"2025-02-08T09:56:27+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/fivemor.com\/?p=75538\"},\"wordCount\":228,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/fivemor.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/?p=75538#primaryimage\"},\"thumbnailUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/gtag-get-api.jpg\",\"keywords\":[\"API\",\"Custom\",\"GTAG\",\"TAG\",\"Template\"],\"articleSection\":[\"Analytics\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/fivemor.com\/?p=75538#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/fivemor.com\/?p=75538\",\"url\":\"https:\/\/fivemor.com\/?p=75538\",\"name\":\"GTAG GET API - Custom Tag Template - Som2ny Network\",\"isPartOf\":{\"@id\":\"https:\/\/fivemor.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/fivemor.com\/?p=75538#primaryimage\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/?p=75538#primaryimage\"},\"thumbnailUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/gtag-get-api.jpg\",\"datePublished\":\"2025-02-08T09:56:27+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/fivemor.com\/?p=75538#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/fivemor.com\/?p=75538\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/?p=75538#primaryimage\",\"url\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/gtag-get-api.jpg\",\"contentUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/gtag-get-api.jpg\",\"width\":1782,\"height\":1024},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/fivemor.com\/?p=75538#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/fivemor.com\/?bp_activities=1\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"GTAG GET API &#8211; Custom Tag Template\"}]},{\"@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":"GTAG GET API - Custom Tag Template - 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=75538","og_locale":"en_US","og_type":"article","og_title":"GTAG GET API - Custom Tag Template - Som2ny Network","og_description":"The GTAG GET API custom tag template is a tag template for Google Tag Manager\u2019s community template gallery. Description This tag writes the values for the selected default fields (Client ID, Session ID, GCLID) as well as any custom fields set with the Google Analytics 4 template into dataLayer. It utilizes the asynchronous .get() API [&hellip;]","og_url":"https:\/\/fivemor.com\/?p=75538","og_site_name":"Som2ny Network","article_published_time":"2025-02-08T09:56:27+00:00","og_image":[{"width":1782,"height":1024,"url":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/gtag-get-api.jpg","type":"image\/jpeg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fivemor.com\/?p=75538#article","isPartOf":{"@id":"https:\/\/fivemor.com\/?p=75538"},"author":{"name":"admin","@id":"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371"},"headline":"GTAG GET API &#8211; Custom Tag Template","datePublished":"2025-02-08T09:56:27+00:00","mainEntityOfPage":{"@id":"https:\/\/fivemor.com\/?p=75538"},"wordCount":228,"commentCount":0,"publisher":{"@id":"https:\/\/fivemor.com\/#organization"},"image":{"@id":"https:\/\/fivemor.com\/?p=75538#primaryimage"},"thumbnailUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/gtag-get-api.jpg","keywords":["API","Custom","GTAG","TAG","Template"],"articleSection":["Analytics"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fivemor.com\/?p=75538#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fivemor.com\/?p=75538","url":"https:\/\/fivemor.com\/?p=75538","name":"GTAG GET API - Custom Tag Template - Som2ny Network","isPartOf":{"@id":"https:\/\/fivemor.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fivemor.com\/?p=75538#primaryimage"},"image":{"@id":"https:\/\/fivemor.com\/?p=75538#primaryimage"},"thumbnailUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/gtag-get-api.jpg","datePublished":"2025-02-08T09:56:27+00:00","breadcrumb":{"@id":"https:\/\/fivemor.com\/?p=75538#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fivemor.com\/?p=75538"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/?p=75538#primaryimage","url":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/gtag-get-api.jpg","contentUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/gtag-get-api.jpg","width":1782,"height":1024},{"@type":"BreadcrumbList","@id":"https:\/\/fivemor.com\/?p=75538#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fivemor.com\/?bp_activities=1"},{"@type":"ListItem","position":2,"name":"GTAG GET API &#8211; Custom Tag Template"}]},{"@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\/75538","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=75538"}],"version-history":[{"count":0,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts\/75538\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/media\/75539"}],"wp:attachment":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=75538"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=75538"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=75538"},{"taxonomy":"dealstore","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fdealstore&post=75538"},{"taxonomy":"offerexpiration","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fofferexpiration&post=75538"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}