The $p("init") function acts as the 'start button' for all other LiftIgniter SDK functions. It must be invoked first in order to use the rest of the Javascript integration method.
It also allows a significant number of default settings to be enabled, disabled, or modified to cover a number of special use cases or site architectures. For most integrations, there is no need to modify any of the default settings. These config options are covered below.
Settings Structure
Configs are controlled via JSON and specific key-value pairs. There are some general options available at the global config level, and several nested JSON objects that contain the settings for specific parts of the integration, like the inventory and activity tracking.
In general, we recommend placing all config options within a variable between the beacon snippet code and the $p("init") function. Here's an example with some of the more common configuration options:
<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 &amp;&amp; w.performance.now &amp;&amp; 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 = { apiRegex: /JS Regular Expression/ sdk: { requestFields: ["url", "author", "title", "rank", "thumbnail", "category"], requestFieldsAON: true }, inventory: { mandatoryFeatures: ["title", "url", "category"] } } $p("init", "JAVASCRIPT_KEY", {config: customConfig}); // REPLACE JAVASCRIPT_KEY $p("send", "pageview"); } </script>
Global Config Options
These options appear in the first level of JSON (see the apiRegex option in the sample code above)
Name | Type (Default Value) | 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. |
globalCtx | JSON array (default: undefined) | f you know that you'll be providing the same context information on every event, then you can set the globalCtx when the script is initialized.Then every event sent to LiftIgniter (including pageviews) will have that information appended to it without you having to define it in the context object of p(track) or p(send). |
isInFrame | Boolean (default: false) | If LiftIgniter is embedded in a page via iFrame, setting this to true will tell our tracking functions to pull current URL and canonical URL context information from the parent window automatically. |
SDK Options
These settings are nested within the sdk object in the JSON (see the requestFields and requestFieldsAON options in the sample code above)
Name | Type (Default Value) | Description |
---|---|---|
enableBackup | Boolean (true) | By default, LiftIgniter's default backup recommendation logic is turned on for cases when requests time out. These default backup recommendations do not adhere to rules defined for a particular integration. If configured to false, default backup recommendations will not be requested. Instead, you can define your own custom backup recommendation rendering and tracking logic by using the Custom Timeout Behavior option here. |
requestFields | Array of String (["url", "author", "title", "rank", "thumbnail"]) | List of string fields you want our recommendation to return for each item. |
arrayRequestFields | Array of String ([]) | List of array fields that should be returned in our recommendations. |
requestFieldsAON | Boolean (false) | If true, recommendations must contain a value for ALL of the fields specified in "requestFields". AON stands for "all or nothing" |
mandatoryRequestFields | Array of String ([]) | If requestFieldsAON is set to false (or not set, so it defaults to false) this allows you to mark SOME of the fields listed in requestFields as mandatory. We only return items that have a value for all of the mandatory fields. |
mandatoryArrayRequestFields | Array of String ([]) | If requestFieldsAON is set to false (or not set, so it defaults to false) this allows you to mark SOME of the fields listed in arrayRequestFields as mandatory. We only return items that have a value for all of the mandatory fields. |
multiFetch | Boolean (false) | If true, then allows JavaScript SDK to make multiple recommendation queries on the same page. Useful for lazy-loading widgets. |
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. |
Activity Tracking Options
These options allow the URLs picked up by our $p("track") function to be automatically rewritten. This is useful if you have different URLs for desktop and mobile (www. and m. for example), but are using only the desktop version of the URLs in your inventory. Rewriting the mobile URLs to use the desktop path will allow widget and pageview events to be correctly matched with those inventory items and can have a significant impact on recommendation quality.
Name | Type (Default Value) | 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. |
Inventory Collection Options
These settings allow you to turn inventory collection on or off, and filter out unwanted items from being collected by setting requirements around fields and URL paths that must be present.
Name | Type (Default Value) | 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. |
collectOpenGraph | Boolean (true) | If true, then inventory collection scrapes data from OpenGraph features available on the page. |
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. |
collectOpenGraphOnly | Boolean (true) | If true, then the script collects only pages that have all the mandatory graph features. |
features | Array[Object] (undefined) | List of features on page that you want our script to scrape. Please refer to our detailed documentation on implementing this configuration. |
mandatoryFeatures | Array[String] (["title", "url"]) | List of features that must exist for the script to send page/item to LiftIgniter as a recommendable item. |
filters | Array[Object] ([{name:"noIndex", value: "true"}]) | List of filters for inventory scraping. If the script finds 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 the item. If the url or id matches the regular expression provided here, then it will be sent to the inventory. |
excludeRegex | JS Regular Expression (undefined) | If the url or id matches the regular expression provided here, then it will NOT be sent to the inventory. |
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 the client will be returned as a recommendation or scraped from our end. |
Browsing History Options
Very rarely used, these options modify how LiftIgniter collects URLs in the browsing history of a user. If your site uses query strings or hashes to generate URLs for content, these settings will allow us to correctly match user history to inventory items.
Name | Type (Default Value) | 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" then when a user is on "www.facebook.com/blah", data sent to our side will have "www.google.com/blah" as the current URL. |