$p("setContext")

$p("setContext"): (Object) -> undefined

📘

Simple Single Page Application

Simple Single Page Application refers to an SPA using PushState or hash based routing. If this describes your web site/app, then please refer to this documentation.

Current context refers to what contents the user is viewing. For example, if a user is viewing a video of id 12345, then current context is 12345. Since web implementation is the most common form of LiftIgniter implementation, the JS SDK uses separate API endpoint from the standard documented REST API.

JS SDK normally accepts content identifier as the url. But this may not make sense on a non-Simple Single Page Applications since reading the URL doesn't really tell us anything about the content the user is interacting with. You can modify the current context with:

$p("setContext",{id:"CONTENT_ID"})

Invoking this function modifies the ccu parameter of every subsequent events sent as the id you've declared in the CONTENT_ID. This parameter is the identifier our JS SDK endpoint expects as the default current context. Make sure that the function is used right after $p("init") for when the script first initializes and right before $p("resetPageview") so it could set the appropriate context before tracking new events.