Learn business growth with Google Analytics 4 Forums Google Analytics 4 How to track dynamic dataLayer values as custom dimensions in GA4

  • How to track dynamic dataLayer values as custom dimensions in GA4

    Posted by Archie on 2 May 2023 at 10:38 pm

    So, I’ve got a dataLayer variable that changes with each pageview. In Universal Analytics, it was tracked as a hit-scoped custom dimension and recorded through Google Tag Manager’s analytics settings variable.

    I’m now trying to figure out how to do this or something similar in GA4.

    From what I understand, I need to set up a new GA4 event that triggers on every pageview and send the dataLayer value as an event parameter.

    Am I on the right track? Do I really have to count off an event for EVERY SINGLE PAGEVIEW just to grab dataLayer values as custom dimensions?

    Adam replied 11 months ago 3 Members · 2 Replies
  • 2 Replies
  • Isabella

    8 May 2023 at 3:01 pm

    Sure, you got it! So, you can simply plug this in as a parameter in your GA4 config tag, that way it’ll log the parameter’s value with each page. But here’s the thing: if that value can shift around on one single page without that page getting refreshed or swapped out, you would be better off going ahead and whipping up a new datalayer event. Also, make a matching GTM trigger and tag. This way, any time our shifty value decides to change, you’ll nab it then and there, rather than twiddling your thumbs until the next page loads. Hope this helps clarify things for you!

  • Adam

    9 June 2023 at 3:47 am

    Yes, you are on the right track. In GA4, the tracking model is event-based and no longer relies on sessions and pageviews like in Universal Analytics. There are no scoped dimensions in GA4, instead, all the data you want to track must be sent as an event parameter. It can be tedious to set up, but to track the dataLayer values as custom dimensions, you would indeed need to set up a GA4 event to trigger on every single pageview. You might consider streamlining this process if the dataLayer values are the same across multiple pages by setting up an event that sends the dataLayer value only when it changes. This way, you get the same data but reduce the number of events you trigger.

Log in to reply.