{"_id":"5728f716f9a3e40e00fef82f","githubsync":"","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"},"parentDoc":null,"project":"5668fab608f90021008e882f","user":"5668fa9755e4b32100935d41","__v":23,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-05-03T19:08:06.923Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":true,"order":0,"body":"JavaScript SDK is loaded through our snippet, and is available on the global context (window) under the name you assign on code snippet:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<script type=\\\"text/javascript\\\">\\nif (typeof $igniter_var === 'undefined') {\\n// Ensures that our client code is updated.\\n(function(w,d,s,p,v,e,r) {w.$ps = (w.performance && w.performance.now && typeof(w.performance.now) == \\\"function\\\") ? w.performance.now() : undefined;w['$igniter_var']=v;w[v]=w[v]||function(){(w[v].q=w[v].q||[]).push(\\narguments)};w[v].l=1*new Date();e=d.createElement(s),r=d.getElementsByTagName(s)[0];e.async=1;\\ne.src=p+'?ts='+(+new Date()/3600000|0);\\nr.parentNode.insertBefore(e,r)})(window,document,'script','//cdn.petametrics.com/{JAVASCRIPT_KEY}.js','$p');\\n// Don't forget to REPLACE JAVASCRIPT_KEY for cdn url.\\n\\n$p(\\\"init\\\", {JAVASCRIPT_KEY}); // REPLACE JAVASCRIPT_KEY\\n$p(\\\"send\\\", \\\"pageview\\\");\\n}\\n</script>\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\nAs you see on line 6,\n\n`(window,document,'script','//cdn.petametrics.com/{JAVASCRIPT_KEY}.js','$p')`\n\nThe last argument defines the namespace in which our SDK is accessible through. We set it to `$p` by default but you may change it to `$li` or any other form you're comfortable with in case `$p` is already taken for you.\n\n`$p` functions can be invoked by passing in the string that specifies a function. This is followed by an argument that's specific to the function, and then an options object where you have the option of defining a callback or certain configurations.\n\nFor example, line 9 shows our init function, with the Javascript Key passed in as the second argument. But you can also pass in an optional options object as the third argument that configures our script.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Single Page Application Integration\"\n}\n[/block]\nOn a standard web flow there is a predictable site navigation procedure (request a new page, loads the page, and etc). However, Single Page Applications are usually like standard Apps in that you load it once and have its state changed in response to user's actions.\n\nMost of Single Page Application Integration is just disabling automated activities that our JavaScript SDK assumes from a standard web flow such as pageview and cookie update, and manually handling those according to how you define user flow on your app.","excerpt":"","slug":"sdk-overview","type":"basic","title":"SDK Overview"}
JavaScript SDK is loaded through our snippet, and is available on the global context (window) under the name you assign on code snippet: [block:code] { "codes": [ { "code": "<script type=\"text/javascript\">\nif (typeof $igniter_var === 'undefined') {\n// Ensures that our client code is updated.\n(function(w,d,s,p,v,e,r) {w.$ps = (w.performance && w.performance.now && typeof(w.performance.now) == \"function\") ? w.performance.now() : undefined;w['$igniter_var']=v;w[v]=w[v]||function(){(w[v].q=w[v].q||[]).push(\narguments)};w[v].l=1*new Date();e=d.createElement(s),r=d.getElementsByTagName(s)[0];e.async=1;\ne.src=p+'?ts='+(+new Date()/3600000|0);\nr.parentNode.insertBefore(e,r)})(window,document,'script','//cdn.petametrics.com/{JAVASCRIPT_KEY}.js','$p');\n// Don't forget to REPLACE JAVASCRIPT_KEY for cdn url.\n\n$p(\"init\", {JAVASCRIPT_KEY}); // REPLACE JAVASCRIPT_KEY\n$p(\"send\", \"pageview\");\n}\n</script>", "language": "html" } ] } [/block] As you see on line 6, `(window,document,'script','//cdn.petametrics.com/{JAVASCRIPT_KEY}.js','$p')` The last argument defines the namespace in which our SDK is accessible through. We set it to `$p` by default but you may change it to `$li` or any other form you're comfortable with in case `$p` is already taken for you. `$p` functions can be invoked by passing in the string that specifies a function. This is followed by an argument that's specific to the function, and then an options object where you have the option of defining a callback or certain configurations. For example, line 9 shows our init function, with the Javascript Key passed in as the second argument. But you can also pass in an optional options object as the third argument that configures our script. [block:api-header] { "type": "basic", "title": "Single Page Application Integration" } [/block] On a standard web flow there is a predictable site navigation procedure (request a new page, loads the page, and etc). However, Single Page Applications are usually like standard Apps in that you load it once and have its state changed in response to user's actions. Most of Single Page Application Integration is just disabling automated activities that our JavaScript SDK assumes from a standard web flow such as pageview and cookie update, and manually handling those according to how you define user flow on your app.