google analytics not tracking custom dimension in context to events - google-analytics

I need to differentiate the users (Internal and External) who are performing some event action. so I am using the following code to track the user using custom dimension. My end goal is to know who performed the specific event by internal or external user
ga('send', 'event', 'Contract Change', 'click', 'Landing Page', 'My Value', {
'dimension3': 'External'
});
ga('send', 'event', 'Contract Change', 'click', 'Landing Page', 'My Value', {
'dimension3': 'Internal'
});
I have triggered this tracking code from javascript console for the testing purpose however it's not logging any data and I am not able to get the custom dimension value at any of the place.

I would change a couple of things:
Integers for event value: like Eike Pierstorff said, the event value has to be an integer. Technically you could leave the field out as it's optional, but it's best practice to assign values to your goal, so you can quantity the importance of user actions on your website:
https://developers.google.com/analytics/devguides/collection/analyticsjs/events#event_fields
Set dimensions before events: what you're doing should work, however it makes the code harder to read (most code formatting will break the {} syntax into 2 lines). Also, if you're sending multiple events which should be associated with the dimension, it's just cleaner to have the dimension declaration first, then all your events. Finally, if it's a user-scope dimension (internal vs. external users), it's more logical to declare the dimension before events, otherwise it looks like the dimension is hit-scope:
For instance:
ga('set', 'dimension3', 'Internal');
ga('send', 'event', 'Contract Change', 'click', 'Landing Page', 10);
ga('send', 'event', 'Other event with dimension', 'foo', 'bar', 20);

Related

Google Analytics 4: custom dimensions in gtag.js

I am trying to send some custom dimension together with my event.
This is my code:
gtag('config', 'G-XXXXXXXXXX', {
'custom_map': { 'dimension1': 'age' }
});
gtag('event', 'age_dimension', {
'event_category': category,
'event_label': action,
'value': data(),
'nonInteraction': 1,
'age': '666'
});
This is my dimension on UI:
I am sending my events together with my custom dimension, on UI I see all my data as parameters in the event,
but when I try to make something with my dimension GA just says me that there is no data for this dimension.
I don't know, probably I configured the map incorrectly or probably something wrong with the dimension which I created.
So the question, is my configuration and dimension correct? and if no, what is wrong? thanks!

Sending more GTM event data without duplicating Tags

I collect video tracking data to data layer and I would like send all the data as a part of the same event.
dataLayer.push({
'event': 'video',
'EventCategory': 'HTML5 Video',
'EventAction': VideoProgressWatched,
'EventLabel': videoLink,
'EventContributor': videoContributor,
'EventVideoCategory': videoCategory,
'EventVideoDuration': videoDuration
});
I tried splitting this into few different Tags that are triggered by the same triggers.
Tag 1:
Event Category: {{EventCategory}},
Event Action: {{EventAction}},
Event Label: {{EventLabel}}
Tag 2:
Event Category: {{EventCategory}},
Event Action: {{EventAction}},
Event Label: {{EventContributor}}
Tag 3:
Event Category: {{EventCategory}},
Event Action: {{EventAction}},
Event Label: {{EventVideoCategory}}
But I somehow doubt this is the right way to do it. What would be the correct way of doing this?
Consider sending the additional data as hit-scoped custom dimensions, then on the GA side defining those Custom dimensions as things like "Event Contributor" etc.

Google analytics enhanced ecommerce: order of checkout steps

