{"id":112884,"date":"2025-02-27T07:37:37","date_gmt":"2025-02-27T07:37:37","guid":{"rendered":"https:\/\/peraltafinancing.com\/analytics\/add-client-id-to-custom-dimension-with-gtag-js\/"},"modified":"2025-02-27T07:37:37","modified_gmt":"2025-02-27T07:37:37","slug":"add-client-id-to-custom-dimension-with-gtag-js","status":"publish","type":"post","link":"https:\/\/fivemor.com\/?p=112884","title":{"rendered":"Add Client ID To Custom Dimension With gtag.js"},"content":{"rendered":"<p> <br \/>\n<\/p>\n<div>\n<p>When Google released <a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/gtagjs\/\">gtag.js<\/a>, the new, global tracking library designed to (eventually) replace <a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/analyticsjs\/\">analytics.js<\/a>, many Universal Analytics practitioners and users were confused (see e.g. Jeff\u2019s great overview <a href=\"https:\/\/www.jeffalytics.com\/google-gtag-js\/\">here<\/a>). It seemed like <strong>gtag.js<\/strong> wasn\u2019t really solving any immediate problem, since analytics.js had done a bang-up job with Universal Analytics tracking for all these years. However, <strong>gtag\u2019s<\/strong> modus operandi is the ability to leverage the same semantic information (distributed across <code>dataLayer<\/code>!) across a number of Google products, starting with GA and AdWords.<\/p>\n<p>But migrating to <strong>gtag.js<\/strong> isn\u2019t just a find-and-replace operation &#8211; there are <a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/gtagjs\/migration\">many things<\/a> to consider due to the fact that they are completely different tracking libraries, and feature parity is yet to be reached.<\/p>\n<div style=\"aspect-ratio: 1346 \/ 314;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2017\/12\/add-clientid-custom-dimension-gtag.jpg\" title=\"Add Client ID as a custom dimension when using gtag.js\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"314\" width=\"1346\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2017\/12\/add-clientid-custom-dimension-gtag.jpg#ZgotmplZ\" alt=\"Add Client ID as a custom dimension when using gtag.js\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>One of the things I was really concerned about was how to add my <a href=\"https:\/\/www.simoahava.com\/analytics\/two-ways-to-persist-data-via-google-tag-manager\/\">favorite<\/a> custom dimension to the hits: the Client ID stored in the <code>_ga<\/code> cookie. With <strong>gtag.js<\/strong>, this is actually ridiculously easy, and you don\u2019t need to leverage <a href=\"https:\/\/www.simoahava.com\/gtm-tips\/use-customtask-access-tracker-values-google-tag-manager\/\"><code>customTask<\/code><\/a> or the <code>ga.getAll()<\/code> tracker method (which still does exist when using <strong>gtag.js<\/strong>!).<\/p>\n<p>Huge thanks to <strong>Yamata Ryoda<\/strong> for pointing this method out. You can read the original tip (in Japanese) <a href=\"https:\/\/sem-technology.info\/en\/google-analytics\/gtag-clientid\">here<\/a>.<\/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=\"how-to-add-client-id-to-a-custom-dimension-with-gtagjs\">How to add Client ID to a custom dimension with gtag.js<\/h2>\n<p>So after the long preamble here\u2019s the tip in all its glory:<\/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-js\" data-lang=\"js\">gtag(<span style=\"color:#a50\">'config'<\/span>, <span style=\"color:#a50\">'UA-12345-1'<\/span>, {\n  <span style=\"color:#a50\">'custom_map'<\/span>: {\n    <span style=\"color:#a50\">'dimensionX'<\/span>: <span style=\"color:#a50\">'clientId'<\/span>\n  }\n});\n<\/code><\/pre>\n<\/div>\n<p>Just replace <code>UA-12345-1<\/code> with your Universal Analytics tracking ID, and the X in <code>dimensionX<\/code> with the custom dimension index, and <strong>gtag.js<\/strong> takes care of the rest.<\/p>\n<p>Such a simple way to do it. My main gripe right now is that this isn\u2019t officially documented, and we don\u2019t know what other \u201cspecial\u201d values <strong>gtag.js<\/strong> hides under its hood. And what if I wanted to send the string \u201cclientId\u201d to GA as the value of that custom dimension? Hmm. Might not be that common.<\/p>\n<h2 id=\"summary\">Summary<\/h2>\n<p>So there is a really easy way to add the Client ID to a custom dimension when using <strong>gtag.js<\/strong>. It\u2019s so easy, in fact, that you should do it right now. Sending the Client ID to Google Analytics is almost necessary in order to see reports distributed row-by-row, where each row is a distinct Google Analytics user. You only get this otherwise in the <a href=\"https:\/\/support.google.com\/analytics\/answer\/6339208?hl=en\">User Explorer<\/a> reports.<\/p>\n<\/p><\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>When Google released gtag.js, the new, global tracking library designed to (eventually) replace analytics.js, many Universal Analytics practitioners and users were confused (see e.g. Jeff\u2019s great overview here). It seemed like gtag.js wasn\u2019t really solving any immediate problem, since analytics.js had done a bang-up job with Universal Analytics tracking for all these years. However, gtag\u2019s [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":112886,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12033],"tags":[16353,12982,834,34452,43615],"dealstore":[],"offerexpiration":[],"class_list":["post-112884","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-analytics","tag-add","tag-client","tag-custom","tag-dimension","tag-gtag-js"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Add Client ID To Custom Dimension With gtag.js - 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=112884\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Add Client ID To Custom Dimension With gtag.js - Som2ny Network\" \/>\n<meta property=\"og:description\" content=\"When Google released gtag.js, the new, global tracking library designed to (eventually) replace analytics.js, many Universal Analytics practitioners and users were confused (see e.g. Jeff\u2019s great overview here). It seemed like gtag.js wasn\u2019t really solving any immediate problem, since analytics.js had done a bang-up job with Universal Analytics tracking for all these years. However, gtag\u2019s [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fivemor.com\/?p=112884\" \/>\n<meta property=\"og:site_name\" content=\"Som2ny Network\" \/>\n<meta property=\"article:published_time\" content=\"2025-02-27T07:37:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/add-clientid-custom-dimension-gtag.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1346\" \/>\n\t<meta property=\"og:image:height\" content=\"314\" \/>\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=112884#article\",\"isPartOf\":{\"@id\":\"https:\/\/fivemor.com\/?p=112884\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371\"},\"headline\":\"Add Client ID To Custom Dimension With gtag.js\",\"datePublished\":\"2025-02-27T07:37:37+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/fivemor.com\/?p=112884\"},\"wordCount\":410,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/fivemor.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/?p=112884#primaryimage\"},\"thumbnailUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/add-clientid-custom-dimension-gtag.jpg\",\"keywords\":[\"Add\",\"client\",\"Custom\",\"Dimension\",\"gtag.js\"],\"articleSection\":[\"Analytics\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/fivemor.com\/?p=112884#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/fivemor.com\/?p=112884\",\"url\":\"https:\/\/fivemor.com\/?p=112884\",\"name\":\"Add Client ID To Custom Dimension With gtag.js - Som2ny Network\",\"isPartOf\":{\"@id\":\"https:\/\/fivemor.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/fivemor.com\/?p=112884#primaryimage\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/?p=112884#primaryimage\"},\"thumbnailUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/add-clientid-custom-dimension-gtag.jpg\",\"datePublished\":\"2025-02-27T07:37:37+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/fivemor.com\/?p=112884#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/fivemor.com\/?p=112884\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/?p=112884#primaryimage\",\"url\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/add-clientid-custom-dimension-gtag.jpg\",\"contentUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/add-clientid-custom-dimension-gtag.jpg\",\"width\":1346,\"height\":314},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/fivemor.com\/?p=112884#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/fivemor.com\/?bp_activities=1\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Add Client ID To Custom Dimension With gtag.js\"}]},{\"@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":"Add Client ID To Custom Dimension With gtag.js - 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=112884","og_locale":"en_US","og_type":"article","og_title":"Add Client ID To Custom Dimension With gtag.js - Som2ny Network","og_description":"When Google released gtag.js, the new, global tracking library designed to (eventually) replace analytics.js, many Universal Analytics practitioners and users were confused (see e.g. Jeff\u2019s great overview here). It seemed like gtag.js wasn\u2019t really solving any immediate problem, since analytics.js had done a bang-up job with Universal Analytics tracking for all these years. However, gtag\u2019s [&hellip;]","og_url":"https:\/\/fivemor.com\/?p=112884","og_site_name":"Som2ny Network","article_published_time":"2025-02-27T07:37:37+00:00","og_image":[{"width":1346,"height":314,"url":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/add-clientid-custom-dimension-gtag.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=112884#article","isPartOf":{"@id":"https:\/\/fivemor.com\/?p=112884"},"author":{"name":"admin","@id":"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371"},"headline":"Add Client ID To Custom Dimension With gtag.js","datePublished":"2025-02-27T07:37:37+00:00","mainEntityOfPage":{"@id":"https:\/\/fivemor.com\/?p=112884"},"wordCount":410,"commentCount":0,"publisher":{"@id":"https:\/\/fivemor.com\/#organization"},"image":{"@id":"https:\/\/fivemor.com\/?p=112884#primaryimage"},"thumbnailUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/add-clientid-custom-dimension-gtag.jpg","keywords":["Add","client","Custom","Dimension","gtag.js"],"articleSection":["Analytics"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fivemor.com\/?p=112884#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fivemor.com\/?p=112884","url":"https:\/\/fivemor.com\/?p=112884","name":"Add Client ID To Custom Dimension With gtag.js - Som2ny Network","isPartOf":{"@id":"https:\/\/fivemor.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fivemor.com\/?p=112884#primaryimage"},"image":{"@id":"https:\/\/fivemor.com\/?p=112884#primaryimage"},"thumbnailUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/add-clientid-custom-dimension-gtag.jpg","datePublished":"2025-02-27T07:37:37+00:00","breadcrumb":{"@id":"https:\/\/fivemor.com\/?p=112884#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fivemor.com\/?p=112884"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/?p=112884#primaryimage","url":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/add-clientid-custom-dimension-gtag.jpg","contentUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/add-clientid-custom-dimension-gtag.jpg","width":1346,"height":314},{"@type":"BreadcrumbList","@id":"https:\/\/fivemor.com\/?p=112884#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fivemor.com\/?bp_activities=1"},{"@type":"ListItem","position":2,"name":"Add Client ID To Custom Dimension With gtag.js"}]},{"@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\/112884","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=112884"}],"version-history":[{"count":0,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts\/112884\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/media\/112886"}],"wp:attachment":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=112884"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=112884"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=112884"},{"taxonomy":"dealstore","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fdealstore&post=112884"},{"taxonomy":"offerexpiration","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fofferexpiration&post=112884"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}