Sending multiple site ids with matomo-tracker

Hi there,

I’d like to track multiple site ids similarly to how it’s described here but using matomo-tracker. I can’t see anything in the docs or the source code that indicates that this is currently possible, but perhaps I’m missing something.

Any advice is appreciated.

Hi @dave.cooper
I think you could create a wrapper and call it:

var MatomoTracker = require('matomo-tracker');
 
// Initialize with your site ID and Matomo URL
var matomo1 = new MatomoTracker(1, 'http://mywebsite.com/matomo.php');
var matomo2 = new MatomoTracker(2, 'http://anotherwebsite.com/matomo.php'); (or use some array of matomos)

 
// Track a request URL:
// Either as a simple string or with further options…
function track(obj) {
 matomo1.track(obj);
 matomo2.track(obj);
 // or map on the matomos array...
}
 
// … or trackBulk:
function trackBulk(events) {
  matomo1.trackBulk(events, (resData) => {
    // done.
  })
  matomo2.trackBulk(events, (resData) => {
    // done.
  })
  // or map on the matomos array...
}

(not tested)

Also, there is a ticket (probably made by you?) about this new feature request:

Hey Philippe - that was indeed me that created that on GitHub :slight_smile:

I’ll take a look at our codebase and see if we could use a solution similar to what you’ve provided. I’ll get back to you when I do either way to let you know how I went.

-Dave

1 Like