Skip to content

Commit

Permalink
Merge pull request indexexchange#2 from jimee02/gdpr-support
Browse files Browse the repository at this point in the history
GDPR Support
  • Loading branch information
ix-certification authored May 17, 2018
2 parents afb5f38 + 43a6138 commit 70f7cc7
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 47 deletions.
9 changes: 0 additions & 9 deletions open-x-htb-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,6 @@ var partnerValidator = function (configs) {
type: 'string',
minLength: 1
},
bidderCode: {
optional: true,
type: 'string',
minLength: 1
},
trackingEnabled: {
optional: true,
type: 'boolean'
},
xSlots: {
type: 'object',
properties: {
Expand Down
120 changes: 82 additions & 38 deletions open-x-htb.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var Utilities = require('utilities.js');
var Whoopsie = require('whoopsie.js');
var EventsService;
var RenderService;
var ComplianceService;

//? if (DEBUG) {
var ConfigValidators = require('config-validators.js');
Expand Down Expand Up @@ -103,44 +104,65 @@ function OpenXHtb(configs) {
* @return {object}
*/
function __generateRequestObj(returnParcels) {
var callbackId = '_' + System.generateUniqueId();

var auidString = '';
var ausString = '';

for (var i = 0; i < returnParcels.length; i++) {
auidString += returnParcels[i].xSlotRef.adUnitId.toString() + ',';
ausString += Size.arrayToString(returnParcels[i].xSlotRef.sizes, ',') + '|';
var callbackId = '_' + System.generateUniqueId();

var auidString = '';
var ausString = '';

/**
* @typedef {{
* applies: boolean,
* consentString: string
* }}
*/
var gdprConsent = ComplianceService.gdpr.getConsent();
var gdprPrivacyEnabled = ComplianceService.isPrivacyEnabled();



for (var i = 0; i < returnParcels.length; i++) {
auidString += returnParcels[i].xSlotRef.adUnitId.toString() + ',';
ausString += Size.arrayToString(returnParcels[i].xSlotRef.sizes, ',') + '|';
}

auidString = auidString.slice(0, -1);
ausString = ausString.slice(0, -1);

var queryObj = {
auid: auidString,
aus: ausString,
ju: Browser.getPageUrl(),
jr: Browser.getReferrer(),
ch: configs.charset,
tz: System.getTimezoneOffset(),
bc: 'hb_ix',
be: 1,
res: Size.arrayToString([
[Browser.getScreenWidth(), Browser.getScreenHeight()]
]),
tws: Size.arrayToString([
[Browser.getViewportWidth(), Browser.getViewportHeight()]
]),
ifr: Browser.isTopFrame() ? 0 : 1,
callback: 'window.' + SpaceCamp.NAMESPACE + '.OpenXHtb.adResponseCallbacks.' + callbackId,
cache: new Date().getTime()
};

if (gdprPrivacyEnabled) {
if (gdprConsent.consentString !== void(0)) {
queryObj.gdpr_consent = gdprConsent.consentString;
}

auidString = auidString.slice(0, -1);
ausString = ausString.slice(0, -1);

var queryObj = {
auid: auidString,
aus: ausString,
ju: Browser.getPageUrl(),
jr: Browser.getReferrer(),
ch: configs.charset,
tz: System.getTimezoneOffset(),
bc: 'hb_ix',
be: 1,
res: Size.arrayToString([
[Browser.getScreenWidth(), Browser.getScreenHeight()]
]),
tws: Size.arrayToString([
[Browser.getViewportWidth(), Browser.getViewportHeight()]
]),
ifr: Browser.isTopFrame() ? 0 : 1,
callback: 'window.' + SpaceCamp.NAMESPACE + '.OpenXHtb.adResponseCallbacks.' + callbackId,
cache: new Date().getTime()
};
if (gdprConsent.applies !== void(0)) {
queryObj.gdpr = gdprConsent.applies ? '1' : '0';
}
}

return {
url: __baseAdRequestUrl,
data: queryObj,
callbackId: callbackId
};
return {
url: __baseAdRequestUrl,
data: queryObj,
callbackId: callbackId
};
}

/* Helpers
Expand All @@ -152,7 +174,18 @@ function OpenXHtb(configs) {
function __parseResponse(sessionId, adResponse, returnParcels, outstandingXSlotNames, startTime, endTime, timedOut) {
var unusedReturnParcels = returnParcels.slice();

var ads = adResponse.ads;
/**
* @typedef {{
* applies: boolean,
* consentString: string
* }}
*/
var gdprConsent = ComplianceService.gdpr.getConsent();
var gdprPrivacyEnabled = ComplianceService.isPrivacyEnabled();



var ads = adResponse.ads;

if (!ads || !ads.ad || !Utilities.isArray(ads.ad)) {

Expand All @@ -166,7 +199,17 @@ function OpenXHtb(configs) {
}

if (ads.pixels) {
Browser.createHiddenIFrame(ads.pixels);
if(gdprPrivacyEnabled){
if (gdprConsent.consentString !== void(0)) {
ads.pixels += '&gdpr_consent=' + gdprConsent.consentString;
}

if (gdprConsent.applies !== void(0)) {
ads.pixels += '&gdpr=' + (gdprConsent.applies ? '1' : '0');
}
}

Browser.createHiddenIFrame(ads.pixels);
}

var bids = ads.ad;
Expand Down Expand Up @@ -316,8 +359,9 @@ function OpenXHtb(configs) {
(function __constructor() {
EventsService = SpaceCamp.services.EventsService;
RenderService = SpaceCamp.services.RenderService;
ComplianceService = SpaceCamp.services.ComplianceService;

__profile = {
__profile = {
partnerId: 'OpenXHtb',
namespace: 'OpenXHtb',
statsId: 'OPNX',
Expand Down

0 comments on commit 70f7cc7

Please sign in to comment.