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

MgidAdapter: change user sync get parameters #9891

Merged
merged 3 commits into from
May 6, 2023
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
17 changes: 9 additions & 8 deletions modules/mgidBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,40 +380,41 @@ export const spec = {

const syncs = [];
const query = [];
query.push('cbuster=' + Math.round(new Date().getTime()));
query.push('consentData=' + encodeURIComponent(isPlainObject(gdprConsent) && isStr(gdprConsent?.consentString) ? gdprConsent.consentString : ''));
query.push('cbuster={cbuster}');
query.push('gdpr_consent=' + encodeURIComponent(isPlainObject(gdprConsent) && isStr(gdprConsent?.consentString) ? gdprConsent.consentString : ''));
if (isPlainObject(gdprConsent) && typeof gdprConsent?.gdprApplies === 'boolean' && gdprConsent.gdprApplies) {
query.push('gdprApplies=1');
query.push('gdpr=1');
} else {
query.push('gdprApplies=0');
query.push('gdpr=0');
}
if (isPlainObject(uspConsent) && uspConsent?.consentString) {
query.push(`uspString=${encodeURIComponent(uspConsent?.consentString)}`);
query.push(`us_privacy=${encodeURIComponent(uspConsent?.consentString)}`);
}
if (isPlainObject(gppConsent) && gppConsent?.gppString) {
query.push(`gppString=${encodeURIComponent(gppConsent?.gppString)}`);
}
if (config.getConfig('coppa')) {
query.push('coppa=1')
}
const q = query.join('&')
if (syncOptions.iframeEnabled) {
syncs.push({
type: 'iframe',
url: 'https://cm.mgid.com/i.html?' + query.join('&')
url: 'https://cm.mgid.com/i.html?' + q.replace('{cbuster}', Math.round(new Date().getTime()))
});
} else if (syncOptions.pixelEnabled) {
if (pixels.length === 0) {
for (let i = 0; i < spb; i++) {
syncs.push({
type: 'image',
url: 'https://cm.mgid.com/i.gif?' + query.join('&') // randomly selects partner if sync required
url: 'https://cm.mgid.com/i.gif?' + q.replace('{cbuster}', Math.round(new Date().getTime())) // randomly selects partner if sync required
});
}
} else {
for (let i = 0; i < spb && i < pixels.length; i++) {
syncs.push({
type: 'image',
url: pixels[i] + (pixels[i].indexOf('?') > 0 ? '&' : '?') + query.join('&')
url: pixels[i] + (pixels[i].indexOf('?') > 0 ? '&' : '?') + q.replace('{cbuster}', Math.round(new Date().getTime()))
});
}
}
Expand Down
18 changes: 9 additions & 9 deletions test/spec/modules/mgidBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -824,43 +824,43 @@ describe('Mgid bid adapter', function () {
const sync = spec.getUserSyncs({iframeEnabled: true})
expect(sync).to.have.length(1)
expect(sync[0]).to.have.property('type', 'iframe')
expect(sync[0]).to.have.property('url').match(/https:\/\/cm\.mgid\.com\/i\.html\?cbuster=\d+&consentData=&gdprApplies=0/)
expect(sync[0]).to.have.property('url').match(/https:\/\/cm\.mgid\.com\/i\.html\?cbuster=\d+&gdpr_consent=&gdpr=0/)
});
it('should return frame object with gdpr consent', function () {
const sync = spec.getUserSyncs({iframeEnabled: true}, undefined, {consentString: 'consent', gdprApplies: true})
expect(sync).to.have.length(1)
expect(sync[0]).to.have.property('type', 'iframe')
expect(sync[0]).to.have.property('url').match(/https:\/\/cm\.mgid\.com\/i\.html\?cbuster=\d+&consentData=consent&gdprApplies=1/)
expect(sync[0]).to.have.property('url').match(/https:\/\/cm\.mgid\.com\/i\.html\?cbuster=\d+&gdpr_consent=consent&gdpr=1/)
});
it('should return frame object with gdpr + usp', function () {
const sync = spec.getUserSyncs({iframeEnabled: true}, undefined, {consentString: 'consent1', gdprApplies: true}, {'consentString': 'consent2'})
expect(sync).to.have.length(1)
expect(sync[0]).to.have.property('type', 'iframe')
expect(sync[0]).to.have.property('url').match(/https:\/\/cm\.mgid\.com\/i\.html\?cbuster=\d+&consentData=consent1&gdprApplies=1&uspString=consent2/)
expect(sync[0]).to.have.property('url').match(/https:\/\/cm\.mgid\.com\/i\.html\?cbuster=\d+&gdpr_consent=consent1&gdpr=1&us_privacy=consent2/)
});
it('should return img object with gdpr + usp', function () {
config.setConfig({userSync: {syncsPerBidder: undefined}});
const sync = spec.getUserSyncs({pixelEnabled: true}, undefined, {consentString: 'consent1', gdprApplies: true}, {'consentString': 'consent2'})
expect(sync).to.have.length(USERSYNC_DEFAULT_CONFIG.syncsPerBidder)
for (let i = 0; i < USERSYNC_DEFAULT_CONFIG.syncsPerBidder; i++) {
expect(sync[i]).to.have.property('type', 'image')
expect(sync[i]).to.have.property('url').match(/https:\/\/cm\.mgid\.com\/i\.gif\?cbuster=\d+&consentData=consent1&gdprApplies=1&uspString=consent2/)
expect(sync[i]).to.have.property('url').match(/https:\/\/cm\.mgid\.com\/i\.gif\?cbuster=\d+&gdpr_consent=consent1&gdpr=1&us_privacy=consent2/)
}
});
it('should return frame object with gdpr + usp', function () {
const sync = spec.getUserSyncs({iframeEnabled: true, pixelEnabled: true}, undefined, {consentString: 'consent1', gdprApplies: true}, {'consentString': 'consent2'})
expect(sync).to.have.length(1)
expect(sync[0]).to.have.property('type', 'iframe')
expect(sync[0]).to.have.property('url').match(/https:\/\/cm\.mgid\.com\/i\.html\?cbuster=\d+&consentData=consent1&gdprApplies=1&uspString=consent2/)
expect(sync[0]).to.have.property('url').match(/https:\/\/cm\.mgid\.com\/i\.html\?cbuster=\d+&gdpr_consent=consent1&gdpr=1&us_privacy=consent2/)
});
it('should return img (pixels) objects with gdpr + usp', function () {
const response = [{body: {ext: {cm: ['http://cm.mgid.com/i.gif?cdsp=1111', 'http://cm.mgid.com/i.gif']}}}]
const sync = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: true}, response, {consentString: 'consent1', gdprApplies: true}, {'consentString': 'consent2'})
expect(sync).to.have.length(2)
expect(sync[0]).to.have.property('type', 'image')
expect(sync[0]).to.have.property('url').match(/http:\/\/cm\.mgid\.com\/i\.gif\?cdsp=1111&cbuster=\d+&consentData=consent1&gdprApplies=1&uspString=consent2/)
expect(sync[0]).to.have.property('url').match(/http:\/\/cm\.mgid\.com\/i\.gif\?cdsp=1111&cbuster=\d+&gdpr_consent=consent1&gdpr=1&us_privacy=consent2/)
expect(sync[1]).to.have.property('type', 'image')
expect(sync[1]).to.have.property('url').match(/http:\/\/cm\.mgid\.com\/i\.gif\?cbuster=\d+&consentData=consent1&gdprApplies=1&uspString=consent2/)
expect(sync[1]).to.have.property('url').match(/http:\/\/cm\.mgid\.com\/i\.gif\?cbuster=\d+&gdpr_consent=consent1&gdpr=1&us_privacy=consent2/)
});
});

