I was trying to enable global context in my javascript tacker with the below sample.
let user_context = {
schema: 'iglu:com.pathfactory/user_context/jsonschema/1-0-0',
data: {
userid: 1234,
name: 'john doe'
}
};
// if a global context has a conditional component (in this case, a schema rule set)
// our global context must be supplied as an array, where the first element is
// the conditional part and the context is the second element
let global_context = [
{accept: 'iglu:com.pathfactory/*/jsonschema/*'},
user_context
]
window.snowplow('addGlobalContexts', [global_context]);
I couldn’t see any thing in the tracker with snowplow plugin that data generated. infact it is not hitting the sp.js createglobalcontext method.
This looks correct though the addGlobalContexts method itself doesn’t fire an event - you’ll need something like a trackPageView. In this case you have a condition for the global context so you’ll require a trackSelfDescribingJson that fires a com.pathfactory/*/jsonschema/* event to attach the global contexts.
// if a global context has a conditional component (in this case, a schema rule set)
// our global context must be supplied as an array, where the first element is
// the conditional part and the context is the second element
let global_context = [
{accept: ‘iglu:com.pathfactory//jsonschema/’},
user_context
]
What event are you trying to figure with the global context? You’ve attached a global context but there’s no Javascript that then fires any events for the global contexts to get attached to.
Thanks for the feedback on the docs. I agree with you, some more examples of how Global Contexts can be used would definitely be helpful in there.
I’ll look to improve this area of the docs with the next release of the JS Tracker.
Also, we have a new docs site now that is often more up to date than our GitHub wiki (which we’re in the process of migrating away from). Check it out here: https://docs.snowplowanalytics.com/