We can return any or all fields that are part of an item's inventory metadata.


By default, we'll return an item's url, title, thumbnail (aka image), and description. To request additional fields be returned, you can ask for them to be included as either a global setting, or on a per-widget basis. It's important to note that there are separate settings for single-value (String) fields, and fields that contain multiple values (Arrays). You can also set some or all fields as mandatory, meaning that we will only return recommendations that have values for the specified fields.


1. Set default fields globally


If you will always want the same fields returned for all items in all widgets the best method will be to use the configuration options available in the Javascript initialization function, $p("init"). This is done by adding the following to the beacon code, just before the $p("init") command.


For Single-Value (String) Fields:

var customConfig = {
  sdk: {
    requestFields: ["url", "author", "title", "rank", "thumbnail", "other_fields_you_may_want"]
  }
}


For Multi-Value (Array) Fields:

var customConfig = {
  sdk: {
    arrayRequestFields: ["tags", "multi-value-field1", "multi-value-field2"]
  }
}


Here is a completed sample beacon containing requests for both String and Array fields combined:


<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;amp;&amp;amp;amp; w.performance.now &amp;amp;amp;&amp;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 = {
  sdk: {
    requestFields: ["url", "author", "title", "rank", "thumbnail"],
    arrayRequestFields: ["tags", "multi-value-field1", "multi-value-field2"]
  }
}

$p("init", "JAVASCRIPT_KEY", { config: customConfig }); // REPLACE JAVASCRIPT_KEY
$p("send", "pageview");
}
</script>


2. Request additional fields in a particular widget query

If you only require additional fields for a particular widget, you can include our $p("setRequestFields") (for single-value fields) and/or $p("setArrayRequestFields") (for arrays) functions before the $p("fetch") function which triggers the call to our servers to get the recommendations. 


Here is a sample widget request containing requests for both String and Array fields:

$p('register', {
                  max: 100, // Large number requested so you can see our full range of items
                  widget: 'default-widget', // name of widget
                  callback: function(resp) {
                    }
               }
);
$p("setRequestFields",["url", "author", "title", "rank", "thumbnail"]) // Set request fields
$p("setArrayRequestFields", ["tags", "multi-value-field1", "multi-value-field2"]) // Set array request fields
$p('fetch');
// Execute the registered call.


Setting Fields as Mandatory


All Fields Mandatory

If you have used either of the requested fields settings outlined above, you can also use an "all or nothing" modifier to get only items which have values for ALL of the fields specified. As above, this can be done in either the beacon configuration (shown below) or using $p("setRequestFieldsAON",true) before the $p("fetch") function.


<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;amp;amp;&amp;amp;amp;amp; w.performance.now &amp;amp;amp;amp;&amp;amp;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 = {
  sdk: {
    requestFields: ["url", "author", "title", "rank", "thumbnail"],
    requestFieldsAON: true
  }
}

$p("init", "JAVASCRIPT_KEY", { config: customConfig }); // REPLACE JAVASCRIPT_KEY
$p("send", "pageview");
}
</script>


Only Some Fields Mandatory

If only some of the fields you are requesting should be considered mandatory, (e.g. you want them to always have title and thumbnail, but it's okay if author is blank) you can provide us with the list of which ones must have values. As with the request fields, there are separate settings for String and Array fields, and they can be called in either the beacon configuration (shown below) or using the functions $p("setMandatoryRequestFields",["title","url"]) and/or $p("setMandatoryArrayRequestFields",["list","of","mandatory","array","request","fields"]);  before the $p("fetch") function.


<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;amp;amp;amp;&amp;amp;amp;amp;amp; w.performance.now &amp;amp;amp;amp;amp;&amp;amp;amp;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 = {
  sdk: {
    requestFields: ["url", "author", "title", "rank", "thumbnail"],
    mandatoryRequestFields: ["title", "thumbnail"]
  }
}

$p("init", "JAVASCRIPT_KEY", { config: customConfig }); // REPLACE JAVASCRIPT_KEY
$p("send", "pageview");
}
</script>