Hi there!
I have a strange situation. I am using sp.js (v2.7.0) for tracking page_views, page_pings and a few self-describing events. My site is also loading an external js plugin called keywee.js (that basically scans through the content). This plugin is also making its own call to sp.js since it also uses sp.js (v2.4.3) for its own internal tracking of our websites. So we now have 2 instances of the sp.js tracker (v2.7 and v.2.4.3) loading on our site.
Page loads and pings fire properly. However, when I try to fire the unstruct event (on a mouseclick), the other sp.js throws an error.
Uncaught TypeError: Cannot read property 'apply' of undefined
at Object.u [as push] (http://dc8xl0ndzn2cb.cloudfront.net/sp.js:31:324)
....
for (x = 0; x < C.length; x++) {
C[x][A].apply(C[x], z)
}
....
The error above is referencing the spjs loaded through keywee inclusion and not my sp.min.js here. Even though I created the new tracker and snowplow in the head as async addition as per below:
<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","/mediav2/build/assets/js/sp.min.js","Sp"));
window.Sp('newTracker', 'scala', '<collector-url>', {
appId: '<web-id>',
platform: "web"
});
window.Sp('enableActivityTracking', 30, 10);
window.Sp('trackPageView');
</script>
The events thats thowing the error is structured as:
window.ihSp('trackSelfDescribingEvent', {
schema: 'iglu:com.site.iglu/site_event/jsonschema/1-0-0',
data: {
actionType: 'open',
shareUrl: encodeURI(this.data),
senderEmail: this.email
}
});
Its difficult to trace this error precisely but I was wondering if there’s a way to handle multiple sp.js loads for different trackers on the same page without conflicts like the above?
One thing I noted is that this error is not consistently reproducible. I happens on some page loads, which leads me to think it may be something related to load sequence (which js loads first?). But this is not clear…However once the error occurs, its breaks the js on the website completely.
Thanks very much!