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:
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!