I haven't done a lot of event tracking before, but I had a good read of how to do it and have implemented it with Universal Analytics, and here is the code used to send to GA:
function sendEventAction(category, action, label, value, non_interaction) {
value = typeof value !== 'undefined' ? value : '';
non_interaction = typeof non_interaction !== 'undefined' ? non_interaction : true;
ga('send', {
'hitType': 'event',
'eventCategory': category,
'eventAction': action,
'eventLabel': label,
'eventValue': value,
'nonInteraction': non_interaction
}
);
}
Example call:
sendEventAction('online-application-form', 'entered-word-tm', 'Word Trademark');
Looking at the developer console it seems to send the request, but nothing appears in the real time view.
What am I doing wrong here!? I read you can set Goals, but they are optional and hence I haven't set any up.
I am also wondering how google knows what account to credit the event to? As I said above I have universal analytics setup - does it get it from that? That script I believe is below the JS code that sends the event to GA however.
ga
object will be created based on the tracking ID, ie.ga('create', 'UA-XXX-Y')
. That's how GA knows which property to send hits to.typeof value
isundefined
, then just set it asundefined
(the value, not the text).