Reputation: 602
First off: I'm very new to Google Analytics!
I'm trying to use GA to track a custom event with some custom parameters, but I'm not doing very well. I've set up gtag.js
according to this and it is working if I only set the following parameters:
function trackOutboundLink(url) {
gtag('event', 'click', {
'event_category': 'outbound',
'event_label': url,
'transport_type': 'beacon',
'event_callback': function() {
document.location = url;
}
});
return false;
}
But I would like to set some additional parameters and according to this it should be possible:
"You can add custom data, in the form of additional parameters, to any event (recommended or custom)"
I'm setting up GA using this:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=MY_GA_TRACKING_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'MY_GA_TRACKING_ID');
</script>
And I'm calling gtag()
the following way:
function trackOutboundLinkWithCustomParameters(label, version, url) {
gtag('event', 'click', {
'event_category': 'outbound',
'event_label': label,
'transport_type': 'beacon',
'mobile_app_version': version,
'download_url': url,
'event_callback': function() {
document.location = url;
}
});
return false;
}
If I break at dataLayer.push(arguments);
and prints arguments
I get the following (which is what I want to track):
But after having installed GA Debugger it seems it ignores my extra parameters when sending the tracking data:
Bottom line is: I can't see the additional info I provide about mobile_app_version
and download_url
in my GA dashboard.
Help!
Upvotes: 1
Views: 2863
Reputation: 8907
Any custom parameters that you want to see in your standard reports will need to be configured before you send your data in with your event (cf. https://developers.google.com/analytics/devguides/collection/gtagjs/custom-dims-mets#send-custom-dimensions), so in your example, you should have something like this:
gtag('config', 'MY_GA_TRACKING_ID', {
'custom_map': {
'dimension1': 'mobile_app_version',
'dimension2': 'download_url'
}
})
Make sure you have already configured what the custom dimensions are.
Upvotes: 2