[FIXED] Javascript: Tracker namespace co already exists


#1

I’m using version 2.8.1 and I started getting this warning that stops the execution of the rest of the events related to the click.

Snowplow: Tracker namespace co already exists.
d.warn	@	sp.js:33
q	@	sp.js:29
s	@	sp.js:29

I’m tracking this using GTM (the code in window.snowplow is the same I was using before moving to GTM):

<!-- Snowplow event tracking -->
<script type="text/javascript">
;(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[];
p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments)
};p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1;
n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,"script","//d1fc8wv8zag5ca.cloudfront.net/2.8.1/sp.js","snowplow"));

window.snowplow('newTracker', 'co', '{{Snowplow Cloudfront Bucket}}', {
  appId: '{{Snowplow App ID}}',
  platform: 'web'
});
  
window.snowplow('trackUnstructEvent', {{event_json}});
</script>

All the event on my page are getting tacked by the same tag, since all of them are unstructured events. I based my solution on https://discourse.snowplowanalytics.com/t/firing-unstructured-events-custom-contexts-within-google-tag-manager/260.

As you can see co is the value set for the new tracker.

If you go to this page https://staging.chefsfeed.com/ and click on any of the buttons of the navbar you can see the warning on the console.

Normally this will log the event data and then take you to the correct page, now it logs the data, send the warning and stops there.

Any ideas?


#2

Hi @lsarni,

I suspect that this is happening because another tracking tag is already on the page.

Indeed when I use the Snowplow Inspector plugin (which was developed by our partners at Snowflake Analytics), I can see that there’s a self-describing event being sent with an undefined app_id.

If you change the namespace of the tracker you should be able to instantiate it, and if you change "snowplow" at the end of the initialisation script to something else (“sp” below), you can call the tracking methods for your tracker as opposed to the other ones.

;(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[];
p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments)
};p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1;
n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,"script","//d1fc8wv8zag5ca.cloudfront.net/2.8.1/sp.js","sp"));

window.sp('newTracker', 'namespace', '{{Snowplow Cloudfront Bucket}}', {
  appId: '{{Snowplow App ID}}',
  platform: 'web'
});

The other tracker may be another team, or it may be an old tag which was never removed.

I hope this helps.

Best,


#3

Thanks for adding the link to the debugger.

I figured out I was using the GTM Environments incorrectly and that’s why the app_id was undefined (I’m using a look up table based on the environment). But having fixed that I still get this error.

The tag on GTM has the code included on the original question and is configured to get trigger once per event. Does this mean that all that code gets executed on each event? This would explain why the namespace is already being used. When I had this set up on the website side this was only executed once per window.

Could this be the problem?

Update
That was indeed the problem I broke down the Tag into two tags:

<!-- Snowplow event tracking -->
<script type="text/javascript">
;(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[];
p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments)
};p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1;
n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,"script","//d1fc8wv8zag5ca.cloudfront.net/2.8.1/sp.js","snowplow"));

window.snowplow('newTracker', 'co', '{{Snowplow Cloudfront Bucket}}', {
  appId: '{{Snowplow App ID}}',
  platform: 'web'
});
</script>

<!-- Snowplow event tracking -->
<script type="text/javascript">
window.snowplow('trackUnstructEvent', {{event_json}});
</script>

Now I no longer get the warning since the first one only executes one per page.
But it still seems to stop the rest of the execution.

This is how I send the event:

if this.enableLogging
  this._logEvents(this.schema, data)
dataLayer.push
  'event': 'selfDescribingEvent'
  'event_json':
    schema: this.schema,
    data: data

It seems like it’s preventing the default click

FIXED
I was missing a return when sending the event. Now it’s fixed.

Thanks for your help pointing out the debugging tool!