riveted icon indicating copy to clipboard operation
riveted copied to clipboard

Update riveted.js with support for multiple simultaneous trackers

Open jerclarke opened this issue 7 years ago • 0 comments

The previous version supports multi-tracker setups with the gaTracker argument, which specifies a single tracker to which Riveted events will be sent. This is a bummer if you want several trackers to all receive the Riveted events so that they match (and since the data is useful everywhere).

This patch adds support for sending events to several trackers:

  • gaTracker now allows both the old string format for a single tracker and array format to pass several trackers
  • universalSendCommand switches to array universalSeldCommands so it can contain commands for multiple trackers
  • init now processes gaTracker based on whether it's an array, (build commands for each tracker in the array), a string (build the single command for that tracker) or empty (build a command for the default tracker).
  • sendUserTiming and sendEvent now loop through the commands in universalSendCommands array to send events for each registered tracker

Note that it also adds references to default tracker, which is a string used to indicate the main tracker that doesn't require a prefix for ga send commands. If you pass in multiple trackers via an array in gaTracker then you would use default to indicate that prefix-less tracker. We also made sure that if you pass in default as a string for a single tracker what happens is what you'd expect: The code for the prefix-less tracker is used.

As far as we know this update is back-compatible with previous versions. If gaTracker is empty or a string with a single tracker, Riveted will work the same as before!

Thanks for considering this PR! If it can't be merged, I hope it can help someone else having the same problem as us (wanting Riveted on both of our trackers).

jerclarke avatar Oct 04 '18 21:10 jerclarke