Reputation: 686
I have configured dimension in my page like this :
// Maps 'dimension2' to 'age'.
gtag('config', 'GA_TRACKING_ID', {
'custom_map': {'dimension2': 'age'}
});
// Sends an event that passes 'age' as a parameter.
gtag('event', 'age_dimension', {'age': 12});
But whenever I want to raise an event from gtag like :
gtag('event', 'xyz');
Config values are persisted with each navigator.sendBeacon call. Suppose on click of any button I want to raise this event but don't want to send dimension data.
I know that I have to configure it again like:
gtag('config', 'GA_TRACKING_ID')
But If I want to send dimensions again on another button click I will have to configure it again which I don't want to do.
Is there any option available for such type of configuration in gtag?
Upvotes: 1
Views: 727
Reputation: 1570
When you add the custom dimension on the config, all the future interactions will carry the CD, so there is 3 options,
1.- Send the information only when is needed, for example, if you want to send the information only on the pageview you can set the parameter only to this object passing the configuration in a json
gtag('config', 'UA-xxxxxxxxxxxxx-1' , {'dimension1': "asd"});
2.- Send Always but nullify in a object: for example, if you want to send always the custom dimensions but in a single hit don't don't want to send it, you can pass the null as the value, in that case, and in only that it will no carry the information
gtag('event', 'xyz' , {'dimension1' : null});
3.- In the last chance, you can use the set element to apply all the
gtag('config', 'UA-82629596-1'); // Hit with no CD
gtag( 'set' , {'dimension1' : "yxz"} ); // CD Set fot the future
gtag('config', 'UA-82629596-1'); // Will carry the CD
gtag('event', 'login' ); // Will carry the CD
Upvotes: 1