2 comments

[ 0.22 ms ] story [ 12.8 ms ] thread
Nice post, Bradley. I think you might be the first one doing A/B testing with Plausible :)

Just a heads up, I think registering a plausible event in the `onclick` handler could introduce a race condition. If the page navigates and unloads before the request to Plausible is sent, you might miss the click in analytics.

The code here is a bit obtuse, but for our Outbound Link tracking feature we set a 150ms delay for navigation [1]. It should give enough time to complete the request to Plausible.

I am planning to tackle this limitation by seeing if we can implement custom event tracking with `navigator.sendBeacon` instead.

1. https://github.com/plausible/analytics/blob/master/tracker/s...

Ouch, you're right. Thanks for the heads up!

Indeed, on fast connections the request to Plausible gets cancelled before it can be completed. I've updated my code to use that `setTimeout` trick.

`navigator.sendBeacon` support would be amazing! I really like how simple Plausible has been to set up (having never really used analytics before) so removing even more pitfalls/hurdles would be cool