Skip to content

Comment on Ask HN: How can I trust Google Analytics?parent

Comments

Why not just use an event handler which sends the event to GA, and after that, follows your link? They provide a callback and everything...

   var outboundLink = function(url) {
      ga('send', 'event', 'button', 'click', {'hitCallback':
         function () {
            document.location = url;
         }
      });
   }

   <a href="#" onclick="outboundLink('https://www.foo.com'); return false;">Foo</a>
See: https://developers.google.com/analytics/devguides/collection...

You can also do

    ga('send', 'event', 'button', 'click', {transport: 'beacon'});
This will work even after you redirect to another page but only if the browser supports navigator.sendBeacon(). Currently not IE or Safari.

And now you have a website that feels slow to respond to link clicks.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.