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

Finative bid Adapter: initial release #8557

Merged
merged 29 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7281e54
add seedingAlliance Adapter
sag-jonhil Dec 17, 2019
4612570
Merge pull request #1 from prebid/master
Jan 24, 2020
043b2a0
add two native default params
sag-jonhil Feb 11, 2020
bd9a1cd
...
sag-jonhil Feb 11, 2020
bfe4fdf
...
sag-jonhil Feb 11, 2020
4e6e34a
Merge pull request #2 from prebid/master
Feb 11, 2020
1771978
seedingAlliance Adapter: add two more default native params
sag-jonhil Feb 11, 2020
a193ea7
Merge branch 'seedingAlliance' of https://github.com/SeedingAllianceT…
sag-jonhil Feb 11, 2020
39feec3
Merge pull request #3 from prebid/master
Jul 20, 2020
4036c82
Merge branch 'master' into seedingAlliance
sag-jonhil Jul 20, 2020
717c487
updating seedingAlliance Adapter
sag-jonhil Jul 20, 2020
d7840c3
Merge pull request #4 from prebid/master
Sep 15, 2021
351a503
fix for merge
sag-jonhil Sep 15, 2021
29dd4db
Merge pull request #6 from prebid/master
Sep 16, 2021
c77748b
Merge branch 'master' into seedingAlliance
sag-jonhil Sep 16, 2021
26eaa2b
seedingAlliance Adapter
sag-jonhil Sep 16, 2021
5dd6c15
Merge pull request #7 from prebid/master
Jan 7, 2022
85072ca
Merge branch 'seedingAlliance' into master
Jan 7, 2022
bb4d1b0
Merge pull request #8 from SeedingAllianceTech/master
Jan 7, 2022
94d9903
quickfix no bids + net revenue
sag-jonhil Jan 7, 2022
097defa
Merge pull request #9 from prebid/master
Apr 5, 2022
993d60c
Merge branch 'master' into seedingAlliance
sag-jonhil Apr 5, 2022
ab915a0
bugfix replace auction price
sag-jonhil Apr 5, 2022
df192cc
Merge pull request #10 from prebid/master
Apr 19, 2022
1ea4f03
Merge branch 'master' into seedingAlliance
sag-jonhil Apr 19, 2022
4fb76aa
change URL and add versioning
sag-jonhil Apr 19, 2022
0d48075
add Finative Adapter
sag-henmus Jun 8, 2022
73fea98
Rename Test
sag-henmus Jun 13, 2022
725fc91
Add proper testing params
sag-henmus Jun 14, 2022
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
235 changes: 235 additions & 0 deletions modules/finativeBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
// jshint esversion: 6, es3: false, node: true
'use strict';

import { registerBidder } from '../src/adapters/bidderFactory.js';
import { NATIVE } from '../src/mediaTypes.js';
import { _map, deepSetValue, isEmpty, deepAccess } from '../src/utils.js';
import { config } from '../src/config.js';

const BIDDER_CODE = 'finative';
const DEFAULT_CUR = 'EUR';
const ENDPOINT_URL = 'https://b.finative.cloud/cds/rtb/bid?format=openrtb2.5&ssp=pb';

const NATIVE_ASSET_IDS = {0: 'title', 1: 'body', 2: 'sponsoredBy', 3: 'image', 4: 'cta', 5: 'icon'};

const NATIVE_PARAMS = {
title: {
id: 0,
name: 'title'
},

body: {
id: 1,
name: 'data',
type: 2
},

sponsoredBy: {
id: 2,
name: 'data',
type: 1
},

image: {
id: 3,
type: 3,
name: 'img'
},

cta: {
id: 4,
type: 12,
name: 'data'
},

icon: {
id: 5,
type: 1,
name: 'img'
}
};

