$p("init"): (String, Object) -> undefined
Technical documentation
This is technical documentation for the init function. It is used as part of the Javascript snippet you install when Integrating LiftIgniter.
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:
<script type="text/javascript">
if (typeof $igniter_var === 'undefined') {
// Ensures that our client code is updated.
(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(
arguments)};w[v].l=1*new Date();e=d.createElement(s),r=d.getElementsByTagName(s)[0];e.async=1;
e.src=p+'?ts='+(+new Date()/3600000|0);
r.parentNode.insertBefore(e,r)})(window,document,'script','//cdn.petametrics.com/{JAVASCRIPT_KEY}.js','$p');
// Don't forget to REPLACE JAVASCRIPT_KEY for cdn url.
var customConfig = {
inventory: {
collect: false
}
}
$p("init", {JAVASCRIPT_KEY}, {config: customConfig}); // REPLACE JAVASCRIPT_KEY
$p("send", "pageview");
}
</script>
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:
// General structure of the config variable
var config = {
inventory: {INVENTORY_OPTION: VALUE_A},
sdk: {SDK_OPTION: VALUE_B},
CONFIG_OPTION: VALUE_C
...
}
Here are the configurable options and values for inventory
object:
Name | Type (Default) | Description |
---|---|---|
collect | Boolean (true) | If true, then inventory collection function runs every time $p("init") is invoked. Also, setting this to false enables $p("sendItem") function. |
version | Number (undefined) | 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. |
collectJSON | Boolean (true) | 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. |
collectOpenGraph | Boolean (true) | If true, then inventory collection scrapes data from OpenGraph features available on the page. |
collectOpenGraphOnly | Boolean (true) | If true, then the script collects only pages that have all the mandatory graph features. |
disableCustomWidget | Boolean (false) | If true, then disable custom code that LiftIgniter implemented for you to render widgets. |
mandatoryFeatures | Array[String] (["title", "url"]) | 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". |
mandatoryOpenGraphFeatures | Array[String] (["title","url","type"]) | 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". |
features | Array[Object] (undefined) | 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. |
filters | Array[Object] ([{name:"noIndex", value: "true"}]) | 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. |
itemRegex | JS Regular Expression (undefined) | 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. |
excludeRegex | JS Regular Expression (undefined) | If the url or id matches the regular expression provided here, then it will not be sent over to LiftIgniter. |
extensionOff | Boolean (false) | If set to true, disables custom JS that LiftIgniter is running for the client. |
For activity
object:
Name | Type (Default) | Description |
---|---|---|
canonicalUrlTransform | Function (identity) | Transforms the current canonical url given by window.location to a value returned by the function. |
urlTransform | Function (identity) | Transforms url given by window.location.href to a value returned by the function. |
For sdk
object:
Name | Type (Default) | Description |
---|---|---|
requestFields | Array of String (["url", "author", "title", "rank", "thumbnail"]) | List of fields you want our recommendation to return for each item. |
arrayRequestFields | Array of String ([]) | List of fields returned as recommendation which is an array of string. |
requestFieldsAON | Boolean (false) | If true, requests the model query to return items that contain all of the features specified in request fields. |
mandatoryRequestFields | Array of String ([]) | 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. |
mandatoryArrayRequestFields | Array of String ([]) | 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. |
multiFetch | Boolean (false) | If true, then allows JavaScript SDK to make multiple recommendation queries on the same page. |
pushStateReset | Boolean (false) | If set to true, the script refreshes and triggers a new pageview when a push state occurs. |
replaceStateReset | Boolean (false) | If set to true, the script refreshes and triggers a new pageview when replace state occurs. |
pushStateCallback | Function (function(){}) | A callback function that's invoked at pushState/hash routing when pushStateReset/replaceState is set to true, or hash based routing is active. |
For histSettings
object
Name | Type (Default) | Description |
---|---|---|
stripTags | Boolean (True) | If true, strip tags from URL to clean the browsing history of a user. |
stripHashes | Boolean (True) | If true, strip hashes from URL to clean the browsing history of a user. |
stripDashes | Boolean (False) | If true, strip dashes from URL to clean the browsing history of a user. |
origin | String (undefined) | 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. |
For general object (not object nested)
Name | Type (Default) | Description |
---|---|---|
apiRegex | JS Regular Expression (undefined) | 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. |
apiExcludeRegex | JS Regular Expression (undefined) | 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. |
globalTracking | Boolean (default: true) | Setting this to false will disable third party cookie that tracks users cross-site. |
trackingTransURL | function (default: identity) | 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. |
customBrowsingHistory | function (default: undefined) | If this function is defined, then it will run in place of our internal JS function that updates the browsing history of a user. |