Snowplow Javascript Tracker | Multiple Collector in JS Tracker

Hi All,
I have added one more collector to the JS tracker, but snowplow tracker is behaving strange.
What it is doing,
For example if three events are meant for each collector, what it is doing after first event all events are going to recently second collector.

Events Collector
Event 1 Collector 1
Event 1 Collector 2
Event 2 Collector 2
Event 2 Collector 2
Event 3 Collector 2
Event 3 Collector 2

did anybody faced this kind of issue, while adding one more collector to existing tracker?

Can you share the code that you have used to instrument and initialise? The main thing you want to ensure is that each tracker you initialise has it’s own unique namespace.

for (var ci=0; ci<collectors.length; ci++) {
    var cname = namespace + '_' + ci;
    var config = { 
        appId: params.siteId,
        discoverRootDomain: true,
        cookieName: "sp",
        forceSecureTracker : true
    };    
    window.snowplow('newTracker', cname, collectors[ci], config); 
}

That looks ok to me. What version of the tracker are you using and how are you calling the track... methods, could you share an example trackPageView or similar?

trackerVersion : 2.9.0

below is example for PageView :

window.snowplow(‘trackPageView:’+ namespace.join(‘;’), null, data);

There is observation, i want to share:
we have a main collector (C1) which is of https type,
Earlier,
when C2 collector was of http type, it was working smooth.
but when C2 collector changed to https type, this error came up.

I’ve certainly never seen this happen before. One thing to perhaps check, are your network requests all succeeding in your browser? I’m curious if one is failing (due to https or something) and then maybe it’s retrying but to the wrong collector (that’d be a bug but 2.9.0 is rather old now).

I’d suggest trying 2.18.2. You could quickly try it from jsDelivr: https://cdn.jsdelivr.net/gh/snowplow/sp-js-assets@2.18.2/sp.js

Also, is the namespace array in your tracking example 100% the same values as cname you’ve used in the newTracker calls? I ask as cname is a concatenation of three strings so it looks like some potential for a mismatch there.

  1. Yes All Networks are successful, collector end points are working fine.

  2. let me try this version
    https://cdn.jsdelivr.net/gh/snowplow/sp-js-assets@2.18.2/sp.js

  3. No there is no mismatch, in cnames

Could you check your localstorage queue names? You should have a queue for each tracker namespace you’ve created.

I’m a bit baffled as to why you’re seeing this behaviour if I’m honest, I think the http to https switch is a red herring as that shouldn’t have any impact if you aren’t seeing any failing network requests (to be honest, even if you were the tracker shouldn’t be sending events to the wrong collector).

I’m thinking it might be worth removing some of the complexity from your tracker set up just to rule out any programming errors.

    var config = { 
        appId: params.siteId,
        discoverRootDomain: true,
        cookieName: "sp",
        forceSecureTracker : true
    };    
    window.snowplow('newTracker', 'snow_1', 'https://mycollector1.mydomain.com', config);
    window.snowplow('newTracker', 'snow_2', 'https://mycollector2.mydomain.com', config);
    window.snowplow('trackPageView:snow_1;snow_2');
    window.snowplow('trackPageView:snow_1;snow_2');
    window.snowplow('trackPageView:snow_1;snow_2');

I’m curious if this correctly sends three page views to both collectors as you’d expect or not? Switch out the collector URLs for your collectors.

1 Like