Global Context not sent

Hello,

I’m integrating the JS tracker on my web site and i encounter difficulties with the addGlobalContext method.

For now, my implementation is quite simple :

<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","https://d1fc8wv8zag5ca.cloudfront.net/2.10.0/sp.js","snowplow"));

  window.snowplow("newTracker", "xxxx_tracker","//dev-snowplow.xxxxx.fr", {
    appId: 'xxxx_useraccount',
    discoverRootDomain: true,
    eventMethod: 'get',
    forceSecureTracker: true,
    respectDoNotTrack: true,                                              
  });

  window.snowplow('setDebug', true)
  window.snowplow('addGlobalContexts', [
    {
      "data": {
        "environment" : window._Y_.environment,
      }
    }
  ]);
  window.snowplow('enableActivityTracking', 30, 10);
  window.snowplow('trackPageView');
</script> 

I think i’m missing something here because neither in the request neither in metabase do i see my context sent. Do i really need a schema even if i don’t need to make filter on my context ? What am i doing wrong ?

Thank you very much for your help.

Hi Claire!

Your context JSON doesn’t look like Self-describing JSON - it needs to reference a schema, like so:

{
  schema: 'iglu:com.acme/user_context/jsonschema/1-0-0'
  data: {
    userid: ,
    name: 'john doe'
  }
}

I think the easiest thing to do is first send some events with custom contexts the ‘old way’, to get used to how they’re done, then use global context once you’ve done that successfully.

Best,

I didn’t have understood right the way that a schema was required in order to attached a global context. Thank you!

1 Like