Skip to content
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
141 changes: 141 additions & 0 deletions libraries/vizionikUtils/vizionikUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import { hasPurpose1Consent } from '../../src/utils/gdpr.js';
import { BANNER, VIDEO } from '../../src/mediaTypes.js';
import { deepAccess, isArray, parseSizesInput } from '../../src/utils.js';

export function getUserSyncs(syncEndpoint, paramNames) {
return function(syncOptions, serverResponses, gdprConsent, uspConsent) {
const syncs = [];

if (!hasPurpose1Consent(gdprConsent)) {
return syncs;
}

let params = `${paramNames?.usp ?? 'us_privacy'}=${uspConsent ?? ''}&${paramNames?.consent ?? 'gdpr_consent'}=${gdprConsent?.consentString ?? ''}`;

if (typeof gdprConsent?.gdprApplies === 'boolean') {
params += `&gdpr=${Number(gdprConsent.gdprApplies)}`;
}

if (syncOptions.iframeEnabled) {
syncs.push({
type: 'iframe',
url: `//${syncEndpoint}/match/sp.ifr?${params}`,
});
}

if (syncOptions.pixelEnabled) {
syncs.push({
type: 'image',
url: `//${syncEndpoint}/match/sp?${params}`,
});
}

return syncs;
}
}

export function sspInterpretResponse(ttl, adomain) {
return function(serverResponse, request) {
if (!serverResponse?.body?.content?.data) {
return [];
}

const bidResponses = [];
const body = serverResponse.body;

let mediaType = BANNER;
let ad, vastXml;
let width;
let height;

const sizes = getSize(body.size);
if (isArray(sizes)) {
[width, height] = sizes;
}

if (body.type.format != '') {
// banner
ad = body.content.data;
if (body.content.imps?.length) {
for (const imp of body.content.imps) {
ad += `<script src="${imp}"></script>`;
}
}
} else {
// video
vastXml = body.content.data;
mediaType = VIDEO;

if (!width || !height) {
const pSize = deepAccess(request.bidRequest, 'mediaTypes.video.playerSize');
const reqSize = getSize(pSize);
if (isArray(reqSize)) {
[width, height] = reqSize;
}
}
}

const bidResponse = {
requestId: request.bidRequest.bidId,
cpm: body.cpm,
currency: body.currency || 'USD',
width: parseInt(width),
height: parseInt(height),
creativeId: body.id,
netRevenue: true,
ttl: ttl,
ad: ad,
mediaType: mediaType,
vastXml: vastXml,
meta: {
advertiserDomains: [adomain],
}
};

if ((mediaType === VIDEO && request.bidRequest.mediaTypes?.video) || (mediaType === BANNER && request.bidRequest.mediaTypes?.banner)) {
bidResponses.push(bidResponse);
}

return bidResponses;
}
}

export function sspBuildRequests(defaultEndpoint) {
return function(validBidRequests, bidderRequest) {
const requests = [];
for (const bid of validBidRequests) {
const endpoint = bid.params.endpoint || defaultEndpoint;

requests.push({
method: 'GET',
url: `https://${endpoint}/get`,
data: {
site_id: bid.params.siteId,
placement_id: bid.params.placementId,
prebid: true,
},
bidRequest: bid,
});
}

return requests;
}
}

export function sspValidRequest(bid) {
const valid = bid.params.siteId && bid.params.placementId;

return !!valid;
}

function getSize(paramSizes) {
const parsedSizes = parseSizesInput(paramSizes);
const sizes = parsedSizes.map(size => {
const [width, height] = size.split('x');
const w = parseInt(width, 10);
const h = parseInt(height, 10);
return [w, h];
});

return sizes[0] || null;
}
21 changes: 21 additions & 0 deletions modules/digitalcaramelBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { getUserSyncs, sspBuildRequests, sspInterpretResponse, sspValidRequest } from '../libraries/vizionikUtils/vizionikUtils.js';

const BIDDER_CODE = 'digitalcaramel';
const DEFAULT_ENDPOINT = 'ssp-asr.digitalcaramel.com';
const SYNC_ENDPOINT = 'sync.digitalcaramel.com';
const ADOMAIN = 'digitalcaramel.com';
const TIME_TO_LIVE = 360;

export const spec = {
code: BIDDER_CODE,

isBidRequestValid: sspValidRequest,
buildRequests: sspBuildRequests(DEFAULT_ENDPOINT),
interpretResponse: sspInterpretResponse(TIME_TO_LIVE, ADOMAIN),
getUserSyncs: getUserSyncs(SYNC_ENDPOINT, {usp: 'usp', consent: 'consent'}),
supportedMediaTypes: [ BANNER, VIDEO ]
}

registerBidder(spec);
46 changes: 46 additions & 0 deletions modules/digitalcaramelBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Overview

```
Module Name: Digitalcaramel Bid Adapter
Module Type: Bidder Adapter
Maintainer: tech@digitalcaramel.com
```

# Description
Connects to Digitalcaramel server for bids.
Module supports banner and video mediaType.

