segmentio/analytics.js-core

Use beacons in trackLinks for supporting browsers

Closed this issue · 3 comments

Currently trackLinks adds a 300ms timeout to links to allow enough time for the analytics to fire, but beacons solves this issue without the performance overhead + all modern browsers now support it (https://caniuse.com/#search=beacon)

I'd love to see beacon support added (with the 300ms timeout left for unsupporting browsers).

Additionally, what do you guys think about adding a new trackLink function that can be added directly as an onclick to a link (rather than requiring a selector)? I feel like this API would be nicer for devs building out component-architected UI's.

So I've been digging around through the analytics source-code and it looks like this might be trickier than I originally thought, since I think trackLinks is actually just an abstraction around emitting "track" events - which are implemented by specific integrations, and could be black boxes of sync logic.

Has anyone looked into this before?

Hi Alex,

I do think it would be tricky due to our integrations. However, we're looking to rethink how we do analytics.js to improve it's performance later this year

That's great to hear - looking forward to updates