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!
Unlike analytics. js, gtag. js doesn't use trackers to send data to Google Analytics. It sends data to Google Analytics properties identified by their IDs set by the config command.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With