javascript tracker: which to use window.snowplow_name_here or snowplow_name_here

26 views
Skip to first unread message

Travis Devitt

unread,
Mar 31, 2016, 2:42:18 PM3/31/16
to Snowplow
I'm setting up the javascript tracker and the documentation at https://github.com/snowplow/snowplow/wiki/2-Specific-event-tracking-with-the-Javascript-tracker shows mixed syntax when it comes to the examples. 

For instance the following two syntaxes are being used interchangeably:

window.snowplow('trackPageView');

snowplow_name_here('trackPageView');

Which is the right syntax to use?

Thanks,
Travis





Ihor Tomilenko

unread,
Mar 31, 2016, 3:15:56 PM3/31/16
to Snowplow
Hi Travis,

It's up to you how you name your tracker. The name is defined in the snippet of code you embed into your HTML (see the highlighted parted at the end):

<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.5.1/sp.js","snowplow_name_here"));

....

Whatever name you give in the code above that's how you refer to your tracker. If you name it "snowplow" (in the snippet above in place of "snowplow_name_here") then you have to state snowplow('trackPageView');.

The "snowplow_name_here" (in the snippet I pasted above) just indicates that this is the (default) name of your tracker and it's up to you to either keep this name or change it to something else.

Regards,
Ihor

Travis Devitt

unread,
Mar 31, 2016, 4:03:51 PM3/31/16
to Snowplow
Thanks Ihor, but it's not the tracker name that is confusing me (I understand it can be whatever you want), it is the javascript reserved word prefix of "window" that is confusing. 

In some of the examples, window.trackername('xxxx') is used and in some other of the examples it's just trackername('xxxx')

Please advise

Ihor Tomilenko

unread,
Mar 31, 2016, 4:26:04 PM3/31/16
to Snowplow
Travis,

window is the default object the method is being called on. Either way (with or without window) should work.

Regards,
Ihor

Travis Devitt

unread,
Mar 31, 2016, 4:32:29 PM3/31/16
to Snowplow
Thanks!
Reply all
Reply to author
Forward
0 new messages