Category: Analytics
This integration is only available for Web projects
What to expect
Contentsquare allows you to use your Google Analytics segments in every Contentsquare module (Journey Analysis, Page Comparator, Zoning Analysis, Session Replay).
To import your segments, you need to add a snippet of code to your website. This code pushes an identifier to Google Analytics. It helps us match Google Analytics sessions with Contentsquare one's.
What we collect
Dynamic Variables
Key | Value | Data Type |
csMatchingKey | {csMatchingKey} | Text |
csMatchingKey
Refers to the unique value used to cross reference Google dimensions with Contentsquare sessions.
Implementation
Implementation Steps
Create a Custom Dimension

There are many ways to integrate the code but we will cover the following options:
-
Google Tag Manager
- Tealium Tag Manager
-
Tag Commander or Directly Inline
-
Shopify
Google Tag Manager configuration







Tealium Tag Manager configuration










Grab the relevant code below in the code section and paste it in there.

Tag Commander or Inline configuration
Tag Commander currently does not have a built-in Google Analytics code container so you are most likely using a custom Javascript container.
If you are using GA code inline then the same applies below.
In the relevant code section below there are parts that you will already have defined and the rest is what you need to add to the existing parts in the same logical order.
Shopify
In Shopify if you are using the built in Google Analytics app then all you need to do is insert the code into this open textarea:
In the relevant code section below there are parts that you will already have defined and the rest is what you need to add to the existing parts in the same logical order.
The Code
Please note that if you have a cookie policy which requires our cookies to first be accepted before injection, then it is up to you to ensure the code below is wrapped in your cookie consent policy logic.
Google Tag Manager
/* *Name: Google Analytics CS Integration *Version: 1.13.0 (csMatchingKey + GTM) */ function gaCSintegration() { var version = "1.13.0"; function callback() { if (!disableCallback) { disableCallback = true; if (window.CS_CONF) { CS_CONF.integrations = CS_CONF.integrations || []; CS_CONF.integrations.push("Google Analytics - v" + version); } } } var disableCallback = false; window._uxa = window._uxa || []; _uxa.push(["afterPageView", callback]); var cmk = null; var cn = "_cs_mk_ga"; function init(cookieValue) { if (cookieValue) { cmk = cookieValue; } else { cmk = Math.random() + "_" + Date.now(); var tld = (function () { var i = 0, domain = document.domain, p = domain.split("."), s = "_cs_tld" + new Date().getTime(); while (i < p.length - 1 && document.cookie.indexOf(s + "=" + s) == -1) { domain = p.slice(-1 - ++i).join("."); document.cookie = s + "=" + s + ";domain=" + domain + ";SameSite=None;Secure"; } document.cookie = s + "=;expires=Thu, 01 Jan 1970 00:00:01 GMT;domain=" + domain + ";"; return domain; })(); var now = new Date(); var time = now.getTime(); time += 30 * 60 * 1000; now.setTime(time); document.cookie = cn + "=" + cmk + "; expires=" + now.toUTCString() + ";path=/;domain=" + tld + ";SameSite=None;Secure"; } _uxa.push([ "trackDynamicVariable", { key: "csMatchingKey", value: cmk, }, ]); } var cookies = "; " + document.cookie; if (cookies) { var getCookie = cookies.split("; " + cn + "="); if (getCookie.length == 1) { init(); } else { var cookieValue = getCookie[1].split(";")[0]; init(cookieValue); } } return cmk; } //Google Analytics CS Integration End
Tealium Tag Manager
/* *Name: Google Analytics CS Integration *Version: 1.9.0 (Tealium + csMatchingKey) */ (function () { var version = "1.9.0"; function callback() { if (!disableCallback) { disableCallback = true; if (window.CS_CONF) { CS_CONF.integrations = CS_CONF.integrations || []; CS_CONF.integrations.push("Google Analytics - v" + version); } } } var disableCallback = false; window._uxa = window._uxa || []; _uxa.push(["afterPageView", callback]); var cmk = null; var cn = "_cs_mk_ga"; function init(cookieValue) { if (cookieValue) { cmk = cookieValue; } else { cmk = Math.random() + "_" + Date.now(); var now = new Date(); var time = now.getTime(); time += 30 * 60 * 1000; now.setTime(time); document.cookie = cn + "=" + cmk + "; expires=" + now.toUTCString() + ";path=/;domain=." + utag.cfg.domain + ";SameSite=None;Secure"; } b.cs_matching_key = cmk; _uxa.push([ "trackDynamicVariable", { key: "csMatchingKey", value: cmk, }, ]); } if (!b["cp._cs_mk_ga"]) { init(); } else { var getCookieValue = b["cp._cs_mk_ga"]; init(getCookieValue); } })(); //Google Analytics CS Integration End
Tag Commander or Inline (ga version)
ga("create", "UA-XXXXXXXXX-X", "auto");For the gtag solution see below the ga code solution.
So change the X in this line:
ga("set", "dimensionX", cmk);
ga("send", "pageview");This is the code example below
(function () { ga("create", "UA-XXXXXXXXX-X", "auto"); /* *Name: Google Analytics CS Integration *Version: 1.11.0 (ga + csMatchingKey + inline) */ var version = "1.11.0"; function callback() { if (!disableCallback) { disableCallback = true; if (window.CS_CONF) { CS_CONF.integrations = CS_CONF.integrations || []; CS_CONF.integrations.push("Google Analytics - v" + version); } } } var disableCallback = false; window._uxa = window._uxa || []; _uxa.push(["afterPageView", callback]); var cmk = null; var cn = "_cs_mk_ga"; function init(cookieValue) { if (cookieValue) { cmk = cookieValue; } else { cmk = Math.random() + "_" + Date.now(); var tld = (function () { var i = 0, domain = document.domain, p = domain.split("."), s = "_cs_tld" + new Date().getTime(); while (i < p.length - 1 && document.cookie.indexOf(s + "=" + s) == -1) { domain = p.slice(-1 - ++i).join("."); document.cookie = s + "=" + s + ";domain=" + domain + ";SameSite=None;Secure"; } document.cookie = s + "=;expires=Thu, 01 Jan 1970 00:00:01 GMT;domain=" + domain + ";"; return domain; })(); var now = new Date(); var time = now.getTime(); time += 30 * 60 * 1000; now.setTime(time); document.cookie = cn + "=" + cmk + "; expires=" + now.toUTCString() + ";path=/;domain=" + tld + ";SameSite=None;Secure"; } _uxa.push([ "trackDynamicVariable", { key: "csMatchingKey", value: cmk, }, ]); } var cookies = "; " + document.cookie; if (cookies) { var getCookie = cookies.split("; " + cn + "="); if (getCookie.length == 1) { init(); } else { var cookieValue = getCookie[1].split(";")[0]; init(cookieValue); } } if (cmk) { ga("set", "dimensionX", cmk); } //Google Analytics CS Integration End ga("send", "pageview"); })();
Tag Commander or Inline (gtag version)
gtag("js", new Date());
So change the X in this line:
"dimensionX": "csMatchingKey"
gtag("config", "UA-XXXXXXXXX-X", { "csMatchingKey": cmk });
(function () { window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments); } gtag("js", new Date()); /* *Name: Google Analytics CS Integration *Version: 1.11.0 (gtag + csMatchingKey + Inline + Tag Commander) */ var version = "1.11.0"; function callback() { if (!disableCallback) { disableCallback = true; if (window.CS_CONF) { CS_CONF.integrations = CS_CONF.integrations || []; CS_CONF.integrations.push("Google Analytics - v" + version); } } } var disableCallback = false; window._uxa = window._uxa || []; _uxa.push(["afterPageView", callback]); var cmk = null; var cn = "_cs_mk_ga"; function init(cookieValue) { if (cookieValue) { cmk = cookieValue; } else { cmk = Math.random() + "_" + Date.now(); var tld = (function () { var i = 0, domain = document.domain, p = domain.split("."), s = "_cs_tld" + new Date().getTime(); while (i < p.length - 1 && document.cookie.indexOf(s + "=" + s) == -1) { domain = p.slice(-1 - ++i).join("."); document.cookie = s + "=" + s + ";domain=" + domain + ";SameSite=None;Secure"; } document.cookie = s + "=;expires=Thu, 01 Jan 1970 00:00:01 GMT;domain=" + domain + ";"; return domain; })(); var now = new Date(); var time = now.getTime(); time += 30 * 60 * 1000; now.setTime(time); document.cookie = cn + "=" + cmk + "; expires=" + now.toUTCString() + ";path=/;domain=" + tld + ";SameSite=None;Secure"; } _uxa.push([ "trackDynamicVariable", { key: "csMatchingKey", value: cmk, }, ]); } var cookies = "; " + document.cookie; if (cookies) { var getCookie = cookies.split("; " + cn + "="); if (getCookie.length == 1) { init(); } else { var cookieValue = getCookie[1].split(";")[0]; init(cookieValue); } } if (cmk) { gtag("set", { custom_map: { dimensionX: "csMatchingKey", }, }); gtag("config", "UA-XXXXXXXXX-X", { csMatchingKey: cmk, }); } //Google Analytics CS Integration End else { gtag("config", "UA-XXXXXXXXX-X"); } })();
Shopify
So change the X in this line:
ga("set", "dimensionX", cmk);
/* *Name: Google Analytics CS Integration *Version: 1.11.0 (ga + csMatchingKey + Shopify) */ var version = "1.11.0"; function callback() { if (!disableCallback) { disableCallback = true; if (window.CS_CONF) { CS_CONF.integrations = CS_CONF.integrations || []; CS_CONF.integrations.push("Google Analytics - v" + version); } } } var disableCallback = false; window._uxa = window._uxa || []; _uxa.push(["afterPageView", callback]); var cmk = null; var cn = "_cs_mk_ga"; function init(cookieValue) { if (cookieValue) { cmk = cookieValue; } else { cmk = Math.random() + "_" + Date.now(); var tld = (function () { var i = 0, domain = document.domain, p = domain.split("."), s = "_cs_tld" + new Date().getTime(); while (i < p.length - 1 && document.cookie.indexOf(s + "=" + s) == -1) { domain = p.slice(-1 - ++i).join("."); document.cookie = s + "=" + s + ";domain=" + domain + ";SameSite=None;Secure"; } document.cookie = s + "=;expires=Thu, 01 Jan 1970 00:00:01 GMT;domain=" + domain + ";"; return domain; })(); var now = new Date(); var time = now.getTime(); time += 30 * 60 * 1000; now.setTime(time); document.cookie = cn + "=" + cmk + "; expires=" + now.toUTCString() + ";path=/;domain=" + tld + ";SameSite=None;Secure"; } _uxa.push([ "trackDynamicVariable", { key: "csMatchingKey", value: cmk, }, ]); } var cookies = "; " + document.cookie; if (cookies) { var getCookie = cookies.split("; " + cn + "="); if (getCookie.length == 1) { init(); } else { var cookieValue = getCookie[1].split(";")[0]; init(cookieValue); } } if (cmk) { ga("set", "dimensionX", cmk); } //Google Analytics CS Integration End
Verifying it works


Google Connector Configuration
After you have completed the steps above please resume with setting up the Google Analytics connector in the Contentsquare app by going to this link.