Joined April 2013
·

Christopher Parker

Sr. JavaScript Web Developer at Fidelity Investments
·
Malden, MA
·
·
·

I faced this same problem (activations not reliably being recorded), but with a different analytics platform.

I ended up writing a promise-based wrapper around the tracking method. The promise resolves when the tracker image finishes loading.

Used sparingly, this solution provides a synchronous hook into the analytics-tracking workflow and eliminates the unreliable use of setTimeout().

(I also wrote a custom pub/sub implementation that detects when promises are used by subscribers in order to conditionally provide promises on all .publish() calls. This means any subscriber can transparently inject dependencies into the pub/sub lifecycle on an as-needed, even ad-hoc, basis. All analytics tracking is abstracted using events. So, if we want to redirect, but only after all of an event's subscribers have finished responding to the event, all we have to do is wrap the redirect in the event's .done() method.)

Achievements
50 Karma
0 Total ProTip Views