Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yl 4121 add user matching to prebid #4

Merged
merged 3 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion modules/yieldlabBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { _each, isPlainObject, isArray, deepAccess } from '../src/utils.js';
import {_each, isPlainObject, isArray, deepAccess, timestamp} from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js'
import find from 'core-js-pure/features/array/find.js'
import { VIDEO, BANNER, NATIVE } from '../src/mediaTypes.js'
Expand Down Expand Up @@ -174,6 +174,37 @@ export const spec = {
}
})
return bidResponses
},

/**
* Register the user sync pixels which should be dropped after the auction.
*
* @param {SyncOptions} syncOptions Which user syncs are allowed?
* @param {ServerResponse[]} serverResponses List of server's responses.
* @param {Object} gdprConsent Is the GDPR Consent object wrapping gdprApplies {boolean} and consentString {string} attributes.
* @param {string} uspConsent Is the US Privacy Consent string.
* @return {UserSync[]} The user syncs which should be dropped.
*/
getUserSyncs: function (syncOptions, serverResponses, gdprConsent, uspConsent) {
const syncs = [];

if (syncOptions.iframeEnabled) {
let params = [];
params.push(`ts=${timestamp()}`);
params.push(`type=h`)
if (gdprConsent && (typeof gdprConsent.gdprApplies === 'boolean')) {
params.push(`gdpr=${Number(gdprConsent.gdprApplies)}`);
}
if (gdprConsent && (typeof gdprConsent.consentString === 'string')) {
params.push(`gdpr_consent=${gdprConsent.consentString}`);
}
syncs.push({
type: 'iframe',
url: `${ENDPOINT}/d/6846326/766/2x2?${params.join('&')}`
});
}

return syncs;
}
};

Expand Down
36 changes: 36 additions & 0 deletions test/spec/modules/yieldlabBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,4 +414,40 @@ describe('yieldlabBidAdapter', function () {
expect(result[0].vastUrl).to.include('&iab_content=id%3Afoo_id%2Cepisode%3A99%2Ctitle%3Afoo_title%252Cbar_title%2Cseries%3Afoo_series%2Cseason%3As1%2Cartist%3Afoo%2520bar%2Cgenre%3Abaz%2Cisrc%3ACC-XXX-YY-NNNNN%2Curl%3Ahttp%253A%252F%252Ffoo_url.de%2Ccat%3Acat1%7Ccat2%252Cppp%7Ccat3%257C%257C%257C%252F%252F%2Ccontext%3A7%2Ckeywords%3Ak1%252C%7Ck2..%2Clive%3A0')
})
})

describe('getUserSyncs', function () {
const syncOptions = {
iframeEnabled: true,
pixelEnabled: false
};
const expectedUrlSnippets = ['https://ad.yieldlab.net/d/6846326/766/2x2?', 'ts=', 'type=h'];

it('should return user sync as expected', function () {
const bidRequest = {
gdprConsent: {
consentString: 'BN5lERiOMYEdiAKAWXEND1AAAAE6DABACMA',
gdprApplies: true
},
uspConsent: '1YYY'
};
const sync = spec.getUserSyncs(syncOptions, [], bidRequest.gdprConsent, bidRequest.uspConsent);
expect(expectedUrlSnippets.every(urlSnippet => sync[0].url.includes(urlSnippet)));
expect(sync[0].url).to.have.string('gdpr=' + Number(bidRequest.gdprConsent.gdprApplies));
expect(sync[0].url).to.have.string('gdpr_consent=' + bidRequest.gdprConsent.consentString);
// USP consent should be ignored
expect(sync[0].url).not.have.string('usp_consent=');
expect(sync[0].type).to.have.string('iframe');
});

it('should return user sync even without gdprApplies in gdprConsent', function () {
const gdprConsent = {
consentString: 'BN5lERiOMYEdiAKAWXEND1AAAAE6DABACMA'
}
const sync = spec.getUserSyncs(syncOptions, [], gdprConsent, undefined);
expect(expectedUrlSnippets.every(urlSnippet => sync[0].url.includes(urlSnippet)));
expect(sync[0].url).to.have.string('gdpr_consent=' + gdprConsent.consentString);
expect(sync[0].url).not.have.string('gdpr=');
expect(sync[0].type).to.have.string('iframe');
});
});
})