0

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

  1. Sign in to Google Analytics.
  2. Click Admin, and navigate to the property to which you want to add custom dimensions.
  3. In the PROPERTY column, click Custom Definitions > Custom Dimensions.
  4. Click New Custom Dimension.
  5. Add a Name. I have added a name unit id
  6. Select the Scope. Added the user as the scope
  7. Click Save.

This is the screenshot:

enter image description here

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.

enter image description here What i am missing here? Any guidance will be appreciated. Thank you.

enter image description here

Rasik
  • 1,961
  • 3
  • 35
  • 72

1 Answers1

1

Looks like you've missed an essential step of debugging: inspecting your collect network request to make sure that you really do meaningfully set this dimension. But don't worry, I see the problem.

Gtag set doesn't work as you expect. Don't use it. Use config, or set your user id property in the event directly. Please read the full answer here: Google Analytics custom dimension not working: gtag set() method issues

If reimplementing your gtag tracking will still not work, please include the screenshot of the actual Network call. It normally reliably indicates whether the problem is in GA, or on the page.

BNazaruk
  • 6,300
  • 3
  • 19
  • 33