Skip to content

Commit

Permalink
Qc/qc usersyncs (prebid#4923)
Browse files Browse the repository at this point in the history
* QC adapter. support usersyncs

* cache user sync
  • Loading branch information
SleimanJneidi authored and iggyfisk committed Jun 22, 2020
1 parent fe013bd commit a104aec
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 2 deletions.
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 @@ -80,6 +81,7 @@ export const spec = {
code: BIDDER_CODE,
GVLID: 11,
supportedMediaTypes: ['banner', 'video'],
hasUserSynced: false,

/**
* Verify the `AdUnits.bids` response with `true` for valid request and `false`
Expand Down Expand Up @@ -223,6 +225,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 @@ -542,5 +542,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();
});
});
});

0 comments on commit a104aec

Please sign in to comment.