{"_id":"5743a68a583f470e000a789e","user":"5668fa9755e4b32100935d41","parentDoc":null,"project":"5668fab608f90021008e882f","version":{"_id":"5668fab608f90021008e8832","__v":19,"project":"5668fab608f90021008e882f","createdAt":"2015-12-10T04:08:22.769Z","releaseDate":"2015-12-10T04:08:22.769Z","categories":["5668fab708f90021008e8833","569740f124490c3700170a64","569742b58560a60d00e2c25d","569742bd0b09a41900b2446c","569742cd69393517000c82b3","569742f459a6692d003fad8f","569743020b09a41900b2446d","5697430b69393517000c82b5","56a17776470ae00d00c30642","56a2c48a831e2a0d0069b1ad","56b535757bccae0d00e9a1cd","56e1ff6aa49fdc0e005746b5","57e1c88115bf6522002a5e4e","57fa65275ba65a17008b988f","57fbeea34002550e004c032e","58474584889b6c2d00fb86e9","58475dcc64157f0f002f1907","587e7b5158666c2700965d4e","58a349fc30852819007ba083"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.18.0","version":"1.18"},"category":{"_id":"569743020b09a41900b2446d","__v":3,"pages":["56975be30b09a41900b24494","56a15cfd470ae00d00c3061f","56e356004dc30f0e0051b3ed"],"project":"5668fab608f90021008e882f","version":"5668fab608f90021008e8832","sync":{"url":"","isSync":false},"reference":true,"createdAt":"2016-01-14T06:41:06.893Z","from_sync":false,"order":2,"slug":"javascript-sdk","title":"JavaScript SDK"},"__v":12,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-05-24T00:55:38.060Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":true,"order":3,"body":"`$p(\"setContext\"): (Object) -> undefined`\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"`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](https://liftigniter.readme.io/docs/push-state-based-single-page-application).\",\n  \"title\": \"Simple Single Page Application\"\n}\n[/block]\n`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.\n\nJS 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:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$p(\\\"setContext\\\",{id:\\\"CONTENT_ID\\\"})\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nInvoking 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.","excerpt":"","slug":"psetcontext","type":"fn","title":"$p(\"setContext\")"}
`$p("setContext"): (Object) -> undefined` [block:callout] { "type": "info", "body": "`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](https://liftigniter.readme.io/docs/push-state-based-single-page-application).", "title": "Simple Single Page Application" } [/block] `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: [block:code] { "codes": [ { "code": "$p(\"setContext\",{id:\"CONTENT_ID\"})", "language": "javascript" } ] } [/block] 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.