Tracking code comes after functionality
Events in Google Analytics (or Mixpanel, etc) are a very useful way of tracking very specific usage within your application.
When triggering them, however, it’s imperative that the tracking code comes after functionality.
A lot of users, especially more technically savvy ones, run some equivalent of Adblock. Features will break if the code that’s supposed to trigger an event comes before functionality.
Adblockers exclude scripts completely. As a result, not only are events not sent but they actually cause exceptions. This then causes the functional code to not be executed.
So, this is broken:
But this is fine:
Uber’s website fails to do this. I tried to log in using my Google Account but it kept failing. I checked the console to see if there were any clues:
It seems that tracking is being triggered first. And since it throws an exception the logging in doesn’t function then.
Another service I use has found a creative way of fixing that.
Get in touch
Or send me feedback. It will take less than 20 seconds.