9
votes

I'm trying to get custom dimensions to work in Google Analytics using the 'new' gtag library. I've added a new custom dimension to the property in the GA administration section:

Username image

Next I've configured a mapping as per the (specs) by adding this snippet:

gtag('config', '<My GA tag here>', {
    'send_page_view': false,
    'custom_map': {
        'dimension1': 'my_username'
    }
});

Next when the user logs in I set the my_username property:

gtag('set', 'my_username', '<username of logged in user>');

And expect it to be pushed for every event:

gtag('event', 'login');
gtag('event', 'page_view', {'page_path': calculated_current_spa_location});
etc

Unfortunately, while the events show up in Analytics when setting the secondary dimension to Username none of the events seem to have the value.

I've also tried setting the property directly when registering the event:

gtag('event', 'page_view', {
    'page_path': calculated_current_spa_location,
    'my_username', '<username of logged in user>'
});

But to no avail :(

Any help would be greatly appreciated, thanks!

2
Did you manage to find a solution for this?cyberpirate92
I did not, but my priorities shifted and I've let it rest, if you do figure it out though, please let me know.Robba

2 Answers

2
votes

Try this:

gtag('config', 'GA_TRACKING_ID', {
    'custom_map': {'dimension1': 'my_username'}
});
gtag('event', 'my_username_event', {'my_username': '<username of logged in user>'});

Should work fine and should give you Secondary dimension data.

1
votes

I experienced a similar issue. It was related to not re-sending the custom dimensions again in custom_map when tracking page views. You can view my answer here on how I solved the problem.