export const spec = {
code: BIDDER_CODE,

supportedMediaTypes: [NATIVE],

isBidRequestValid: function(bid) {
return !!bid.params.adUnitId;
},

buildRequests: (validBidRequests, bidderRequest) => {
const pt = setOnAny(validBidRequests, 'params.pt') || setOnAny(validBidRequests, 'params.priceType') || 'net';
const tid = validBidRequests[0].transactionId;
const cur = [config.getConfig('currency.adServerCurrency') || DEFAULT_CUR];
let url = bidderRequest.refererInfo.referer;

const imp = validBidRequests.map((bid, id) => {
const assets = _map(bid.nativeParams, (bidParams, key) => {
const props = NATIVE_PARAMS[key];

const asset = {
required: bidParams.required & 1
};

if (props) {
asset.id = props.id;

let w, h;

if (bidParams.sizes) {
w = bidParams.sizes[0];
h = bidParams.sizes[1];
}

asset[props.name] = {
len: bidParams.len,
type: props.type,
w,
h
};

return asset;
}
})
.filter(Boolean);

if (bid.params.url) {
url = bid.params.url;
}

return {
id: String(id + 1),
tagid: bid.params.adUnitId,
tid: tid,
pt: pt,
native: {
request: {
assets
}
}
};
});

const request = {
id: bidderRequest.auctionId,
site: {
page: url
},
device: {
ua: navigator.userAgent
},
cur,
imp,
user: {},
regs: {
ext: {
gdpr: 0,
pb_ver: '$prebid.version$'
}
}
};

if (bidderRequest && bidderRequest.gdprConsent) {
deepSetValue(request, 'user.ext.consent', bidderRequest.gdprConsent.consentString);
deepSetValue(request, 'regs.ext.gdpr', (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean' && bidderRequest.gdprConsent.gdprApplies) ? 1 : 0);
}

return {
method: 'POST',
url: ENDPOINT_URL,
data: JSON.stringify(request),
options: {
contentType: 'application/json'
},
bids: validBidRequests
};
},

interpretResponse: function(serverResponse, { bids }) {
if (isEmpty(serverResponse.body)) {
return [];
}

const { seatbid, cur } = serverResponse.body;

const bidResponses = (typeof seatbid != 'undefined') ? flatten(seatbid.map(seat => seat.bid)).reduce((result, bid) => {
result[bid.impid - 1] = bid;
return result;
}, []) : [];

return bids
.map((bid, id) => {
const bidResponse = bidResponses[id];

if (bidResponse) {
return {
requestId: bid.bidId,
cpm: bidResponse.price,
creativeId: bidResponse.crid,
ttl: 1000,
netRevenue: (!bid.netRevenue || bid.netRevenue === 'net'),
currency: cur,
mediaType: NATIVE,
bidderCode: BIDDER_CODE,
native: parseNative(bidResponse),
meta: {
advertiserDomains: bidResponse.adomain && bidResponse.adomain.length > 0 ? bidResponse.adomain : []
}
};
}
})
.filter(Boolean);
}
};

registerBidder(spec);

function parseNative(bid) {
const {assets, link, imptrackers} = bid.adm.native;

let clickUrl = link.url.replace(/\$\{AUCTION_PRICE\}/g, bid.price);

if (link.clicktrackers) {
link.clicktrackers.forEach(function (clicktracker, index) {
link.clicktrackers[index] = clicktracker.replace(/\$\{AUCTION_PRICE\}/g, bid.price);
});
}

if (imptrackers) {
imptrackers.forEach(function (imptracker, index) {
imptrackers[index] = imptracker.replace(/\$\{AUCTION_PRICE\}/g, bid.price);
});
}

const result = {
url: clickUrl,
clickUrl: clickUrl,
clickTrackers: link.clicktrackers || undefined,
impressionTrackers: imptrackers || undefined
};

assets.forEach(asset => {
const kind = NATIVE_ASSET_IDS[asset.id];
const content = kind && asset[NATIVE_PARAMS[kind].name];

if (content) {
result[kind] = content.text || content.value || { url: content.url, width: content.w, height: content.h };
}
});

return result;
}

function setOnAny(collection, key) {
for (let i = 0, result; i < collection.length; i++) {
result = deepAccess(collection[i], key);
if (result) {
return result;
}
}
}

function flatten(arr) {
return [].concat(...arr);
}
45 changes: 45 additions & 0 deletions modules/finativeBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Overview
Module Name: Finative Bidder Adapter
Type: Finative Adapter
Maintainer: [email protected]

# Description
Finative Bidder Adapter for Prebid.js.

# Test Parameters
```
var adUnits = [{
code: 'test-div',

mediaTypes: {
native: {
title: {
required: true,
len: 50
},
body: {
required: true,
len: 350
},
url: {
required: true
},
image: {
required: true,
sizes : [300, 175]
},
sponsoredBy: {
required: true
}
}
},
bids: [{
bidder: 'finative',
params: {
url : "https://mockup.finative.cloud",
adUnitId: "1uyo"
}
}]
}];
```

12 changes: 8 additions & 4 deletions modules/seedingAllianceBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { config } from '../src/config.js';

const BIDDER_CODE = 'seedingAlliance';
const DEFAULT_CUR = 'EUR';
const ENDPOINT_URL = 'https://b.nativendo.de/cds/rtb/bid?format=openrtb2.5&ssp=nativendo';
const ENDPOINT_URL = 'https://b.nativendo.de/cds/rtb/bid?format=openrtb2.5&ssp=pb';

const NATIVE_ASSET_IDS = {0: 'title', 1: 'body', 2: 'sponsoredBy', 3: 'image', 4: 'cta', 5: 'icon'};

Expand Down Expand Up @@ -124,7 +124,8 @@ export const spec = {
user: {},
regs: {
ext: {
gdpr: 0
gdpr: 0,
pb_ver: '$prebid.version$'
}
}
};
Expand Down Expand Up @@ -187,20 +188,23 @@ registerBidder(spec);
function parseNative(bid) {
const {assets, link, imptrackers} = bid.adm.native;

let clickUrl = link.url.replace(/\$\{AUCTION_PRICE\}/g, bid.price);

if (link.clicktrackers) {
link.clicktrackers.forEach(function (clicktracker, index) {
link.clicktrackers[index] = clicktracker.replace(/\$\{AUCTION_PRICE\}/g, bid.price);
});
}

if (imptrackers) {
imptrackers.forEach(function (imptracker, index) {
imptrackers[index] = imptracker.replace(/\$\{AUCTION_PRICE\}/g, bid.price);
});
}

const result = {
url: link.url,
clickUrl: link.url,
url: clickUrl,
clickUrl: clickUrl,
clickTrackers: link.clicktrackers || undefined,
impressionTrackers: imptrackers || undefined
};
Expand Down
Loading