简体   繁体   中英

Google analytics tracking outbound events

I have setup outbound event tracking for Google analytics as per instructed by Google:

var trackOutboundLink = function(url) {
   ga('send', 'event', 'outbound', 'click', url, {
     'transport': 'beacon',
     'hitCallback': function(){document.location = url;}
   });
}

I am trying to determine if it is working properly eg if the event is being tracked.

When I view the click in my developer tools, it says the 'collect' request sent to google analytics was cancelled.

However, if I set the link to open in a new tab, the 'collect' request does not get cancelled.

I am wondering if it matters that collect was cancelled, eg even though my network tools are saying it was cancelled, was it really sent to google and my browser thinks it was cancelled because it did not register a response - which in this case we do not need we are redirecting away from the page anyway?

I know it is accessing 'hitcallback' as the code inside executes - so I assume this means the call back has happend as intended?

The reason I ask is because for iphone, I cant get the link to open in a new window, and I will to wait 1+ days to see if the iphone event is tracked

There is an "events" item in the realtime reports menu, so you do not have to wait.

As far as your transport method is concerned, according to this site mobile Safari does not support navigator.sendBeacon, so this setting will do nothing for that specific use case and simply fall back to image or xhr respectively. Since that requires a server response I would assume that your events are not being tracked if the request is cancelled. But do go and check the realtime report to be certain.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM