Search code examples
google-analyticsvimeo

Can I route GA events from default tracker to named tracker? (OR make Vimeo use my named tracker?)


Context

I'm using the Vimeo analytics script to integrate video events with Google Analytics. The page I'm working on needs to route all GA events to a named tracker as created by...

ga('create', 'UA-XXXXXX-1', 'auto', { name: 'MyTracker' })

All ga events on the page are then sent with...

ga('MyTracker.send', /* ... */)

That works, but...

The vimeo script doesn't include the MyTracker prefix for events. As Far as I can tell, there's no way to make it use a named tracker (I could be wrong?). So, events look like...

ga("send", "event", "Video", "load", "My Super Awesome Video")

which gives this error (from GA debug):

Command ignored. Unknown target: undefined

Question

Is there a way to either...

  1. Make the Vimeo analytics script use the named tracker? OR
  2. Re-route these GA events from the default tracker to the named tracker?

Solution

  • Is there a way to either...

    Make the Vimeo analytics script use the named tracker? OR

    If you can't change the Vimeo analytics code then no: it will be harcoded with ga('send' thus pointing to the main tracker.

    Re-route these GA events from the default tracker to the named tracker?

    Yes using custom tasks. For instance using sendHitTask, something along those lines:

    ga('create', 'UA-XXXXX-Y', 'auto');
    
    ga(function(tracker) {
    
      // Grab a reference to the default sendHitTask function.
      var originalSendHitTask = tracker.get('sendHitTask');
    
      tracker.set('sendHitTask', function(model) {
        // Send data to other tracker
        ga('MyTracker.send', /* ... */)
    
        // Comment below line if you don't want to send
        // data to original tracker
        originalSendHitTask(model);
    
      });
    });