$p("init")

$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:

NameType (Default)Description
collectBoolean (true)If true, then inventory collection function runs every time $p("init") is invoked.

Also, setting this to false enables $p("sendItem") function.
versionNumber (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.
collectJSONBoolean (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.
collectOpenGraphBoolean (true)If true, then inventory collection scrapes data from OpenGraph features available on the page.
collectOpenGraphOnlyBoolean (true)If true, then the script collects only pages that have all the mandatory graph features.
disableCustomWidgetBoolean (false)If true, then disable custom code that LiftIgniter implemented for you to render widgets.
mandatoryFeaturesArray[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".
mandatoryOpenGraphFeaturesArray[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".
featuresArray[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.
filtersArray[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.
itemRegexJS 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.
excludeRegexJS Regular Expression (undefined)If the url or id matches the regular expression provided here, then it will not be sent over to LiftIgniter.
extensionOffBoolean (false)If set to true, disables custom JS that LiftIgniter is running for the client.

For activity object:

NameType (Default)Description
canonicalUrlTransformFunction (identity)Transforms the current canonical url given by window.location to a value returned by the function.
urlTransformFunction (identity)Transforms url given by window.location.href to a value returned by the function.

For sdk object:

NameType (Default)Description
requestFieldsArray of String (["url", "author", "title", "rank", "thumbnail"])List of fields you want our recommendation to return for each item.
arrayRequestFieldsArray of String ([])List of fields returned as recommendation which is an array of string.
requestFieldsAONBoolean (false)If true, requests the model query to return items that contain all of the features specified in request fields.
mandatoryRequestFieldsArray 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.
mandatoryArrayRequestFieldsArray 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.
multiFetchBoolean (false)If true, then allows JavaScript SDK to make multiple recommendation queries on the same page.
pushStateResetBoolean (false)If set to true, the script refreshes and triggers a new pageview when a push state occurs.
replaceStateResetBoolean (false)If set to true, the script refreshes and triggers a new pageview when replace state occurs.
pushStateCallbackFunction (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

NameType (Default)Description
stripTagsBoolean (True)If true, strip tags from URL to clean the browsing history of a user.
stripHashesBoolean (True)If true, strip hashes from URL to clean the browsing history of a user.
stripDashesBoolean (False)If true, strip dashes from URL to clean the browsing history of a user.
originString (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)

NameType (Default)Description
apiRegexJS 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.
apiExcludeRegexJS 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.
globalTrackingBoolean (default: true)Setting this to false will disable third party cookie that tracks users cross-site.
trackingTransURLfunction (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.
customBrowsingHistoryfunction (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.