Learn business growth with Google Analytics 4 Forums Google Analytics 4 Enhancing Analytics Tracking with Custom Dimensions in Google Analytics 4

  • Enhancing Analytics Tracking with Custom Dimensions in Google Analytics 4

    Posted by Reese on 1 July 2023 at 8:21 pm

    Hey there, I’ve been able to link my UA Google Analytics to a new GA4 property right from the GA admin panel. The data started rolling in without having to tweak any code, which was great.

    But here’s a little hitch: The custom dimensions don’t seem to be showing up.

    Just to give you a picture, the js code on the page has a string of gtag set calls like this:

    gtag('set', 'dimension2', 'test')

    I thought I’d try setting up custom dimensions on the GA4 property just to see if they’d show up without me touching the code. So I popped into the new GA4 property, went to Configure > Custom Definitions > Custom Dimensions, and threw in a bunch of new custom dimensions. I used a User Property naming convention that matches our old-school one: dimension2, dimension3, you know the drill.

    But that doesn’t seem to be doing the trick. Is there some way I can get the UA custom dimensions to feed into the GA4 property without having to alter the javascript? Or is there a way to adjust the javascript so it still works with the earlier version and sends the custom dimension to both my UA and GA4 properties?

    Any insights would be awesome. Thanks!

    Sophia replied 10 months, 4 weeks ago 3 Members · 2 Replies
  • 2 Replies
  • Olivia

    2 July 2023 at 7:22 am

    Absolutely, I’d be happy to clarify it for you. The thing is, it’s really a matter of how the code is formatted. Your current code might not be doing what you want it to because it’s in the incorrect format.

    Instead of the code gtag('set', 'dimension2', 'test'), it should actually be written as gtag('set', {'dimension2', 'test'}). That just means we’re incorporating the dimension and its value together between curly braces.

    Once you tweak that, everything should work as you expect. It’s a straightforward change that should have you seeing those custom dimensions in no time. So just make the switch and you’re good to go!

  • Sophia

    8 July 2023 at 12:15 pm

    Unfortunately, you cannot directly pass the Universal Analytics (UA) custom dimensions to Google Analytics 4 (GA4) without making changes to your JavaScript code. This is because UA and GA4 handle custom dimensions differently. UA uses a flat structure with custom dimensions & metrics being numbers (like dimension1, dimension2), but GA4 utilizes an event-based model and its custom parameters are named.

    It means you’ll have to modify the JavaScript code to handle GA4 custom dimensions (user properties). You’d need to, for example, use gtag('event', 'some_event', {'dimension_name': 'value'}); for GA4.

    You also can’t use the same custom dimension tag to send data to both your UA and GA4 properties because of their different implementations. They would need separate tags.

    Remember to set up the new custom dimensions in GA4, then in GTM ensure your tags reflect the different custom dimension structure of GA4 compared to UA. Finally, thoroughly test everything before fully migrating.

    Keep in mind that enabling GA4 does not mean you have to immediately stop using UA. Both can and should run simultaneously during your transition.

Log in to reply.