Learn business growth with Google Analytics 4 Forums Google Analytics 4 . Google Analytics 4 Custom Dimensions Not Recording: What Did I Miss?

  • . Google Analytics 4 Custom Dimensions Not Recording: What Did I Miss?

    Posted by Caleb on 26 June 2023 at 10:12 am

    So, here’s the deal. I’ve been trying to figure out how to get custom dimensions in Google Analytics working. Here’s a look at how I’ve set up my code:

    <script async src="https://www.googletagmanager.com/gtag/js?id=G-XXX"></script>
        window.dataLayer = window.dataLayer || [];
        function gtag() { dataLayer.push(arguments); }
        gtag('js', new Date());
        // Set up custom dimensions for user ID and unit ID
        gtag('set', { 'user_id': @authorizationService.UserId });
        // Grab unit ID from cookie and use that 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();

    I then went about configuring things in Google Analytics with these steps:

    1. Logged into Google Analytics.
    2. Clicked Admin, then picked the property I’m working on.
    3. In the PROPERTY column, clicked on Custom Definitions > Custom Dimensions.
    4. Clicked New Custom Dimension.
    5. Light-bulb on, added a name. In my case, I named it unit id
    6. Marked user as the scope
    7. And saved the whole shebang!

    Here’s a screenshot of how things look:

    Screenshot of settings

    Now I’m stuck. Is there some other step I’m missing? My unit id doesn’t seem to be interactive, and keeps telling me that there’s no data available. It’s been a sweet two days since I set this up, by the way:

    Screenshot of error message

    Here’s another look at what’s going through:

    Screenshot of the set up

    Any clue about what I might be overlooking? All help appreciated. Cheers!

    Liam replied 11 months, 1 week ago 3 Members · 2 Replies
  • 2 Replies
  • Jayden

    2 July 2023 at 4:27 pm

    Hey there! So, I think I’ve spotted what might be going wrong here. You need to check out your collect network request to see if your dimension is actually being set – that’s an important debugging step.

    As it turns out, gtag set isn’t doing what you think it is. Instead, try using config or setting your user id property directly in the event. For more info, here’s a cool link with a full answer: [Google Analytics custom dimension not working: gtag set() method issues](https://stackoverflow.com/questions/73870122/google-analytics-custom-dimension-not-working-gtag-set-method-issues)

    After that, if you’re still facing issues, please share a screenshot of your actual Network call, that definitely helps determine if the problem is with GA, or on your page. Keep going, you’ve got this!

  • Liam

    2 July 2023 at 5:31 pm

    The issue you are experiencing with your custom dimensions in Google Analytics not working might be because you are not properly setting and passing the custom dimension index. In Google Analytics, each custom dimension you create is assigned a unique index that you need to refer to when passing data. In the code you provided, you are setting a ‘unit_id’ value but not passing the custom dimension index from Google Analytics.

    Your JavaScript code configuration should include the custom dimension index like this:

    gtag('event', 'page_view', {'dimension1': unitId});

    Make sure to replace ‘dimension1’ with the index of the custom dimension you created in Google Analytics. Also, note that sometimes it can take up to 24-48 hours for data to start appearing on Google Analytics. So, you might want to wait for a day or two if you have just setup your codes.

    Lastly, verify that you have correctly added and saved your custom dimension in Google Analytics and that its scope is appropriate for the type of data you’re tracking.

    By properly passing the custom dimension index in your code and ensuring your Dimensions configurations in Google Analytics are correct, your custom dimensions should start working.

Log in to reply.