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');
});
Related
Couldn't find direct migration tutorial or clear description on https://developers.google.com/gtagjs/reference.
Have limitation to analitic portal access and can't properly to test it.
Need to change next ga scripts under my SPA app to gtag.
1. ga('set', 'page', url)
2. ga('send', 'pageview')
3. ga('send', 'event', 'button-interest-request', 'submit-request')
I didn't find how should works set on gtag.
I supposed should be something like next strings for strings 1 and 2
gtag('event', 'page_view', { page_location: url })
And next for string 3
gtag('event', 'button-interest-request', {
'value': 'submit-request'
});
Am I right?
You have to define at least event category and event action in gtag with this syntax:
gtag('event', <action>, {
'event_category': <category>,
'value': <value>
});
In your situation, like this:
gtag('event', 'submit-request', {
'event_category': 'button-interest-request'
});
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);
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.
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'});
Can I do like this
var eLabel = $('#example_placeholder').html();
and put eLabel into this
ga('send', {
'hitType': 'event', // Required.
'eventCategory': 'cash', // Required. privilege acquisition creditcard installment
'eventAction': 'ClickView', // Required.
'eventLabel': eLabel
});
Yes, you can do that. You can shorten things like this as well:
ga('send','event','cash','ClickView',$('#example_placeholder').html());