Expand All @@ -874,9 +874,9 @@ describe('Mgid bid adapter', function () {
const sync = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: true}, response, {consentString: 'consent1', gdprApplies: true}, {'consentString': 'consent2'}, {gppString: 'gpp'})
expect(sync).to.have.length(2)
expect(sync[0]).to.have.property('type', 'image')
expect(sync[0]).to.have.property('url').match(/http:\/\/cm\.mgid\.com\/i\.gif\?cdsp=1111&cbuster=\d+&consentData=consent1&gdprApplies=1&uspString=consent2&gppString=gpp&coppa=1/)
expect(sync[0]).to.have.property('url').match(/http:\/\/cm\.mgid\.com\/i\.gif\?cdsp=1111&cbuster=\d+&gdpr_consent=consent1&gdpr=1&us_privacy=consent2&gppString=gpp&coppa=1/)
expect(sync[1]).to.have.property('type', 'image')
expect(sync[1]).to.have.property('url').match(/http:\/\/cm\.mgid\.com\/i\.gif\?cbuster=\d+&consentData=consent1&gdprApplies=1&uspString=consent2&gppString=gpp&coppa=1/)
expect(sync[1]).to.have.property('url').match(/http:\/\/cm\.mgid\.com\/i\.gif\?cbuster=\d+&gdpr_consent=consent1&gdpr=1&us_privacy=consent2&gppString=gpp&coppa=1/)
});
});

Expand Down