Custom Dimensions not formatted properly for GA4 (and dont work)

Created on 30 March 2023, about 1 year ago
Updated 29 May 2023, about 1 year ago

I setup the newest version of the 7.x module for GA4 reporting, and it's sending data correctly. I had custom dimensions setup and working fine in UA, but they are not working in GA4.

I believe I tracked the problem to the fact that GA4 requires an 'event' to send the custom dimension data on pageload. It doesn't happen automatically with the 'config' tag like it did in UA. So right now the module is formatting a GA4 custom dimension to send like this:

gtag("config", "G-XXXXXXXXXXX", {
    "dimension1":"dimension 1 data",
    "dimension2":"dimension 2 data,    
    [rest of the config code...]});

But it actaully needs to be formatted with an event, similar to the following. First the config:
gtag("config", "G-XXXXXXXXXXX");
Then the actual event for the custom dimensions:

 gtag('event', 'screen_view', {
        'dimension1': 'dimension 1 data',
        'dimension2': 'dimension 2 data',
      });

I haven't confirmed this working yet, but the current module isn't working and this is how it's shown in the documentation.

πŸ› Bug report
Status

Postponed: needs info

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States Rob_Feature

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Rob_Feature
  • πŸ‡ΊπŸ‡ΈUnited States Rob_Feature
  • πŸ‡ΊπŸ‡ΈUnited States Rob_Feature
  • πŸ‡ΊπŸ‡ΈUnited States Rob_Feature

    Just an update: I read that the gtag sends a page_view event automatically on 'config'....so it seems like maybe the code thats in the module should work. But mine isn't. Anyone having luck with Custom Dimensions and GA4? Wondering what I might be missing...

  • Status changed to Postponed: needs info about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States mglaman WI, USA

    The config triggers a page view. Dimensions and metrics should be called using set before any events. These are then automatically attached to all events that get tracked.

    I discussed this with the Google Analytics team to make sure that was correct.

    Can you dump a sample of what the module is generating in terms of the set/config/event calls with gtag? And obfuscate any values as needed.

  • I think i'm facing the same problem, GA-4 custom dimentions does't work, maybe i set something wrong. Did you find what was ann issue?

  • So i managed to make it work by setting names properly in drupal module settings, they have to match event parameter in GA4. Maybe it should be mantioned in module README.

Production build 0.69.0 2024