# Test Parameters

```
var adUnits = [{
code: '/test/div',
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
},
bids: [{
bidder: 'digitalcaramel',
params: {
siteId: 'd1d83nbdi0fs73874a0g',
placementId: 'd1d8493di0fs73874a10'
}
}]
},
{
code: '/test/div',
mediaTypes: {
video: {
playerSize: [[640, 360]]
}
},
bids: [{
bidder: 'digitalcaramel',
params: {
siteId: 'd1d83nbdi0fs73874a0g',
placementId: 'd24v2ijdi0fs73874afg'
}
}]
},];
```
142 changes: 5 additions & 137 deletions modules/programmaticaBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { hasPurpose1Consent } from '../src/utils/gdpr.js';
import { deepAccess, parseSizesInput, isArray } from '../src/utils.js';
import { getUserSyncs, sspBuildRequests, sspInterpretResponse, sspValidRequest } from '../libraries/vizionikUtils/vizionikUtils.js';

const BIDDER_CODE = 'programmatica';
const DEFAULT_ENDPOINT = 'asr.programmatica.com';
Expand All @@ -12,142 +11,11 @@ const TIME_TO_LIVE = 360;
export const spec = {
code: BIDDER_CODE,

isBidRequestValid: function(bid) {
const valid = bid.params.siteId && bid.params.placementId;

return !!valid;
},

buildRequests: function(validBidRequests, bidderRequest) {
const requests = [];
for (const bid of validBidRequests) {
const endpoint = bid.params.endpoint || DEFAULT_ENDPOINT;

requests.push({
method: 'GET',
url: `https://${endpoint}/get`,
data: {
site_id: bid.params.siteId,
placement_id: bid.params.placementId,
prebid: true,
},
bidRequest: bid,
});
}

return requests;
},

interpretResponse: function(serverResponse, request) {
if (!serverResponse?.body?.content?.data) {
return [];
}

const bidResponses = [];
const body = serverResponse.body;

let mediaType = BANNER;
let ad, vastXml;
let width;
let height;

const sizes = getSize(body.size);
if (isArray(sizes)) {
[width, height] = sizes;
}

if (body.type.format != '') {
// banner
ad = body.content.data;
if (body.content.imps?.length) {
for (const imp of body.content.imps) {
ad += `<script src="${imp}"></script>`;
}
}
} else {
// video
vastXml = body.content.data;
mediaType = VIDEO;

if (!width || !height) {
const pSize = deepAccess(request.bidRequest, 'mediaTypes.video.playerSize');
const reqSize = getSize(pSize);
if (isArray(reqSize)) {
[width, height] = reqSize;
}
}
}

const bidResponse = {
requestId: request.bidRequest.bidId,
cpm: body.cpm,
currency: body.currency || 'USD',
width: parseInt(width),
height: parseInt(height),
creativeId: body.id,
netRevenue: true,
ttl: TIME_TO_LIVE,
ad: ad,
mediaType: mediaType,
vastXml: vastXml,
meta: {
advertiserDomains: [ADOMAIN],
}
};

if ((mediaType === VIDEO && request.bidRequest.mediaTypes?.video) || (mediaType === BANNER && request.bidRequest.mediaTypes?.banner)) {
bidResponses.push(bidResponse);
}

return bidResponses;
},

getUserSyncs: function(syncOptions, serverResponses, gdprConsent, uspConsent) {
const syncs = []

if (!hasPurpose1Consent(gdprConsent)) {
return syncs;
}

let params = `usp=${uspConsent ?? ''}&consent=${gdprConsent?.consentString ?? ''}`;
if (typeof gdprConsent?.gdprApplies === 'boolean') {
params += `&gdpr=${Number(gdprConsent.gdprApplies)}`;
}

if (syncOptions.iframeEnabled) {
syncs.push({
type: 'iframe',
url: `//${SYNC_ENDPOINT}/match/sp.ifr?${params}`
});
}

if (syncOptions.pixelEnabled) {
syncs.push({
type: 'image',
url: `//${SYNC_ENDPOINT}/match/sp?${params}`
});
}

return syncs;
},

onTimeout: function(timeoutData) {},
onBidWon: function(bid) {},
onSetTargeting: function(bid) {},
onBidderError: function() {},
isBidRequestValid: sspValidRequest,
buildRequests: sspBuildRequests(DEFAULT_ENDPOINT),
interpretResponse: sspInterpretResponse(TIME_TO_LIVE, ADOMAIN),
getUserSyncs: getUserSyncs(SYNC_ENDPOINT, {usp: 'usp', consent: 'consent'}),
supportedMediaTypes: [ BANNER, VIDEO ]
}

registerBidder(spec);

function getSize(paramSizes) {
const parsedSizes = parseSizesInput(paramSizes);
const sizes = parsedSizes.map(size => {
const [width, height] = size.split('x');
const w = parseInt(width, 10);
const h = parseInt(height, 10);
return [w, h];
});

return sizes[0] || null;
}
Loading
Loading