I really cant find the answer in official Google documentation:
Is it acceptable to send ec:checkout_option for previous step and the next checkout step on one event?
What for:
If user have choosen an delivery method and pressed "continue" - I want to set checkout_option for step 2 and checkout-action for step 3 and send them in one event;
ga('ec:setAction', 'checkout_option', {'step': 2,'option':paymentName});
ga('ec:setAction', 'checkout', {'step': 3});
ga('send', 'event', 'Checkout')
If 'yes' - then next question:
Is it acceptable to send ec:checkout_option for previous step after the next checkout step event has been set?
What for:
Nearly the same case, but do I really must keep an order of those ec:setAction calls before sending a beacon? In other words, could I apply such calls sequence?
ga('ec:setAction', 'checkout', {'step': 3});
ga('ec:setAction', 'checkout_option', {'step': 2,'option':paymentName});
ga('send', 'event', 'Checkout')
Go deeper: Is it acceptable to send ec:checkout_option for previous step after the next checkout step event has been SENT?
What for?
user chenged his mind and choosen another option (lets imagine that all checkout is in one step and user can change earlier data without explicit returning to previous step.
ga('ec:setAction', 'checkout', {'step': 3});
ga('send', 'event', 'Checkout')
ga('ec:setAction', 'checkout_option', {'step': 2,'option':paymentName});
ga('send', 'event', 'Checkout')
Thanks in advance :)
Yes, you can do that. You can send the check_option for previous step after the next checkout step event has been set. Before ga send the events, they collect all ec:setAction and then send all the information at same time.
Yes, the actions order has no relevace.
If the checkout is in one page and the user can change some previous data, you can send only the checkout_option with the new option value and google will update the previous value.
I have a checkout process all in one page and it has 8 steps. I recommend to write separated functions" one for checkout and one for checkout_option and call it when you need. It would be something like:
function gaCheckout(step) {
ga('ec:setAction', 'checkout', {'step': step});
ga('send', 'event', 'checkout', 'dummy', 'dummy');
}
function gaCheckoutOption(step, value) {
ga('ec:setAction', 'checkout_option', {'step': step, 'option': value});
ga('send', 'event', 'checkout_option', 'dummy', 'dummy');
}
When the user selects an option you call the gaCheckoutOption and when clicks the continue button the gaCheckout is called. If the user scrolls up and change some previous step value, only the gaCheckoutOption is needed.

Getting events to be dependent on the completion of another event

A part of my site generates a handful of events from the same action. The default for Google Analytics is to have the events run independently. However, one of the events needs to happen last. Is there a way to force an order of event completion or at the least have an event dependent on another event?
I have found no documentation on the subject. Thanks in advance for the help.
Could you do a simple flag?
Event #1
var flag = false;
function eventOne(){
ga('send', 'event', 'Event Chain', 'Trigger', 'First Event');
flag = true;
}
function eventTwo(){
if (flag) {
ga('send', 'event', 'Event Chain', 'Trigger', 'Last Event');
}
}
Google Universal Analytics has hit callbacks , functions that are called when a tracking call is completed. You can at least try to nest event tracking calls within event hits
ga('send', {
'hitType': 'event', // Required.
'eventCategory': 'category', // Required.
'eventAction': 'action', // Required.
'eventLabel': 'label',
'hitCallback': function() {
ga('send', {
'hitType': 'event', // Required.
'eventCategory': 'category', // Required.
'eventAction': 'action 2', // Required.
'eventLabel': 'label 2'
});
}
});
Untested, but judging from the documentation I don't see why this wouldn' work.
There is no built-in way of doing that in Analytics. To implement this sort of behavior, you would have to design it yourself based on your requirements and/or application logic.
If you are implementing a website using JavaScript, you might be interested in using the q library, which could help you in creating and composing asynchronous promises in JavaScript.
Without going into too many details (because it might be out of the scope of your question), that could yield something like:
Q.all([handleEventOne(), handlerEventTwo()]) // Wait for 2 handlers to complete
.done(function (values) { // Execute this callback once the 2 handlers have completed
ga('send', 'event', 'Event Chain', 'Trigger', 'Last Event');
});

Hard code GA event with GTM

I want to be able to hard code some GA event such as below. I'm using GTM and I understand its not possible in this way. Is there a way round this?
ga('send', 'event', 'Mobile', 'Original', 'App');
This is a problem because GTM creates a randomly named tracker instead of the default tracker (t0). You can either use the set fields method on the "name" field to set the tracker name to a known values (i.e. "myTracker") and adapt your calls accordingly:
ga('myTracker.send', 'event', 'Mobile', 'Original', 'App');
Or you can use the ge function to send your event tracking calls to all trackers in the page:
ga(function() {
var trackers = ga.getAll();
for (var i=0; i<trackers.length; ++i) {
var tracker = trackers[i];
tracker.send('event', 'Mobile', 'Original', 'App');
}
});
which will probably create more headache than it's worth. However it is unlikely that there is a scenario that can't be covered without a need to hardcode events - the proper way would be to push a custom GTM event (and your GA event data) to the dataLayer and trigger an GA event tracking call from there.
So for hardcoding event, just don't.
To implement ga event use this syntax wit your onclick.
replace ga('send', 'event', 'Mobile', 'Original', 'App');
with this and it will work:
gtag('event', 'click', {'event_category' : 'Mobile',
'event_action' : 'Original', 'event_label' : 'App'});

Resources