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

CM-864 - dd index id support #18

Closed
wants to merge 4 commits into from
Closed
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
3 changes: 2 additions & 1 deletion modules/.submodules.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"zeotapIdPlusIdSystem",
"adqueryIdSystem",
"gravitoIdSystem",
"freepassIdSystem"
"freepassIdSystem",
"operaadsIdSystem"
],
"adpod": [
"freeWheelAdserverVideo",
Expand Down
2 changes: 2 additions & 0 deletions modules/adrelevantisBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,8 @@ function parseMediaType(rtbBid) {
const adType = rtbBid.ad_type;
if (adType === VIDEO) {
return VIDEO;
} else if (adType === NATIVE) {
return NATIVE;
} else {
return BANNER;
}
Expand Down
106 changes: 64 additions & 42 deletions modules/criteoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { loadExternalScript } from '../src/adloader.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js';
import { find } from '../src/polyfill.js';
import { verify } from 'criteo-direct-rsa-validate/build/verify.js'; // ref#2
import { getStorageManager } from '../src/storageManager.js';
import { getRefererInfo } from '../src/refererDetection.js';
Expand Down Expand Up @@ -219,51 +218,53 @@ export const spec = {

if (body && body.slots && isArray(body.slots)) {
body.slots.forEach(slot => {
const bidRequest = find(request.bidRequests, b => b.adUnitCode === slot.impid && (!b.params.zoneId || parseInt(b.params.zoneId) === slot.zoneid));
const bidId = bidRequest.bidId;
const bid = {
requestId: bidId,
cpm: slot.cpm,
currency: slot.currency,
netRevenue: true,
ttl: slot.ttl || 60,
creativeId: slot.creativecode,
width: slot.width,
height: slot.height,
dealId: slot.deal,
};
if (body.ext?.paf?.transmission && slot.ext?.paf?.content_id) {
const pafResponseMeta = {
content_id: slot.ext.paf.content_id,
transmission: response.ext.paf.transmission
const bidRequest = getAssociatedBidRequest(request.bidRequests, slot);
if (bidRequest) {
const bidId = bidRequest.bidId;
const bid = {
requestId: bidId,
cpm: slot.cpm,
currency: slot.currency,
netRevenue: true,
ttl: slot.ttl || 60,
creativeId: slot.creativecode,
width: slot.width,
height: slot.height,
dealId: slot.deal,
};
bid.meta = Object.assign({}, bid.meta, { paf: pafResponseMeta });
}
if (slot.adomain) {
bid.meta = Object.assign({}, bid.meta, { advertiserDomains: [slot.adomain].flat() });
}
if (slot.ext?.meta?.networkName) {
bid.meta = Object.assign({}, bid.meta, { networkName: slot.ext.meta.networkName })
}
if (slot.native) {
if (bidRequest.params.nativeCallback) {
bid.ad = createNativeAd(bidId, slot.native, bidRequest.params.nativeCallback);
} else {
bid.native = createPrebidNativeAd(slot.native);
bid.mediaType = NATIVE;
if (body.ext?.paf?.transmission && slot.ext?.paf?.content_id) {
const pafResponseMeta = {
content_id: slot.ext.paf.content_id,
transmission: response.ext.paf.transmission
};
bid.meta = Object.assign({}, bid.meta, { paf: pafResponseMeta });
}
} else if (slot.video) {
bid.vastUrl = slot.displayurl;
bid.mediaType = VIDEO;
const context = deepAccess(bidRequest, 'mediaTypes.video.context');
// if outstream video, add a default render for it.
if (context === OUTSTREAM) {
bid.renderer = createOutstreamVideoRenderer(slot);
if (slot.adomain) {
bid.meta = Object.assign({}, bid.meta, { advertiserDomains: [slot.adomain].flat() });
}
} else {
bid.ad = slot.creative;
if (slot.ext?.meta?.networkName) {
bid.meta = Object.assign({}, bid.meta, { networkName: slot.ext.meta.networkName })
}
if (slot.native) {
if (bidRequest.params.nativeCallback) {
bid.ad = createNativeAd(bidId, slot.native, bidRequest.params.nativeCallback);
} else {
bid.native = createPrebidNativeAd(slot.native);
bid.mediaType = NATIVE;
}
} else if (slot.video) {
bid.vastUrl = slot.displayurl;
bid.mediaType = VIDEO;
const context = deepAccess(bidRequest, 'mediaTypes.video.context');
// if outstream video, add a default render for it.
if (context === OUTSTREAM) {
bid.renderer = createOutstreamVideoRenderer(slot);
}
} else {
bid.ad = slot.creative;
}
bids.push(bid);
}
bids.push(bid);
});
}

Expand Down Expand Up @@ -786,6 +787,27 @@ function createOutstreamVideoRenderer(slot) {
return renderer;
}

function getAssociatedBidRequest(bidRequests, slot) {
for (const request of bidRequests) {
if (request.adUnitCode === slot.impid) {
if (request.params.zoneId && parseInt(request.params.zoneId) === slot.zoneid) {
return request;
} else if (slot.native) {
if (request.mediaTypes?.native || request.nativeParams) {
return request;
}
} else if (slot.video) {
if (request.mediaTypes?.video) {
return request;
}
} else if (request.mediaTypes?.banner || request.sizes) {
return request;
}
}
}
return undefined;
}

export function tryGetCriteoFastBid() {
// begin ref#1
try {
Expand Down
17 changes: 16 additions & 1 deletion modules/liveIntentIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ export const liveIntentIdSubmodule = {
result.magnite = { 'id': value.magnite, ext: { provider: LI_PROVIDER_DOMAIN } }
}

if (value.index) {
result.index = { 'id': value.index, ext: { provider: LI_PROVIDER_DOMAIN } }
}

return result
}

Expand Down Expand Up @@ -294,7 +298,18 @@ export const liveIntentIdSubmodule = {
}
}
},

'index': {
source: 'indexexchange.com',
atype: 3,
getValue: function(data) {
return data.id;
},
getUidExt: function(data) {
if (data.ext) {
return data.ext;
}
}
}
}
};

Expand Down
5 changes: 5 additions & 0 deletions modules/operaadsBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,11 @@ function mapNativeImage(image, type) {
* @returns {String} userId
*/
function getUserId(bidRequest) {
let operaId = deepAccess(bidRequest, 'userId.operaId');
if (operaId) {
return operaId;
}

let sharedId = deepAccess(bidRequest, 'userId.sharedid.id');
if (sharedId) {
return sharedId;
Expand Down
10 changes: 5 additions & 5 deletions modules/operaadsBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,18 @@ var adUnits = [{

### User Ids

Opera Ads Bid Adapter uses `sharedId`, `pubcid` or `tdid`, please config at least one.
Opera Ads Bid Adapter uses `operaId`, please refer to [`Opera ID System`](./operaadsIdSystem.md).

```javascript
pbjs.setConfig({
...,
userSync: {
userIds: [{
name: 'sharedId',
name: 'operaId',
storage: {
name: '_sharedID', // name of the 1st party cookie
type: 'cookie',
expires: 30
name: 'operaId',
type: 'html5',
expires: 14
}
}]
}
Expand Down
106 changes: 106 additions & 0 deletions modules/operaadsIdSystem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/**
* This module adds operaId to the User ID module
* The {@link module:modules/userId} module is required
* @module modules/operaadsIdSystem
* @requires module:modules/userId
*/
import * as ajax from '../src/ajax.js';
import { submodule } from '../src/hook.js';
import { logMessage, logError } from '../src/utils.js';

const MODULE_NAME = 'operaId';
const ID_KEY = MODULE_NAME;
const version = '1.0';
const SYNC_URL = 'https://t.adx.opera.com/identity/';
const AJAX_TIMEOUT = 300;
const AJAX_OPTIONS = {method: 'GET', withCredentials: true, contentType: 'application/json'};

function constructUrl(pairs) {
const queries = [];
for (let key in pairs) {
queries.push(`${key}=${encodeURIComponent(pairs[key])}`);
}
return `${SYNC_URL}?${queries.join('&')}`;
}

function asyncRequest(url, cb) {
ajax.ajaxBuilder(AJAX_TIMEOUT)(
url,
{
success: response => {
try {
const jsonResponse = JSON.parse(response);
const { uid: operaId } = jsonResponse;
cb(operaId);
return;
} catch (e) {
logError(`${MODULE_NAME}: invalid response`, response);
}
cb();
},
error: (err) => {
logError(`${MODULE_NAME}: ID error response`, err);
cb();
}
},
null,
AJAX_OPTIONS
);
}

export const operaIdSubmodule = {
/**
* used to link submodule with config
* @type {string}
*/
name: MODULE_NAME,

/**
* @type {string}
*/
version,

/**
* decode the stored id value for passing to bid requests
* @function
* @param {string} id
* @returns {{'operaId': string}}
*/
decode: (id) =>
id != null && id.length > 0
? { [ID_KEY]: id }
: undefined,

/**
* performs action to obtain id and return a value in the callback's response argument
* @function
* @param {SubmoduleConfig} [config]
* @returns {IdResponse|undefined}
*/
getId(config, consentData) {
logMessage(`${MODULE_NAME}: start synchronizing opera uid`);
const params = (config && config.params) || {};
if (typeof params.pid !== 'string' || params.pid.length == 0) {
logError(`${MODULE_NAME}: submodule requires a publisher ID to be defined`);
return;
}

const { pid, syncUrl = SYNC_URL } = params;
const url = constructUrl(syncUrl, { publisherId: pid });

return {
callback: (cb) => {
asyncRequest(url, cb);
}
}
},

eids: {
'operaId': {
source: 't.adx.opera.com',
atype: 1
},
}
};

submodule('userId', operaIdSubmodule);
52 changes: 52 additions & 0 deletions modules/operaadsIdSystem.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Opera ID System

For help adding this module, please contact [adtech-prebid-group@opera.com](adtech-prebid-group@opera.com).

### Prebid Configuration

You should configure this module under your `userSync.userIds[]` configuration:

```javascript
pbjs.setConfig({
userSync: {
userIds: [
{
name: "operaId",
storage: {
name: "operaId",
type: "html5",
expires: 14
},
params: {
pid: "your-pulisher-ID-here"
}
}
]
}
})
```
<br>

| Param under `userSync.userIds[]` | Scope | Type | Description | Example |
| -------------------------------- | -------- | ------ | ----------------------------- | ----------------------------------------- |
| name | Required | string | ID for the operaId module | `"operaId"` |
| storage | Optional | Object | Settings for operaId storage | See [storage settings](#storage-settings) |
| params | Required | Object | Parameters for opreaId module | See [params](#params) |
<br>

### Params

| Param under `params` | Scope | Type | Description | Example |
| -------------------- | -------- | ------ | ------------------------------ | --------------- |
| pid | Required | string | Publisher ID assigned by Opera | `"pub12345678"` |
<br>

### Storage Settings

The following settings are suggested for the `storage` property in the `userSync.userIds[]` object:

| Param under `storage` | Type | Description | Example |
| --------------------- | ------------- | -------------------------------------------------------------------------------- | ----------- |
| name | String | Where the ID will be stored | `"operaId"` |
| type | String | For best performance, this should be `"html5"` | `"html5"` |
| expires | Number <= 30 | number of days until the stored ID expires. **Must be less than or equal to 30** | `14` |
Loading