Update riveted.js with support for multiple simultaneous trackers
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:
-
gaTrackernow allows both the old string format for a single tracker and array format to pass several trackers -
universalSendCommandswitches to arrayuniversalSeldCommandsso it can contain commands for multiple trackers -
initnow processesgaTrackerbased 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). -
sendUserTimingandsendEventnow loop through the commands inuniversalSendCommandsarray 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).