{"_id":"5728f6f80388c70e00f3d87b","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"},"__v":37,"githubsync":"","parentDoc":null,"project":"5668fab608f90021008e882f","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"},"user":"5668fa9755e4b32100935d41","updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-05-03T19:07:36.095Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":true,"order":2,"body":"`$p(\"init\"): (String, Object) -> undefined`\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Technical documentation\",\n  \"body\": \"This is technical documentation for the init function. It is used as part of the Javascript snippet you install when [Integrating LiftIgniter](doc:integrating-liftigniter).\"\n}\n[/block]\nVarious default settings of our script can be tweaked by specifying the config object.\n\nTo give you a practical sense of what it does, let's say that you want to disable the automatic inventory scraping of our script when the page loads:\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\\nvar customConfig = {\\n\\tinventory: {\\n  \\tcollect: false\\n  }\\n}\\n\\n$p(\\\"init\\\", {JAVASCRIPT_KEY}, {config: customConfig}); // REPLACE JAVASCRIPT_KEY\\n$p(\\\"send\\\", \\\"pageview\\\");\\n}\\n</script>\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nYou can set the option object's `config.inventory.collect = false` to disable automatic scraping that occurs when our script is initialized.\n\n`config` is a global state for our tracker that has two nested objects `inventory` and `sdk`. `inventory` defines the settings for functions related to scraping the data on page, and `sdk` defines settings for functions related to the SDK. Remaining key-value pairs within the `config` object sets our JS SDK's for other behaviors:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// General structure of the config variable\\nvar config = {\\n  inventory: {INVENTORY_OPTION: VALUE_A},\\n  sdk: {SDK_OPTION: VALUE_B},\\n  CONFIG_OPTION: VALUE_C\\n  ...\\n}\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nHere are the configurable options and values for `inventory` object:\n[block:parameters]\n{\n  \"data\": {\n    \"0-0\": \"collect\",\n    \"h-0\": \"Name\",\n    \"h-1\": \"Type (Default)\",\n    \"0-1\": \"Boolean (true)\",\n    \"h-2\": \"Description\",\n    \"0-2\": \"If true, then inventory collection function runs every time $p(\\\"init\\\") is invoked.\\n\\nAlso, setting this to false enables $p(\\\"sendItem\\\") function.\",\n    \"1-0\": \"version\",\n    \"1-1\": \"Number (undefined)\",\n    \"1-2\": \"Specifies the inventory version. If the inventory version is specified, only inventories with version higher than or equal to value specified in client will be returned as a recommendation or scraped from our end.\",\n    \"2-0\": \"collectJSON\",\n    \"2-1\": \"Boolean (true)\",\n    \"2-2\": \"If true, then inventory collection parses the text content of liftigniter-metadata DOM, and merges the JSON content with item information to be sent over to LiftIgniter.\",\n    \"3-0\": \"collectOpenGraph\",\n    \"3-1\": \"Boolean (true)\",\n    \"3-2\": \"If true, then inventory collection scrapes data from OpenGraph features available on the page.\",\n    \"4-0\": \"collectOpenGraphOnly\",\n    \"4-1\": \"Boolean (true)\",\n    \"4-2\": \"If true, then the script collects only pages that have all the mandatory graph features.\",\n    \"6-0\": \"mandatoryFeatures\",\n    \"6-1\": \"Array[String] ([\\\"title\\\", \\\"url\\\"])\",\n    \"6-2\": \"List of features that must exist for the script to send page/item to LiftIgniter as a recommendable item. On a default setting, the mandatory features are \\\"title\\\" and \\\"url\\\".\",\n    \"7-0\": \"mandatoryOpenGraphFeatures\",\n    \"7-1\": \"Array[String] ([\\\"title\\\",\\\"url\\\",\\\"type\\\"])\",\n    \"7-2\": \"List of Open Graph features that must exist for the script to send page/item to LiftIgniter as a recommendable item. On a default setting, the mandatory features are \\\"title\\\", \\\"type\\\", and \\\"url\\\".\",\n    \"8-0\": \"features\",\n    \"8-1\": \"Array[Object] (undefined)\",\n    \"8-2\": \"List of features on page that you want our script to scrape. The documentation on feature object is defined below. You can reference details of this property [here](https://liftigniter.readme.io/docs/configuring-what-to-scrape).\",\n    \"9-0\": \"filters\",\n    \"9-1\": \"Array[Object] ([{name:\\\"noIndex\\\", value: \\\"true\\\"}])\",\n    \"10-0\": \"itemRegex\",\n    \"10-1\": \"JS Regular Expression (undefined)\",\n    \"10-2\": \"Regular expression that matches the `url` or `id` of content on page. If the `url` or `id` matches the regular expression provided here, then it will pass the check to be sent over to LiftIgniter.\",\n    \"9-2\": \"List of filters for inventory scraping. If the script scrapes a field with identifier `name` with value set to `value`, then the script won't scrape the page.\",\n    \"11-0\": \"excludeRegex\",\n    \"11-1\": \"JS Regular Expression (undefined)\",\n    \"11-2\": \"If the `url` or `id` matches the regular expression provided here, then it will not be sent over to LiftIgniter.\",\n    \"12-0\": \"extensionOff\",\n    \"12-1\": \"Boolean (false)\",\n    \"12-2\": \"If set to true, disables custom JS that LiftIgniter is running for the client.\",\n    \"5-0\": \"disableCustomWidget\",\n    \"5-1\": \"Boolean (false)\",\n    \"5-2\": \"If true, then disable custom code that LiftIgniter implemented for you to render widgets.\"\n  },\n  \"cols\": 3,\n  \"rows\": 13\n}\n[/block]\nFor `activity` object:\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Name\",\n    \"h-1\": \"Type (Default)\",\n    \"h-2\": \"Description\",\n    \"0-0\": \"canonicalUrlTransform\",\n    \"1-0\": \"urlTransform\",\n    \"0-1\": \"Function (identity)\",\n    \"1-1\": \"Function (identity)\",\n    \"0-2\": \"Transforms the current canonical url given by `window.location` to a value returned by the function.\",\n    \"1-2\": \"Transforms url given by `window.location.href` to a value returned by the function.\"\n  },\n  \"cols\": 3,\n  \"rows\": 2\n}\n[/block]\nFor `sdk` object:\n[block:parameters]\n{\n  \"data\": {\n    \"0-0\": \"requestFields\",\n    \"h-0\": \"Name\",\n    \"h-1\": \"Type (Default)\",\n    \"h-2\": \"Description\",\n    \"2-0\": \"requestFieldsAON\",\n    \"5-0\": \"multiFetch\",\n    \"0-1\": \"Array of String ([\\\"url\\\", \\\"author\\\", \\\"title\\\", \\\"rank\\\", \\\"thumbnail\\\"])\",\n    \"0-2\": \"List of fields you want our recommendation to return for each item.\",\n    \"5-1\": \"Boolean (false)\",\n    \"5-2\": \"If true, then allows JavaScript SDK to make multiple recommendation queries on the same page.\",\n    \"2-1\": \"Boolean (false)\",\n    \"2-2\": \"If true, requests the model query to return items that contain all of the features specified in request fields.\",\n    \"1-0\": \"arrayRequestFields\",\n    \"1-1\": \"Array of String ([])\",\n    \"1-2\": \"List of fields returned as recommendation which is an array of string.\",\n    \"6-0\": \"pushStateReset\",\n    \"6-1\": \"Boolean (false)\",\n    \"6-2\": \"If set to true, the script refreshes and triggers a new pageview when a push state occurs.\",\n    \"7-0\": \"replaceStateReset\",\n    \"7-1\": \"Boolean (false)\",\n    \"7-2\": \"If set to true, the script refreshes and triggers a new pageview when replace state occurs.\",\n    \"8-0\": \"pushStateCallback\",\n    \"8-1\": \"Function (function(){})\",\n    \"8-2\": \"A callback function that's invoked at pushState/hash routing when pushStateReset/replaceState is set to true, or hash based routing is active.\",\n    \"3-0\": \"mandatoryRequestFields\",\n    \"3-1\": \"Array of String ([])\",\n    \"3-2\": \"If requestFieldsAON is set to false (or not set, so it defaults to false) this allows you to mark a subset of requestFields as mandatory. We only return items that have all those fields.\",\n    \"4-0\": \"mandatoryArrayRequestFields\",\n    \"4-1\": \"Array of String ([])\",\n    \"4-2\": \"If requestFieldsAON is set to false (or not set, so it defaults to false) this allows you to mark a subset of arrayRequestFields as mandatory. We only return items that have all those fields.\"\n  },\n  \"cols\": 3,\n  \"rows\": 9\n}\n[/block]\nFor `histSettings` object\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Name\",\n    \"h-1\": \"Type (Default)\",\n    \"h-2\": \"Description\",\n    \"0-0\": \"stripTags\",\n    \"0-1\": \"Boolean (True)\",\n    \"0-2\": \"If true, strip tags from URL to clean the browsing history of a user.\",\n    \"1-0\": \"stripHashes\",\n    \"1-1\": \"Boolean (True)\",\n    \"1-2\": \"If true, strip hashes from URL to clean the browsing history of a user.\",\n    \"2-0\": \"stripDashes\",\n    \"2-1\": \"Boolean (False)\",\n    \"2-2\": \"If true, strip dashes from URL to clean the browsing history of a user.\",\n    \"3-0\": \"origin\",\n    \"3-1\": \"String (undefined)\",\n    \"3-2\": \"String that replaces the host of page that a user is on. i.e. If the value is set to \\\"www.google.com\\\" when a user is on \\\"www.facebook.com/blah\\\", then data sent to our side will have \\\"www.google.com/blah\\\" as the current URL.\"\n  },\n  \"cols\": 3,\n  \"rows\": 4\n}\n[/block]\nFor general object (not object nested)\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Name\",\n    \"h-1\": \"Type (Default)\",\n    \"h-2\": \"Description\",\n    \"0-0\": \"apiRegex\",\n    \"0-1\": \"JS Regular Expression (undefined)\",\n    \"0-2\": \"Setting this will only send activities on a URL that matches the given regular expression. You can use this to filter out localhost or blacklisted test environment.\",\n    \"1-0\": \"apiExcludeRegex\",\n    \"1-1\": \"JS Regular Expression (undefined)\",\n    \"1-2\": \"Setting this won't send activities on URL matches the given regular expression. You can use this to filter out localhost or blacklisted test environment.\",\n    \"2-0\": \"globalTracking\",\n    \"2-1\": \"Boolean (default: true)\",\n    \"2-2\": \"Setting this to false will disable third party cookie that tracks users cross-site.\",\n    \"3-0\": \"trackingTransURL\",\n    \"3-1\": \"function (default: identity)\",\n    \"3-2\": \"Define a function that takes in an argument as URL/content ID of items being kept track of through the `track` function, and uses return value as the URL that's viewed/clicked on.\",\n    \"4-0\": \"customBrowsingHistory\",\n    \"4-1\": \"function (default: undefined)\",\n    \"4-2\": \"If this function is defined, then it will run in place of our internal JS function that updates the browsing history of a user.\"\n  },\n  \"cols\": 3,\n  \"rows\": 5\n}\n[/block]","excerpt":"","slug":"pinit","type":"fn","title":"$p(\"init\")"}
`$p("init"): (String, Object) -> undefined` [block:callout] { "type": "info", "title": "Technical documentation", "body": "This is technical documentation for the init function. It is used as part of the Javascript snippet you install when [Integrating LiftIgniter](doc:integrating-liftigniter)." } [/block] Various default settings of our script can be tweaked by specifying the config object. To give you a practical sense of what it does, let's say that you want to disable the automatic inventory scraping of our script when the page loads: [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\nvar customConfig = {\n\tinventory: {\n \tcollect: false\n }\n}\n\n$p(\"init\", {JAVASCRIPT_KEY}, {config: customConfig}); // REPLACE JAVASCRIPT_KEY\n$p(\"send\", \"pageview\");\n}\n</script>", "language": "javascript" } ] } [/block] You can set the option object's `config.inventory.collect = false` to disable automatic scraping that occurs when our script is initialized. `config` is a global state for our tracker that has two nested objects `inventory` and `sdk`. `inventory` defines the settings for functions related to scraping the data on page, and `sdk` defines settings for functions related to the SDK. Remaining key-value pairs within the `config` object sets our JS SDK's for other behaviors: [block:code] { "codes": [ { "code": "// General structure of the config variable\nvar config = {\n inventory: {INVENTORY_OPTION: VALUE_A},\n sdk: {SDK_OPTION: VALUE_B},\n CONFIG_OPTION: VALUE_C\n ...\n}", "language": "javascript" } ] } [/block] Here are the configurable options and values for `inventory` object: [block:parameters] { "data": { "0-0": "collect", "h-0": "Name", "h-1": "Type (Default)", "0-1": "Boolean (true)", "h-2": "Description", "0-2": "If true, then inventory collection function runs every time $p(\"init\") is invoked.\n\nAlso, setting this to false enables $p(\"sendItem\") function.", "1-0": "version", "1-1": "Number (undefined)", "1-2": "Specifies the inventory version. If the inventory version is specified, only inventories with version higher than or equal to value specified in client will be returned as a recommendation or scraped from our end.", "2-0": "collectJSON", "2-1": "Boolean (true)", "2-2": "If true, then inventory collection parses the text content of liftigniter-metadata DOM, and merges the JSON content with item information to be sent over to LiftIgniter.", "3-0": "collectOpenGraph", "3-1": "Boolean (true)", "3-2": "If true, then inventory collection scrapes data from OpenGraph features available on the page.", "4-0": "collectOpenGraphOnly", "4-1": "Boolean (true)", "4-2": "If true, then the script collects only pages that have all the mandatory graph features.", "6-0": "mandatoryFeatures", "6-1": "Array[String] ([\"title\", \"url\"])", "6-2": "List of features that must exist for the script to send page/item to LiftIgniter as a recommendable item. On a default setting, the mandatory features are \"title\" and \"url\".", "7-0": "mandatoryOpenGraphFeatures", "7-1": "Array[String] ([\"title\",\"url\",\"type\"])", "7-2": "List of Open Graph features that must exist for the script to send page/item to LiftIgniter as a recommendable item. On a default setting, the mandatory features are \"title\", \"type\", and \"url\".", "8-0": "features", "8-1": "Array[Object] (undefined)", "8-2": "List of features on page that you want our script to scrape. The documentation on feature object is defined below. You can reference details of this property [here](https://liftigniter.readme.io/docs/configuring-what-to-scrape).", "9-0": "filters", "9-1": "Array[Object] ([{name:\"noIndex\", value: \"true\"}])", "10-0": "itemRegex", "10-1": "JS Regular Expression (undefined)", "10-2": "Regular expression that matches the `url` or `id` of content on page. If the `url` or `id` matches the regular expression provided here, then it will pass the check to be sent over to LiftIgniter.", "9-2": "List of filters for inventory scraping. If the script scrapes a field with identifier `name` with value set to `value`, then the script won't scrape the page.", "11-0": "excludeRegex", "11-1": "JS Regular Expression (undefined)", "11-2": "If the `url` or `id` matches the regular expression provided here, then it will not be sent over to LiftIgniter.", "12-0": "extensionOff", "12-1": "Boolean (false)", "12-2": "If set to true, disables custom JS that LiftIgniter is running for the client.", "5-0": "disableCustomWidget", "5-1": "Boolean (false)", "5-2": "If true, then disable custom code that LiftIgniter implemented for you to render widgets." }, "cols": 3, "rows": 13 } [/block] For `activity` object: [block:parameters] { "data": { "h-0": "Name", "h-1": "Type (Default)", "h-2": "Description", "0-0": "canonicalUrlTransform", "1-0": "urlTransform", "0-1": "Function (identity)", "1-1": "Function (identity)", "0-2": "Transforms the current canonical url given by `window.location` to a value returned by the function.", "1-2": "Transforms url given by `window.location.href` to a value returned by the function." }, "cols": 3, "rows": 2 } [/block] For `sdk` object: [block:parameters] { "data": { "0-0": "requestFields", "h-0": "Name", "h-1": "Type (Default)", "h-2": "Description", "2-0": "requestFieldsAON", "5-0": "multiFetch", "0-1": "Array of String ([\"url\", \"author\", \"title\", \"rank\", \"thumbnail\"])", "0-2": "List of fields you want our recommendation to return for each item.", "5-1": "Boolean (false)", "5-2": "If true, then allows JavaScript SDK to make multiple recommendation queries on the same page.", "2-1": "Boolean (false)", "2-2": "If true, requests the model query to return items that contain all of the features specified in request fields.", "1-0": "arrayRequestFields", "1-1": "Array of String ([])", "1-2": "List of fields returned as recommendation which is an array of string.", "6-0": "pushStateReset", "6-1": "Boolean (false)", "6-2": "If set to true, the script refreshes and triggers a new pageview when a push state occurs.", "7-0": "replaceStateReset", "7-1": "Boolean (false)", "7-2": "If set to true, the script refreshes and triggers a new pageview when replace state occurs.", "8-0": "pushStateCallback", "8-1": "Function (function(){})", "8-2": "A callback function that's invoked at pushState/hash routing when pushStateReset/replaceState is set to true, or hash based routing is active.", "3-0": "mandatoryRequestFields", "3-1": "Array of String ([])", "3-2": "If requestFieldsAON is set to false (or not set, so it defaults to false) this allows you to mark a subset of requestFields as mandatory. We only return items that have all those fields.", "4-0": "mandatoryArrayRequestFields", "4-1": "Array of String ([])", "4-2": "If requestFieldsAON is set to false (or not set, so it defaults to false) this allows you to mark a subset of arrayRequestFields as mandatory. We only return items that have all those fields." }, "cols": 3, "rows": 9 } [/block] For `histSettings` object [block:parameters] { "data": { "h-0": "Name", "h-1": "Type (Default)", "h-2": "Description", "0-0": "stripTags", "0-1": "Boolean (True)", "0-2": "If true, strip tags from URL to clean the browsing history of a user.", "1-0": "stripHashes", "1-1": "Boolean (True)", "1-2": "If true, strip hashes from URL to clean the browsing history of a user.", "2-0": "stripDashes", "2-1": "Boolean (False)", "2-2": "If true, strip dashes from URL to clean the browsing history of a user.", "3-0": "origin", "3-1": "String (undefined)", "3-2": "String that replaces the host of page that a user is on. i.e. If the value is set to \"www.google.com\" when a user is on \"www.facebook.com/blah\", then data sent to our side will have \"www.google.com/blah\" as the current URL." }, "cols": 3, "rows": 4 } [/block] For general object (not object nested) [block:parameters] { "data": { "h-0": "Name", "h-1": "Type (Default)", "h-2": "Description", "0-0": "apiRegex", "0-1": "JS Regular Expression (undefined)", "0-2": "Setting this will only send activities on a URL that matches the given regular expression. You can use this to filter out localhost or blacklisted test environment.", "1-0": "apiExcludeRegex", "1-1": "JS Regular Expression (undefined)", "1-2": "Setting this won't send activities on URL matches the given regular expression. You can use this to filter out localhost or blacklisted test environment.", "2-0": "globalTracking", "2-1": "Boolean (default: true)", "2-2": "Setting this to false will disable third party cookie that tracks users cross-site.", "3-0": "trackingTransURL", "3-1": "function (default: identity)", "3-2": "Define a function that takes in an argument as URL/content ID of items being kept track of through the `track` function, and uses return value as the URL that's viewed/clicked on.", "4-0": "customBrowsingHistory", "4-1": "function (default: undefined)", "4-2": "If this function is defined, then it will run in place of our internal JS function that updates the browsing history of a user." }, "cols": 3, "rows": 5 } [/block]