2

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.

  • Try to install Google Tag Assistant so that you can see the hit in the console. Also make sure you don't have a filter that blocks out your hits. If you have the UA snippet on your page set up correctly, then the 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. – nyuen Feb 9 '17 at 23:36
  • Thanks for the top about Google Tag Assistant; installed that and it's catching the event and all the info looks correct and don't see any filters. However I still am not seeing the event show up on GA. Do you have to setup the category or action names in GA at all for them to work or can you basically just pass them straight away however you like? – Brett Feb 10 '17 at 18:40
  • It will take up to 24 hours for data to appear in your reports, but you should be able to see them in real-time. What your are sending in should be fine, wrt the Cat and Act and Label. I think if the typeof value is undefined, then just set it as undefined (the value, not the text). – nyuen Feb 10 '17 at 19:32
  • @nyuen Yeah I know they won't show in the Events section for awhile, but yeah, not seeing them in real time either. – Brett Feb 10 '17 at 19:48
  • Would you be able to share your site and point me to the event? – nyuen Feb 10 '17 at 20:26
1

Site is based on WordPress and turns out it had an old plugin installed that was using the former version of Google Analytics to send events itself; as soon as I deactivated that plugin events started showing up.

The aforementioned plugin is: Analytics Reduce Bounce Rate

I also commented out this line (as suggested by @nyuen):

value = typeof value !== 'undefined' ? value : '';

Not sure if it had any effect, but eventValue is supposed to be of integer type so setting it to blank probably wasn't helping either.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.