It is possible to get and store a user's consent preferences for non-IAB vendors using a combination of the Sourcepoint Consent & Reject actions along with some on-page JavaScript. The described below creates three functions:

  1. addVendor() - A function called from the consent action window from within the Sourcepoint user interface and added to the main page. This function adds a vendor code the site defines to a cookie called noniab_vendors if it is not already a part of the noniab_vendors cookie value. It also adds it to the window.nonIabVendorConsents array if is not already a part of that array.
  2. removeVendor() - A function called from the reject action window from within the Sourcepoint user interface and added to the main page. This function removes a vendor code (defined by the site) from the noniab_vendors cookie if it has not already been removed. It also removes the value from the window.nonIabVendorConsents array if is not already been removed from that array.
  3. getNonIabVendors() - A function that gets the list of vendors stored in the noniab_vendors cookie.

Please see the code below for these functions. The getCookie and setCookie functions are for demonstration purposes. You can substitute your own cookie getter and setter functions. Please also be aware that the example stores the cookie on the root domain of the site so that it can be accessed by all subdomains of the site.

<script type="text/javascript">

function setCookie(cname, cvalue, exdays) {
  var d = new Date();
  d.setTime(d.getTime() + (exdays*24*60*60*1000));
  var expires = "expires="+ d.toUTCString();

  var temp = location.host.split('.').reverse();
  var root_domain = '.' + temp[1] + '.' + temp[0];


  document.cookie = cname + "=" + cvalue + ";" + expires + ";domain="+root_domain+";path=/";
  console.log("Setting Cookie to :" + cvalue + "on domain: " + root_domain);
}

function getCookie(cname) {
  var name = cname + "=";
  var decodedCookie = decodeURIComponent(document.cookie);
  var ca = decodedCookie.split(';');
  for(var i = 0; i <ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0) == ' ') {
      c = c.substring(1);
    }
    if (c.indexOf(name) == 0) {
      return c.substring(name.length, c.length);
    }
  }
  return "";
}

function removeVendor(vendor){
_vendor = vendor;
  vendor_pos=window.nonIabVendorConsents.indexOf(_vendor);
  if(vendor_pos>-1){
  window.nonIabVendorConsents.splice(vendor_pos,1);
  console.log("removing vendor: " + _vendor);
}
else{
console.log("no action needed " + _vendor + "not in consented to");

}
console.log("new cookie value: " + window.nonIabVendorConsents);
setCookie("noniab_vendors",JSON.stringify(nonIabVendorConsents),90);
}

function addVendor(vendor){
_vendor = vendor;
if(typeof window.nonIabVendorConsents == 'undefined'){
  window.nonIabVendorConsents = [_vendor];
}
else{
if(!window.nonIabVendorConsents.includes(_vendor))
  window.nonIabVendorConsents.push(_vendor);
}
setCookie("noniab_vendors",JSON.stringify(nonIabVendorConsents),90);
console.log("adding vendor: " + _vendor);
}


function getNonIabVendors(){
var cookie_val = getCookie("noniab_vendors");
console.log("cookie_val: " + cookie_val);
if(cookie_val!=""){
var noniab_vendors = JSON.parse(cookie_val);
}
else{
console.log("no cookie");
}
return noniab_vendors;
}
</script>

The next part of the solution is adding the necessary configuration pieces to the Sourcepoint configuration code. 

The first step is to set the window.nonIabVendorConsents array to access the array of vendors. This is done using the code below.

//Define Array to capture non-IAB purposes & vendors
window.nonIabVendorConsents = [];


The second steps is adding the code necessary to retrieve the vendors from the cookie if they exist. This is done using the code below.

//get non-iab vendors from cookie if they exist.
if(typeof getNonIabVendors()!= 'undefined'){
  _noniab_vendors = getNonIabVendors();
  window.nonIabVendorConsents = _noniab_vendors;
}

Below is the code shown with the rest of the Sourcepoint configuration code.

<script type = "text/javascript"> 											
window._sp_ = window._sp_ || {};
window._sp_.config = window._sp_.config || {};

//Replace YOUR_ACCOUNT_ID with the account ID provided
//by Sourcepoint
window._sp_.config.account_id = 22;

// replace 'mms.sp-prod.net' with your CNAME’d messaging subdomain
window._sp_.config.mms_domain = 'mms.sp-demo.com';  

// messaging-specific configuration
window._sp_.mms = window._sp_.mms || {};
window._sp_.mms.cmd = window._sp_.mms.cmd || [];

//CMP Flags
window._sp_.config.cmp = _sp_.config.cmp || {};
window._sp_.config.cmp.enabled = true;

//Define Array to capture non-IAB purposes & vendors
window.nonIabVendorConsents = [];

//get non-iab vendors from cookie if they exist.
if(typeof getNonIabVendors()!="undefined"){
_noniab_vendors = getNonIabVendors();
window.nonIabVendorConsents = _noniab_vendors;
}

//Have message show immediately
//window._sp_.config.detection = window._sp_.config.detection || {};
//window._sp_.config.detection.timeout = 1;

//Code to call the server and display a message
window._sp_.mms.cmd.push( function () {
    window._sp_.mms.startMsg();
});
</script>

The last step is to implement the addVendor() and removeVendor() functions into the Consent and Reject actions of the Sourcepoint User interface. In the example below, the code "ga" stands for Google Analytics, but this code can be any alphanumeric code that you use to identify a vendor.

Below is an example of the code entered into the consent action window.

Below is an example of the code entered into the reject action window.

If you have any questions about this article, please contact your Sourcepoint account manager.

Did this answer your question?