googleanalytics / autotrack

Automatic and enhanced Google Analytics tracking for common user interactions on the web.
Other
4.92k stars 564 forks source link

OutboundLinkTracker: Renaming the eventCategory #206

Open EW0JY opened 7 years ago

EW0JY commented 7 years ago

According to the documentation, the default eventCagory "Outbound Link" can be renamed by customizing the options, which I did like so:

ga('require', 'outboundLinkTracker', { events: ['click', 'auxclick'], eventCategory: 'Affiliate Link', ...

However, within the Analytics reports, the event category still only shows "Outbound Link", no sign of the new category name.

What am I missing?

Thanks!

chrisblakley commented 7 years ago

I actually ran into a similar issue a little while back using the Impression Tracker. Tried to change the category, but no luck:

//...inside of a small loop
ga('impressionTracker:observeElements', [{
    'id': jQuery(this).attr('id'),
    'threshold': 0.25,
    'fieldsObj': {
        'eventCategory': 'Contact Form',
    }
}]);

The events are showing up in Google Analytics, but they appear under the "Viewport" category. Not a big deal for me, but thought I'd mention it since I saw this issue.

Edit: Modified the code to use the fieldsObj, but it still appears under Viewport in GA. From what I can tell, it doesn't look like programmatic implementations support the fieldsObj.

To get this to work, I just set up a task to check for my specific element and renamed the event category right there before the payload was sent to GA:

ga(function(tracker){
    tracker.set('buildHitTask', function(model){        
        if ( model.get('hitType') === 'event' && model.get('eventAction') === 'impression' && model.get('eventLabel').indexOf('wpcf7') > -1 ){ //Checking for both hitType and eventAction is probably redundant
            model.set('eventCategory', 'Contact Form', true);
        }
    }
}
philipwalton commented 7 years ago

To modify any field values, you can use the fieldsObj option. E.g. in your case you'd do this:

ga('require', 'outboundLinkTracker', {
  events: ['click', 'auxclick'],
  fieldsObj: {
    eventCategory: 'Affiliate Link',
  },
});

I don't think including eventCategory directly on the config obj is mentioned anywhere in the documentation, but if it is can you show me where? That's definitely not supported.

EW0JY commented 7 years ago

If I wanted to use this newly available event "Outbound Link" to calculate something like "Outbound Link Clicks / User" or "Outbound Link Clicks / Unique Page Views", would I need to set up a custom metric in order to be able to do that?

philipwalton commented 7 years ago

@EW0JY "Outbound Link Clicks / User" would be a calculated metric, and (as I mentioned in #205) those tend to work better with custom metrics (though that's not required). The reason they work better with custom metrics is there's no filtering built in to the definition.

For example, if you were going to use a calculated metric to get outbound link clicks per user without making a custom metric, the formula would have to be {{ Total Events / Users }} and you probably see how that could be problematic if your report contained any events other than just outbound link clicks.

If you wanted to track outbound link clicks with a custom metric, you'd have to:

  1. Create the metric in GA
  2. Update the tracking code to send a count for that metric
ga('require', 'outboundLinkTracker', {
  events: ['click', 'auxclick'],
  fieldsObj: {
    metric4: 1, // Sends a value of 1 to the metric at index 4.
  },
});
EW0JY commented 7 years ago

Awesome, setting that up via the fieldsObj, I would not have known how to do that. The custom metric I did set up and tomorrow the custom report will tell me if I got it right :)...

Thanks again so much, I really appreciate your willingness to share and help!