Skip to content

Commit

Permalink
feat(unrulyBidAdapter): add userSync functionality (#3460)
Browse files Browse the repository at this point in the history
* feat(unrulyBidAdapter): add userSync functionality

* feat(unrulyBidAdapter): add gdpr consent functionality to getUserSyncs

* fix(unrulyBidAdapter): fix empty object pattern in tests
  • Loading branch information
OnoTheHedgehog authored and robertrmartinez committed Jan 31, 2019
1 parent 596af88 commit ea3d10b
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
4 changes: 4 additions & 0 deletions integrationExamples/gpt/unruly_example.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
pbjs.setConfig({
"currency": {
"adServerCurrency": "USD",
},
"userSync": {
"iframeEnabled": true,
"enabledBidders": ['unruly']
}
});
});
Expand Down
20 changes: 20 additions & 0 deletions modules/unrulyBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,26 @@ export const adapter = {
return isInvalidResponse
? noBidsResponse
: buildPrebidResponseAndInstallRenderer(serverResponseBody.bids);
},

getUserSyncs: function(syncOptions, response, gdprConsent) {
let params = '';
if (gdprConsent && 'gdprApplies' in gdprConsent) {
if (gdprConsent.gdprApplies && typeof gdprConsent.consentString === 'string') {
params += `?gdpr=1&gdpr_consent=${gdprConsent.consentString}`;
} else {
params += `?gdpr=0`;
}
}

const syncs = []
if (syncOptions.iframeEnabled) {
syncs.push({
type: 'iframe',
url: 'https://video.unrulymedia.com/iframes/third-party-iframes.html' + params
});
}
return syncs;
}
};

Expand Down
60 changes: 60 additions & 0 deletions test/spec/modules/unrulyBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,64 @@ describe('UnrulyAdapter', function () {
expect(supplyMode).to.equal('prebid');
});
});

describe('getUserSyncs', () => {
it('should push user sync iframe if enabled', () => {
const mockConsent = {}
const response = {}
const syncOptions = { iframeEnabled: true }
const syncs = adapter.getUserSyncs(syncOptions, response, mockConsent)
expect(syncs[0]).to.deep.equal({
type: 'iframe',
url: 'https://video.unrulymedia.com/iframes/third-party-iframes.html'
});
})

it('should not push user sync iframe if not enabled', () => {
const mockConsent = {}
const response = {}
const syncOptions = { iframeEnabled: false }
const syncs = adapter.getUserSyncs(syncOptions, response, mockConsent);
expect(syncs).to.be.empty;
});
});

it('should not append consent params if gdpr does not apply', () => {
const mockConsent = {}
const response = {}
const syncOptions = { iframeEnabled: true }
const syncs = adapter.getUserSyncs(syncOptions, response, mockConsent)
expect(syncs[0]).to.deep.equal({
type: 'iframe',
url: 'https://video.unrulymedia.com/iframes/third-party-iframes.html'
})
})

it('should append consent params if gdpr does apply and consent is given', () => {
const mockConsent = {
gdprApplies: true,
consentString: 'hello'
}
const response = {}
const syncOptions = { iframeEnabled: true }
const syncs = adapter.getUserSyncs(syncOptions, response, mockConsent)
expect(syncs[0]).to.deep.equal({
type: 'iframe',
url: 'https://video.unrulymedia.com/iframes/third-party-iframes.html?gdpr=1&gdpr_consent=hello'
})
})

it('should append consent param if gdpr applies and no consent is given', () => {
const mockConsent = {
gdprApplies: true,
consentString: {}
}
const response = {}
const syncOptions = { iframeEnabled: true }
const syncs = adapter.getUserSyncs(syncOptions, response, mockConsent)
expect(syncs[0]).to.deep.equal({
type: 'iframe',
url: 'https://video.unrulymedia.com/iframes/third-party-iframes.html?gdpr=0'
})
})
});

0 comments on commit ea3d10b

Please sign in to comment.