I have set up the code for google analytics to capture the custom dimension in this way.
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
// Set custom dimensions for user ID and unit ID
gtag('set', { 'user_id': @authorizationService.UserId });
// Retrieve unit ID from the cookie and set as a custom dimension
var unitId = parseInt(getCookieValue('UnitFilter'));
if (!isNaN(unitId)) {
gtag('set', { 'unit_id': unitId });
}
gtag('config', 'G-XXX');
function getCookieValue(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2) {
return parts.pop().split(";").shift();
}
}
</script>
And then I followed the following steps:
Adding Custom Dimensions in Google Analytics
- Sign in to Google Analytics.
- Click Admin, and navigate to the property to which you want to add custom dimensions.
- In the PROPERTY column, click Custom Definitions > Custom Dimensions.
- Click New Custom Dimension.
- Add a Name. I have added a name unit id
- Select the Scope. Added the user as the scope
- Click Save.
This is the screenshot:
Is there anything extra that I need to configure further?
the unit id is not clickable, here it says. It says no data is currently available. And it's been more than 48hrs since I had setup this.
What i am missing here? Any guidance will be appreciated. Thank you.