I'm trying to send an event to Google Analytics after a user is registered and before he's redirected. I'm using Google Tag Manager and universal js.
First, I was trying to use the dataLayer object, as described here: developers.google
Here's what my function looked like:
//Registering new user via ajax
$.ajax('/register/', {
success: function() {
//Pushing event to dataLayer
dataLayer.push({
'Category': 'Registration Process',
'event': 'Registration Submit Btn'
});
//Logging in new user and redirecting the page with a timeout
setTimeout(function(){
loginAction();
}, 500)
}
})
The trouble is that I was receiving just about 25% of all events, all others are lost. I don't know if and when events are actually sent to Google after adding objects to the dataLayer, and I think 75% of events were not send at all.
Now I'm trying to implement another approach:
//Registering new user via ajax
$.ajax('/register/', {
success: function() {
//Sending event through ga('send')
parent.ga('send', 'event', 'Registration Process', 'Registration Submit Btn');
//Logging in new user and redirecting the page with a timeout
setTimeout(function(){
loginAction();
}, 500)
}
})
But ga('send')
does not have any callback function again!
How do I make sure that an event was actually sent to Google, using the dataLayer or ga('send')?