{"id":121476,"date":"2025-03-09T05:17:31","date_gmt":"2025-03-09T05:17:31","guid":{"rendered":"https:\/\/peraltafinancing.com\/analytics\/gtmtips-use-customtask-to-access-tracker-values-in-google-tag-manager\/"},"modified":"2025-03-09T05:17:31","modified_gmt":"2025-03-09T05:17:31","slug":"gtmtips-use-customtask-to-access-tracker-values-in-google-tag-manager","status":"publish","type":"post","link":"https:\/\/fivemor.com\/?p=121476","title":{"rendered":"#GTMTips: Use customTask To Access Tracker Values In Google Tag Manager"},"content":{"rendered":"<p> <br \/>\n<\/p>\n<div>\n<p>One of the things I\u2019ve recommended from the get-go is to <a href=\"https:\/\/www.simoahava.com\/analytics\/improve-data-collection-with-four-custom-dimensions\/\">always send the Client ID<\/a> to <a href=\"https:\/\/analytics.google.com\">Google Analytics<\/a> with your users\u2019 hits. This is very useful for adding a level of granularity to your tracking. At first, I recommended using an Event tag to do this. Then I modified my approach a little so that you could send it with your initial <a href=\"https:\/\/www.simoahava.com\/analytics\/access-the-tracker-object-in-your-page-view-tag\/\">Page View<\/a> (thus not inflating your hit counts).<\/p>\n<p>However, Universal Analytics recently released a new <a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/analyticsjs\/tasks\">task API<\/a>, <code>customTask<\/code>, which lets you access the model object mid-tag, thus letting you modify the payload that is dispatched to Google Analytics. In this article, I\u2019ll show you how this works by using the classic example of sending the Client ID to Google Analytics.<\/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-59-access-the-model-object-mid-tag-in-google-tag-manager\">Tip 59: Access the model object mid-tag in Google Tag Manager<\/h2>\n<p>The setup is really simple. You need a <strong>Custom Dimension<\/strong> setup in Universal Analytics, and then you simply need to add a new <strong>Field to set<\/strong> in your Page View tag (or whatever you want to use to send the data to GA). Remember to read <a href=\"https:\/\/www.simoahava.com\/analytics\/improve-data-collection-with-four-custom-dimensions\/\">my article<\/a> on sending this type of metadata to Google Analytics, if you\u2019re unsure why you would want to do this in the first place.<\/p>\n<p>The tag setup would look like this:<\/p>\n<div style=\"aspect-ratio: 1766 \/ 792;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2017\/06\/customtask-fields-to-set.jpg\" title=\"customTask in Fields to set\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"792\" width=\"1766\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2017\/06\/customtask-fields-to-set.jpg#ZgotmplZ\" alt=\"customTask in Fields to set\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>Field name should be set to <strong>customTask<\/strong>, and as its value you need to use a <strong>Custom JavaScript Variable<\/strong>. The variable looks like this:<\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-javascript\" data-lang=\"javascript\"><span style=\"color:#00a\">function<\/span>() {\n  <span style=\"color:#aaa;font-style:italic\">\/\/ Modify customDimensionIndex to match the index number you want to send the data to\n<\/span><span style=\"color:#aaa;font-style:italic\"\/>  <span style=\"color:#00a\">var<\/span> customDimensionIndex = <span style=\"color:#099\">5<\/span>;\n  <span style=\"color:#00a\">return<\/span> <span style=\"color:#00a\">function<\/span>(model) {\n    model.set(<span style=\"color:#a50\">'dimension'<\/span> + customDimensionIndex, model.get(<span style=\"color:#a50\">'clientId'<\/span>));\n  }\n}\n<\/code><\/pre>\n<\/div>\n<p>What happens is that once Google Tag Manager starts executing the tag code, it first encounters the <strong>customTask<\/strong> field. It resolves the variable to a <em>closure<\/em>, which is basically a function that automatically receives a <a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/analyticsjs\/model-object-reference\">model object<\/a> as a parameter. The model object can be manipulated using the <code>get<\/code> and <code>set<\/code> methods.<\/p>\n<p>Next, we <strong>set<\/strong> the Custom Dimension at index 5 (as determined by the value of <code>customDimensionIndex<\/code>) to the Client ID, which we retrieve with the <strong>get<\/strong> method of the model object.<\/p>\n<p>This little trick means that we can tell the GA tag to fetch the Client ID from the tracker object and send it in a Custom Dimension without any extra hacks or workarounds that we had to employ previously. The fact that <code>customTask<\/code> has no other function in Universal Analytics means that we don\u2019t have to mind the fact that we\u2019re overwriting a task method with this tag.<\/p>\n<p>You can use this for <a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/analyticsjs\/field-reference\">any fields<\/a> in the model\/tracker object if you wish.<\/p>\n<\/p><\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>One of the things I\u2019ve recommended from the get-go is to always send the Client ID to Google Analytics with your users\u2019 hits. This is very useful for adding a level of granularity to your tracking. At first, I recommended using an Event tag to do this. Then I modified my approach a little so [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":121477,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12033],"tags":[1846,47087,1531,14492,14495,1791,1191,11238],"dealstore":[],"offerexpiration":[],"class_list":["post-121476","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-analytics","tag-access","tag-customtask","tag-google","tag-gtmtips","tag-manager","tag-tag","tag-tracker","tag-values"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>#GTMTips: Use customTask To Access Tracker Values In Google Tag Manager - Som2ny Network<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/fivemor.com\/?p=121476\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"#GTMTips: Use customTask To Access Tracker Values In Google Tag Manager - Som2ny Network\" \/>\n<meta property=\"og:description\" content=\"One of the things I\u2019ve recommended from the get-go is to always send the Client ID to Google Analytics with your users\u2019 hits. This is very useful for adding a level of granularity to your tracking. At first, I recommended using an Event tag to do this. Then I modified my approach a little so [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fivemor.com\/?p=121476\" \/>\n<meta property=\"og:site_name\" content=\"Som2ny Network\" \/>\n<meta property=\"article:published_time\" content=\"2025-03-09T05:17:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/customtask-fields-to-set.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1766\" \/>\n\t<meta property=\"og:image:height\" content=\"792\" \/>\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=121476#article\",\"isPartOf\":{\"@id\":\"https:\/\/fivemor.com\/?p=121476\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371\"},\"headline\":\"#GTMTips: Use customTask To Access Tracker Values In Google Tag Manager\",\"datePublished\":\"2025-03-09T05:17:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/fivemor.com\/?p=121476\"},\"wordCount\":436,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/fivemor.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/?p=121476#primaryimage\"},\"thumbnailUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/customtask-fields-to-set.jpg\",\"keywords\":[\"Access\",\"customTask\",\"Google\",\"GTMTips\",\"Manager\",\"TAG\",\"Tracker\",\"Values\"],\"articleSection\":[\"Analytics\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/fivemor.com\/?p=121476#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/fivemor.com\/?p=121476\",\"url\":\"https:\/\/fivemor.com\/?p=121476\",\"name\":\"#GTMTips: Use customTask To Access Tracker Values In Google Tag Manager - Som2ny Network\",\"isPartOf\":{\"@id\":\"https:\/\/fivemor.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/fivemor.com\/?p=121476#primaryimage\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/?p=121476#primaryimage\"},\"thumbnailUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/customtask-fields-to-set.jpg\",\"datePublished\":\"2025-03-09T05:17:31+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/fivemor.com\/?p=121476#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/fivemor.com\/?p=121476\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/?p=121476#primaryimage\",\"url\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/customtask-fields-to-set.jpg\",\"contentUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/customtask-fields-to-set.jpg\",\"width\":1766,\"height\":792},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/fivemor.com\/?p=121476#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/fivemor.com\/?bp_activities=1\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"#GTMTips: Use customTask To Access Tracker Values In Google Tag Manager\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/fivemor.com\/#website\",\"url\":\"https:\/\/fivemor.com\/\",\"name\":\"Som2ny Network\",\"description\":\"Daily Deals\",\"publisher\":{\"@id\":\"https:\/\/fivemor.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/fivemor.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/fivemor.com\/#organization\",\"name\":\"Som2ny Network\",\"url\":\"https:\/\/fivemor.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png\",\"contentUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png\",\"width\":300,\"height\":86,\"caption\":\"Som2ny Network\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png\",\"caption\":\"admin\"},\"sameAs\":[\"https:\/\/fivemor.com\"],\"url\":\"https:\/\/fivemor.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"#GTMTips: Use customTask To Access Tracker Values In Google Tag Manager - Som2ny Network","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/fivemor.com\/?p=121476","og_locale":"en_US","og_type":"article","og_title":"#GTMTips: Use customTask To Access Tracker Values In Google Tag Manager - Som2ny Network","og_description":"One of the things I\u2019ve recommended from the get-go is to always send the Client ID to Google Analytics with your users\u2019 hits. This is very useful for adding a level of granularity to your tracking. At first, I recommended using an Event tag to do this. Then I modified my approach a little so [&hellip;]","og_url":"https:\/\/fivemor.com\/?p=121476","og_site_name":"Som2ny Network","article_published_time":"2025-03-09T05:17:31+00:00","og_image":[{"width":1766,"height":792,"url":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/customtask-fields-to-set.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=121476#article","isPartOf":{"@id":"https:\/\/fivemor.com\/?p=121476"},"author":{"name":"admin","@id":"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371"},"headline":"#GTMTips: Use customTask To Access Tracker Values In Google Tag Manager","datePublished":"2025-03-09T05:17:31+00:00","mainEntityOfPage":{"@id":"https:\/\/fivemor.com\/?p=121476"},"wordCount":436,"commentCount":0,"publisher":{"@id":"https:\/\/fivemor.com\/#organization"},"image":{"@id":"https:\/\/fivemor.com\/?p=121476#primaryimage"},"thumbnailUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/customtask-fields-to-set.jpg","keywords":["Access","customTask","Google","GTMTips","Manager","TAG","Tracker","Values"],"articleSection":["Analytics"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fivemor.com\/?p=121476#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fivemor.com\/?p=121476","url":"https:\/\/fivemor.com\/?p=121476","name":"#GTMTips: Use customTask To Access Tracker Values In Google Tag Manager - Som2ny Network","isPartOf":{"@id":"https:\/\/fivemor.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fivemor.com\/?p=121476#primaryimage"},"image":{"@id":"https:\/\/fivemor.com\/?p=121476#primaryimage"},"thumbnailUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/customtask-fields-to-set.jpg","datePublished":"2025-03-09T05:17:31+00:00","breadcrumb":{"@id":"https:\/\/fivemor.com\/?p=121476#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fivemor.com\/?p=121476"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/?p=121476#primaryimage","url":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/customtask-fields-to-set.jpg","contentUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/customtask-fields-to-set.jpg","width":1766,"height":792},{"@type":"BreadcrumbList","@id":"https:\/\/fivemor.com\/?p=121476#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fivemor.com\/?bp_activities=1"},{"@type":"ListItem","position":2,"name":"#GTMTips: Use customTask To Access Tracker Values In Google Tag Manager"}]},{"@type":"WebSite","@id":"https:\/\/fivemor.com\/#website","url":"https:\/\/fivemor.com\/","name":"Som2ny Network","description":"Daily Deals","publisher":{"@id":"https:\/\/fivemor.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/fivemor.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/fivemor.com\/#organization","name":"Som2ny Network","url":"https:\/\/fivemor.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/#\/schema\/logo\/image\/","url":"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png","contentUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png","width":300,"height":86,"caption":"Som2ny Network"},"image":{"@id":"https:\/\/fivemor.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png","caption":"admin"},"sameAs":["https:\/\/fivemor.com"],"url":"https:\/\/fivemor.com\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts\/121476","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=121476"}],"version-history":[{"count":0,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts\/121476\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/media\/121477"}],"wp:attachment":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=121476"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=121476"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=121476"},{"taxonomy":"dealstore","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fdealstore&post=121476"},{"taxonomy":"offerexpiration","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fofferexpiration&post=121476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}