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

Qc/qc usersyncs #4923

Merged
merged 2 commits into from
Apr 14, 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
23 changes: 23 additions & 0 deletions modules/quantcastBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as utils from '../src/utils.js';
import { ajax } from '../src/ajax.js';
import { config } from '../src/config.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import find from 'core-js/library/fn/array/find.js';

const BIDDER_CODE = 'quantcast';
const DEFAULT_BID_FLOOR = 0.0000000001;
Expand Down Expand Up @@ -79,6 +80,7 @@ function getDomain(url) {
export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: ['banner', 'video'],
hasUserSynced: false,

/**
* Verify the `AdUnits.bids` response with `true` for valid request and `false`
Expand Down Expand Up @@ -221,6 +223,27 @@ export const spec = {
onTimeout(timeoutData) {
const url = `${QUANTCAST_PROTOCOL}://${QUANTCAST_DOMAIN}:${QUANTCAST_PORT}/qchb_notify?type=timeout`;
ajax(url, null, null);
},
getUserSyncs(syncOptions, serverResponses) {
const syncs = []
if (!this.hasUserSynced && syncOptions.pixelEnabled) {
const responseWithUrl = find(serverResponses, serverResponse =>
utils.deepAccess(serverResponse.body, 'userSync.url')
);

if (responseWithUrl) {
const url = utils.deepAccess(responseWithUrl.body, 'userSync.url')
syncs.push({
type: 'image',
url: url
});
}
this.hasUserSynced = true;
}
return syncs;
},
resetUserSync() {
this.hasUserSynced = false;
}
};

Expand Down
10 changes: 8 additions & 2 deletions modules/quantcastBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ const adUnits = [{
battr: [1, 2] // OPTIONAL - Array of blocked creative attributes as per OpenRTB Spec List 5.3
}
}
]
],
userSync: {
url: 'https://quantcast.com/pixelUrl'
}
}];
```

Expand Down Expand Up @@ -63,6 +66,9 @@ var adUnits = [{
}
}
}
]
],
userSync: {
url: 'https://quantcast.com/pixelUrl'
}
}];
```
62 changes: 62 additions & 0 deletions test/spec/modules/quantcastBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,5 +492,67 @@ describe('Quantcast adapter', function () {

expect(interpretedResponse.length).to.equal(0);
});

it('should return pixel url when available userSync available', function () {
const syncOptions = {
pixelEnabled: true
};
const serverResponses = [
{
body: {
userSync: {
url: 'http://quantcast.com/pixelUrl'
}
}
},
{
body: {

}
}
];

const actualSyncs = qcSpec.getUserSyncs(syncOptions, serverResponses);
const expectedSync = {
type: 'image',
url: 'http://quantcast.com/pixelUrl'
};
expect(actualSyncs.length).to.equal(1);
expect(actualSyncs[0]).to.deep.equal(expectedSync);
qcSpec.resetUserSync();
});

it('should not return user syncs if done already', function () {
const syncOptions = {
pixelEnabled: true
};
const serverResponses = [
{
body: {
userSync: {
url: 'http://quantcast.com/pixelUrl'
}
}
},
{
body: {

}
}
];

let actualSyncs = qcSpec.getUserSyncs(syncOptions, serverResponses);
const expectedSync = {
type: 'image',
url: 'http://quantcast.com/pixelUrl'
};
expect(actualSyncs.length).to.equal(1);
expect(actualSyncs[0]).to.deep.equal(expectedSync);

actualSyncs = qcSpec.getUserSyncs(syncOptions, serverResponses);
expect(actualSyncs.length).to.equal(0);

qcSpec.resetUserSync();
});
});
});