I need to use the custom ga('send')
function to send data that's triggered on a form submit, specifically through Marketo.
On web properties where GA is installed as a script tag, this works great. However, on one site I need to do this on, GA is installed as a tag through GTM. It's apparently a best practice.
Basically the code looks like this (for context):
form.onSuccess(function (values, url) {
console.log('success');
...
ga('send', 'event', {
eventCategory: 'form',
eventAction: 'submit',
eventLabel: 'Form Submit'
});
...
return false;
});
I did some research
How to send ga(...) events with Google Tag Manager?
Google Analytics Code Explanation
The premise is that I need to define the ga()
function in the first place - so I do that like so:
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', "UA-XXXXXXXX", 'auto');
form.onSuccess(function (values, url) {
console.log('success');
...
ga('send', 'event', {
eventCategory: 'form',
eventAction: 'submit',
eventLabel: 'Form Submit'
});
...
return false;
});
I can see the `console.log("success") and no errors are being thrown but I'm not seeing the form submission event being logged in GA.
Any ideas? How do I do custom events with a Google Tag Manager implementation of GA vs a script tag?