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

Add warning messages for publishers while native ads send assets containing url without sendId #5096

Merged
merged 2 commits into from
Apr 22, 2020
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
18 changes: 16 additions & 2 deletions modules/criteoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import { verify } from 'criteo-direct-rsa-validate/build/verify.js';
import { getStorageManager } from '../src/storageManager.js';

const GVLID = 91;
export const ADAPTER_VERSION = 27;
export const ADAPTER_VERSION = 28;
const BIDDER_CODE = 'criteo';
const CDB_ENDPOINT = 'https://bidder.criteo.com/cdb';
const CRITEO_VENDOR_ID = 91;
const PROFILE_ID_INLINE = 207;
export const PROFILE_ID_PUBLISHERTAG = 185;
const storage = getStorageManager(GVLID);
const LOG_PREFIX = 'Criteo: ';

// Unminified source code can be found in: https://github.com/Prebid-org/prebid-js-external-js-criteo/blob/master/dist/prod.js
const PUBLISHER_TAG_URL = 'https://static.criteo.net/js/ld/publishertag.prebid.js';
Expand Down Expand Up @@ -245,6 +246,16 @@ function buildCdbUrl(context) {
return url;
}

function checkNativeSendId(bidRequest) {
return !(bidRequest.nativeParams &&
((bidRequest.nativeParams.image && bidRequest.nativeParams.image.sendId !== true) ||
(bidRequest.nativeParams.icon && bidRequest.nativeParams.icon.sendId !== true) ||
(bidRequest.nativeParams.clickUrl && bidRequest.nativeParams.clickUrl.sendId !== true) ||
(bidRequest.nativeParams.displayUrl && bidRequest.nativeParams.displayUrl.sendId !== true) ||
(bidRequest.nativeParams.privacyLink && bidRequest.nativeParams.privacyLink.sendId !== true) ||
(bidRequest.nativeParams.privacyIcon && bidRequest.nativeParams.privacyIcon.sendId !== true)));
}

/**
* @param {CriteoContext} context
* @param {BidRequest[]} bidRequests
Expand Down Expand Up @@ -279,6 +290,9 @@ function buildCdbRequest(context, bidRequests, bidderRequest) {
}
if (bidRequest.params.nativeCallback || utils.deepAccess(bidRequest, `mediaTypes.${NATIVE}`)) {
slot.native = true;
if (!checkNativeSendId(bidRequest)) {
utils.logWarn(LOG_PREFIX + 'all native assets containing URL should be sent as placeholders with sendId(icon, image, clickUrl, displayUrl, privacyLink, privacyIcon)');
}
}
if (hasVideoMediaType(bidRequest)) {
const video = {
Expand All @@ -287,7 +301,7 @@ function buildCdbRequest(context, bidRequests, bidderRequest) {
protocols: bidRequest.mediaTypes.video.protocols,
maxduration: bidRequest.mediaTypes.video.maxduration,
api: bidRequest.mediaTypes.video.api
}
};

video.skip = bidRequest.params.video.skip;
video.placement = bidRequest.params.video.placement;
Expand Down
130 changes: 128 additions & 2 deletions test/spec/modules/criteoBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import { tryGetCriteoFastBid, spec, PROFILE_ID_PUBLISHERTAG, ADAPTER_VERSION, PUBLISHER_TAG_URL } from 'modules/criteoBidAdapter.js';
import { tryGetCriteoFastBid, spec, PROFILE_ID_PUBLISHERTAG, ADAPTER_VERSION } from 'modules/criteoBidAdapter.js';
import { createBid } from 'src/bidfactory.js';
import CONSTANTS from 'src/constants.json';
import * as utils from 'src/utils.js';
Expand Down Expand Up @@ -533,7 +533,7 @@ describe('The Criteo bidding adapter', function () {
expect(ortbRequest.gdprConsent).to.equal(undefined);
});

it('should properly build request with undefined gdpr consent fields when they are not provided', function () {
it('should properly build a request with undefined gdpr consent fields when they are not provided', function () {
const bidRequests = [
{
bidder: 'criteo',
Expand Down Expand Up @@ -1166,6 +1166,132 @@ describe('The Criteo bidding adapter', function () {
});
});

describe('when pubtag prebid adapter is not available', function () {
it('should not warn if sendId is provided on required fields for native bidRequest', () => {
const bidderRequest = { };
const bidRequestsWithSendId = [
{
bidder: 'criteo',
adUnitCode: 'bid-123',
transactionId: 'transaction-123',
sizes: [[728, 90]],
params: {
zoneId: 123,
publisherSubId: '123',
nativeCallback: function() {}
},
nativeParams: {
image: {
sendId: true
},
icon: {
sendId: true
},
clickUrl: {
sendId: true
},
displayUrl: {
sendId: true
},
privacyLink: {
sendId: true
},
privacyIcon: {
sendId: true
}
}
}
];

utilsMock.expects('logWarn').withArgs('Criteo: all native assets containing URL should be sent as placeholders with sendId(icon, image, clickUrl, displayUrl, privacyLink, privacyIcon)').never();
const request = spec.buildRequests(bidRequestsWithSendId, bidderRequest);
utilsMock.verify();
});

it('should warn only once if sendId is not provided on required fields for native bidRequest', () => {
const bidderRequest = { };
const bidRequests = [
{
bidder: 'criteo',
adUnitCode: 'bid-123',
transactionId: 'transaction-123',
sizes: [[728, 90]],
params: {
zoneId: 123,
publisherSubId: '123',
nativeCallback: function() {}
},
},
{
bidder: 'criteo',
adUnitCode: 'bid-456',
transactionId: 'transaction-456',
sizes: [[728, 90]],
params: {
zoneId: 456,
publisherSubId: '456',
nativeCallback: function() {}
},
},
];

const nativeParamsWithoutSendId = [
{
nativeParams: {
image: {
sendId: false
},
}
},
{
nativeParams: {
icon: {
sendId: false
},
}
},
{
nativeParams: {
clickUrl: {
sendId: false
},
}
},
{
nativeParams: {
displayUrl: {
sendId: false
},
}
},
{
nativeParams: {
privacyLink: {
sendId: false
},
}
},
{
nativeParams: {
privacyIcon: {
sendId: false
},
}
}
];

utilsMock.expects('logWarn')
.withArgs('Criteo: all native assets containing URL should be sent as placeholders with sendId(icon, image, clickUrl, displayUrl, privacyLink, privacyIcon)')
.exactly(nativeParamsWithoutSendId.length * bidRequests.length);
nativeParamsWithoutSendId.forEach(nativeParams => {
let transformedBidRequests = {...bidRequests};
transformedBidRequests = [Object.assign(transformedBidRequests[0], nativeParams), Object.assign(transformedBidRequests[1], nativeParams)];
spec.buildRequests(transformedBidRequests, bidderRequest);
});
utilsMock.verify();
});
});

describe('when pubtag prebid adapter is available', function () {
it('should forward response to pubtag when calling interpretResponse', () => {
const response = {};
Expand Down