diff --git a/integrationExamples/gpt/precisoExample.html b/integrationExamples/gpt/precisoExample.html
new file mode 100644
index 00000000000..04f44b28345
--- /dev/null
+++ b/integrationExamples/gpt/precisoExample.html
@@ -0,0 +1,170 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Basic Prebid.js Example with Preciso Bidder
+ Adslot-1
+
+
+
+
+
+
Adslot-2
+
+
+
+
+
+
diff --git a/libraries/precisoUtils/bidUtils.js b/libraries/precisoUtils/bidUtils.js
new file mode 100644
index 00000000000..95278cd1013
--- /dev/null
+++ b/libraries/precisoUtils/bidUtils.js
@@ -0,0 +1,103 @@
+import { convertOrtbRequestToProprietaryNative } from '../../src/native.js';
+import { replaceAuctionPrice } from '../../src/utils.js';
+import { ajax } from '../../src/ajax.js';
+import { consentCheck } from './bidUtilsCommon.js';
+
+export const buildRequests = (endpoint) => (validBidRequests = [], bidderRequest) => {
+ // convert Native ORTB definition to old-style prebid native definition
+ validBidRequests = convertOrtbRequestToProprietaryNative(validBidRequests);
+ var city = Intl.DateTimeFormat().resolvedOptions().timeZone;
+ let req = {
+ // bidRequest: bidderRequest,
+ id: validBidRequests[0].auctionId,
+ cur: validBidRequests[0].params.currency || ['USD'],
+ imp: validBidRequests.map(req => {
+ const { bidId, sizes } = req
+ const impValue = {
+ id: bidId,
+ bidfloor: req.params.bidFloor,
+ bidfloorcur: req.params.currency
+ }
+ if (req.mediaTypes.banner) {
+ impValue.banner = {
+ format: (req.mediaTypes.banner.sizes || sizes).map(size => {
+ return { w: size[0], h: size[1] }
+ }),
+
+ }
+ }
+ return impValue
+ }),
+ user: {
+ id: validBidRequests[0].userId.pubcid || '',
+ buyeruid: validBidRequests[0].buyerUid || '',
+ geo: {
+ country: validBidRequests[0].params.region || city,
+ region: validBidRequests[0].params.region || city,
+ },
+
+ },
+ device: validBidRequests[0].ortb2.device,
+ site: validBidRequests[0].ortb2.site,
+ source: validBidRequests[0].ortb2.source,
+ bcat: validBidRequests[0].ortb2.bcat || validBidRequests[0].params.bcat,
+ badv: validBidRequests[0].ortb2.badv || validBidRequests[0].params.badv,
+ wlang: validBidRequests[0].ortb2.wlang || validBidRequests[0].params.wlang,
+ };
+ if (req.device && req.device != 'undefined') {
+ req.device.geo = {
+ country: req.user.geo.country,
+ region: req.user.geo.region,
+
+ };
+ };
+ req.site.publisher = {
+ publisherId: validBidRequests[0].params.publisherId
+ };
+
+ // req.language.indexOf('-') != -1 && (req.language = req.language.split('-')[0])
+ consentCheck(bidderRequest, req);
+ return {
+ method: 'POST',
+ url: endpoint,
+ data: req,
+
+ };
+}
+
+export function interpretResponse(serverResponse) {
+ const bidsValue = []
+ const bidResponse = serverResponse.body
+ bidResponse.seatbid.forEach(seat => {
+ seat.bid.forEach(bid => {
+ bidsValue.push({
+ requestId: bid.impid,
+ cpm: bid.price,
+ width: bid.w,
+ height: bid.h,
+ creativeId: bid.crid,
+ ad: macroReplace(bid.adm, bid.price),
+ currency: 'USD',
+ netRevenue: true,
+ ttl: 300,
+ meta: {
+ advertiserDomains: bid.adomain || '',
+ },
+ })
+ })
+ })
+ return bidsValue
+}
+
+export function onBidWon(bid) {
+ if (bid.nurl) {
+ const resolvedNurl = replaceAuctionPrice(bid.nurl, bid.price);
+ ajax(resolvedNurl);
+ }
+}
+
+/* replacing auction_price macro from adm */
+function macroReplace(adm, cpm) {
+ let replacedadm = replaceAuctionPrice(adm, cpm);
+ return replacedadm;
+}
diff --git a/libraries/precisoUtils/bidUtilsCommon.js b/libraries/precisoUtils/bidUtilsCommon.js
new file mode 100644
index 00000000000..cb9699035fb
--- /dev/null
+++ b/libraries/precisoUtils/bidUtilsCommon.js
@@ -0,0 +1,173 @@
+import { config } from '../../src/config.js';
+import {
+ isFn,
+ isStr,
+ deepAccess,
+ getWindowTop,
+ triggerPixel
+} from '../../src/utils.js';
+import { BANNER, VIDEO, NATIVE } from '../../src/mediaTypes.js';
+
+function isBidResponseValid(bid) {
+ if (!bid.requestId || !bid.cpm || !bid.creativeId ||
+ !bid.ttl || !bid.currency || !bid.meta) {
+ return false;
+ }
+
+ switch (bid.mediaType) {
+ case BANNER:
+ return Boolean(bid.width && bid.height && bid.ad);
+ case VIDEO:
+ return Boolean(bid.vastXml || bid.vastUrl);
+ case NATIVE:
+ return Boolean(bid.native && bid.native.impressionTrackers);
+ default:
+ return false;
+ }
+}
+
+export function getBidFloor(bid) {
+ if (!isFn(bid.getFloor)) {
+ return deepAccess(bid, 'params.bidFloor', 0);
+ }
+
+ try {
+ const bidFloor = bid.getFloor({
+ currency: 'USD',
+ mediaType: '*',
+ size: '*',
+ });
+ return bidFloor.floor;
+ } catch (_) {
+ return 0
+ }
+}
+
+export function isBidRequestValid(bid) {
+ return Boolean(bid.bidId && bid.params && bid.params.placementId);
+}
+
+export const buildBidRequests = (adurl) => (validBidRequests = [], bidderRequest) => {
+ const winTop = getWindowTop();
+ const location = winTop.location;
+ const placements = [];
+
+ const request = {
+ deviceWidth: winTop.screen.width,
+ deviceHeight: winTop.screen.height,
+ language: (navigator && navigator.language) ? navigator.language.split('-')[0] : '',
+ host: location.host,
+ page: location.pathname,
+ placements: placements
+ };
+ consentCheck(bidderRequest, request);
+
+ // if (bidderRequest) {
+ // if (bidderRequest.uspConsent) {
+ // request.ccpa = bidderRequest.uspConsent;
+ // }
+ // if (bidderRequest.gdprConsent) {
+ // request.gdpr = bidderRequest.gdprConsent;
+ // }
+ // }
+
+ const len = validBidRequests.length;
+ for (let i = 0; i < len; i++) {
+ const bid = validBidRequests[i];
+ const placement = {
+ placementId: bid.params.placementId,
+ bidId: bid.bidId,
+ schain: bid.schain || {},
+ bidfloor: getBidFloor(bid)
+ };
+
+ if (typeof bid.userId !== 'undefined') {
+ placement.userId = bid.userId;
+ }
+
+ const mediaType = bid.mediaTypes;
+
+ if (mediaType && mediaType[BANNER] && mediaType[BANNER].sizes) {
+ placement.sizes = mediaType[BANNER].sizes;
+ placement.adFormat = BANNER;
+ }
+
+ placements.push(placement);
+ }
+
+ return {
+ method: 'POST',
+ url: adurl,
+ data: request
+ };
+}
+
+export function interpretResponse(serverResponse) {
+ let response = [];
+ for (let i = 0; i < serverResponse.body.length; i++) {
+ let resItem = serverResponse.body[i];
+ if (isBidResponseValid(resItem)) {
+ const advertiserDomains = resItem.adomain && resItem.adomain.length ? resItem.adomain : [];
+ resItem.meta = { ...resItem.meta, advertiserDomains };
+
+ response.push(resItem);
+ }
+ }
+ return response;
+}
+
+export function consentCheck(bidderRequest, req) {
+ if (bidderRequest) {
+ if (bidderRequest.uspConsent) {
+ req.ccpa = bidderRequest.uspConsent;
+ }
+ if (bidderRequest.gdprConsent) {
+ req.gdpr = bidderRequest.gdprConsent
+ }
+ if (bidderRequest.gppConsent) {
+ req.gpp = bidderRequest.gppConsent;
+ }
+ }
+}
+
+export const buildUserSyncs = (syncOptions, serverResponses, gdprConsent, uspConsent, syncEndpoint) => {
+ let syncType = syncOptions.iframeEnabled ? 'iframe' : 'image';
+ const isCk2trk = syncEndpoint.includes('ck.2trk.info');
+
+ // Base sync URL
+ let syncUrl = isCk2trk ? syncEndpoint : `${syncEndpoint}/${syncType}?pbjs=1`;
+
+ if (gdprConsent && gdprConsent.consentString) {
+ if (typeof gdprConsent.gdprApplies === 'boolean') {
+ syncUrl += `&gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`;
+ } else {
+ syncUrl += `&gdpr=0&gdpr_consent=${gdprConsent.consentString}`;
+ }
+ } else {
+ syncUrl += isCk2trk ? `&gdpr=0&gdpr_consent=` : '';
+ }
+
+ if (isCk2trk) {
+ syncUrl += uspConsent ? `&us_privacy=${uspConsent}` : `&us_privacy=`;
+ syncUrl += (syncOptions.iframeEnabled) ? `&t=4` : `&t=2`
+ } else {
+ if (uspConsent && uspConsent.consentString) {
+ syncUrl += `&ccpa_consent=${uspConsent.consentString}`;
+ }
+ const coppa = config.getConfig('coppa') ? 1 : 0;
+ syncUrl += `&coppa=${coppa}`;
+ }
+
+ return [{
+ type: syncType,
+ url: syncUrl
+ }];
+}
+
+export function bidWinReport (bid) {
+ const cpm = deepAccess(bid, 'adserverTargeting.hb_pb') || '';
+ if (isStr(bid.nurl) && bid.nurl !== '') {
+ bid.nurl = bid.nurl.replace(/\${AUCTION_PRICE}/, cpm);
+ triggerPixel(bid.nurl);
+ }
+}
diff --git a/modules/idxBidAdapter.js b/modules/idxBidAdapter.js
index 48739275788..12adb4058ae 100644
--- a/modules/idxBidAdapter.js
+++ b/modules/idxBidAdapter.js
@@ -1,6 +1,7 @@
import { registerBidder } from '../src/adapters/bidderFactory.js'
import { BANNER } from '../src/mediaTypes.js'
import { isArray, isNumber } from '../src/utils.js'
+import { interpretResponse } from '../libraries/precisoUtils/bidUtils.js';
const BIDDER_CODE = 'idx'
const ENDPOINT_URL = 'https://dev-event.dxmdp.com/rest/api/v1/bid'
@@ -49,32 +50,7 @@ export const spec = {
}
}
},
- interpretResponse: function (serverResponse) {
- const response = serverResponse.body
-
- const bids = []
-
- response.seatbid.forEach(seat => {
- seat.bid.forEach(bid => {
- bids.push({
- requestId: bid.impid,
- cpm: bid.price,
- width: bid.w,
- height: bid.h,
- creativeId: bid.crid,
- ad: bid.adm,
- currency: 'USD',
- netRevenue: true,
- ttl: 300,
- meta: {
- advertiserDomains: bid.adomain || [],
- },
- })
- })
- })
-
- return bids
- },
+ interpretResponse,
}
registerBidder(spec)
diff --git a/modules/loganBidAdapter.js b/modules/loganBidAdapter.js
index bec23cddc2d..4e2652e452f 100644
--- a/modules/loganBidAdapter.js
+++ b/modules/loganBidAdapter.js
@@ -1,54 +1,18 @@
-import { isFn, deepAccess, getWindowTop } from '../src/utils.js';
+import { getWindowTop } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js';
-import {config} from '../src/config.js';
import { convertOrtbRequestToProprietaryNative } from '../src/native.js';
+import { buildUserSyncs, interpretResponse, isBidRequestValid, getBidFloor, consentCheck } from '../libraries/precisoUtils/bidUtilsCommon.js';
const BIDDER_CODE = 'logan';
const AD_URL = 'https://USeast2.logan.ai/pbjs';
-const SYNC_URL = 'https://ssp-cookie.logan.ai'
-
-function isBidResponseValid(bid) {
- if (!bid.requestId || !bid.cpm || !bid.creativeId ||
- !bid.ttl || !bid.currency || !bid.meta) {
- return false;
- }
- switch (bid.mediaType) {
- case BANNER:
- return Boolean(bid.width && bid.height && bid.ad);
- case VIDEO:
- return Boolean(bid.vastXml || bid.vastUrl);
- case NATIVE:
- return Boolean(bid.native && bid.native.impressionTrackers);
- default:
- return false;
- }
-}
-
-function getBidFloor(bid) {
- if (!isFn(bid.getFloor)) {
- return deepAccess(bid, 'params.bidfloor', 0);
- }
-
- try {
- const bidFloor = bid.getFloor({
- currency: 'USD',
- mediaType: '*',
- size: '*',
- });
- return bidFloor.floor;
- } catch (_) {
- return 0
- }
-}
+const SYNC_URL = 'https://ssp-cookie.logan.ai';
export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, VIDEO, NATIVE],
- isBidRequestValid: (bid) => {
- return Boolean(bid.bidId && bid.params && bid.params.placementId);
- },
+ isBidRequestValid: isBidRequestValid,
buildRequests: (validBidRequests = [], bidderRequest) => {
// convert Native ORTB definition to old-style prebid native definition
@@ -67,14 +31,7 @@ export const spec = {
placements: placements
};
- if (bidderRequest) {
- if (bidderRequest.uspConsent) {
- request.ccpa = bidderRequest.uspConsent;
- }
- if (bidderRequest.gdprConsent) {
- request.gdpr = bidderRequest.gdprConsent;
- }
- }
+ consentCheck(bidderRequest, request);
const len = validBidRequests.length;
for (let i = 0; i < len; i++) {
@@ -123,42 +80,11 @@ export const spec = {
};
},
- interpretResponse: (serverResponse) => {
- let response = [];
- for (let i = 0; i < serverResponse.body.length; i++) {
- let resItem = serverResponse.body[i];
- if (isBidResponseValid(resItem)) {
- const advertiserDomains = resItem.adomain && resItem.adomain.length ? resItem.adomain : [];
- resItem.meta = { ...resItem.meta, advertiserDomains };
-
- response.push(resItem);
- }
- }
- return response;
- },
-
+ interpretResponse: interpretResponse,
getUserSyncs: (syncOptions, serverResponses, gdprConsent, uspConsent) => {
- let syncType = syncOptions.iframeEnabled ? 'iframe' : 'image';
- let syncUrl = SYNC_URL + `/${syncType}?pbjs=1`;
- if (gdprConsent && gdprConsent.consentString) {
- if (typeof gdprConsent.gdprApplies === 'boolean') {
- syncUrl += `&gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`;
- } else {
- syncUrl += `&gdpr=0&gdpr_consent=${gdprConsent.consentString}`;
- }
- }
- if (uspConsent && uspConsent.consentString) {
- syncUrl += `&ccpa_consent=${uspConsent.consentString}`;
- }
-
- const coppa = config.getConfig('coppa') ? 1 : 0;
- syncUrl += `&coppa=${coppa}`;
-
- return [{
- type: syncType,
- url: syncUrl
- }];
+ return buildUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent, SYNC_URL);
}
+
};
registerBidder(spec);
diff --git a/modules/mediabramaBidAdapter.js b/modules/mediabramaBidAdapter.js
index caf6854fe03..9722f1672ba 100644
--- a/modules/mediabramaBidAdapter.js
+++ b/modules/mediabramaBidAdapter.js
@@ -1,155 +1,22 @@
-import {
- isFn,
- isStr,
- deepAccess,
- getWindowTop,
- triggerPixel
-} from '../src/utils.js';
+
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js';
-import { config } from '../src/config.js';
+import { bidWinReport, buildBidRequests, buildUserSyncs, interpretResponse, isBidRequestValid } from '../libraries/precisoUtils/bidUtilsCommon.js';
const BIDDER_CODE = 'mediabrama';
const AD_URL = 'https://prebid.mediabrama.com/pbjs';
const SYNC_URL = 'https://prebid.mediabrama.com/sync';
-function isBidResponseValid(bid) {
- if (!bid.requestId || !bid.cpm || !bid.creativeId ||
- !bid.ttl || !bid.currency || !bid.meta) {
- return false;
- }
-
- switch (bid.mediaType) {
- case BANNER:
- return Boolean(bid.width && bid.height && bid.ad);
- default:
- return false;
- }
-}
-
-function getBidFloor(bid) {
- if (!isFn(bid.getFloor)) {
- return deepAccess(bid, 'params.bidFloor', 0);
- }
-
- try {
- const bidFloor = bid.getFloor({
- currency: 'USD',
- mediaType: '*',
- size: '*',
- });
- return bidFloor.floor;
- } catch (_) {
- return 0
- }
-}
-
export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER],
-
- isBidRequestValid: (bid) => {
- return Boolean(bid.bidId && bid.params && bid.params.placementId);
- },
-
- buildRequests: (validBidRequests = [], bidderRequest) => {
- const winTop = getWindowTop();
- const location = winTop.location;
- const placements = [];
-
- const request = {
- deviceWidth: winTop.screen.width,
- deviceHeight: winTop.screen.height,
- language: (navigator && navigator.language) ? navigator.language.split('-')[0] : '',
- host: location.host,
- page: location.pathname,
- placements: placements
- };
-
- if (bidderRequest) {
- if (bidderRequest.uspConsent) {
- request.ccpa = bidderRequest.uspConsent;
- }
- if (bidderRequest.gdprConsent) {
- request.gdpr = bidderRequest.gdprConsent;
- }
- }
-
- const len = validBidRequests.length;
- for (let i = 0; i < len; i++) {
- const bid = validBidRequests[i];
- const placement = {
- placementId: bid.params.placementId,
- bidId: bid.bidId,
- schain: bid.schain || {},
- bidfloor: getBidFloor(bid)
- };
-
- if (typeof bid.userId !== 'undefined') {
- placement.userId = bid.userId;
- }
-
- const mediaType = bid.mediaTypes;
-
- if (mediaType && mediaType[BANNER] && mediaType[BANNER].sizes) {
- placement.sizes = mediaType[BANNER].sizes;
- placement.adFormat = BANNER;
- }
-
- placements.push(placement);
- }
-
- return {
- method: 'POST',
- url: AD_URL,
- data: request
- };
- },
-
- interpretResponse: (serverResponse) => {
- let response = [];
- for (let i = 0; i < serverResponse.body.length; i++) {
- let resItem = serverResponse.body[i];
- if (isBidResponseValid(resItem)) {
- const advertiserDomains = resItem.adomain && resItem.adomain.length ? resItem.adomain : [];
- resItem.meta = { ...resItem.meta, advertiserDomains };
-
- response.push(resItem);
- }
- }
- return response;
- },
-
+ isBidRequestValid: isBidRequestValid,
+ buildRequests: buildBidRequests(AD_URL),
+ interpretResponse: interpretResponse,
getUserSyncs: (syncOptions, serverResponses, gdprConsent, uspConsent) => {
- let syncType = syncOptions.iframeEnabled ? 'iframe' : 'image';
- let syncUrl = SYNC_URL + `/${syncType}?pbjs=1`;
- if (gdprConsent && gdprConsent.consentString) {
- if (typeof gdprConsent.gdprApplies === 'boolean') {
- syncUrl += `&gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`;
- } else {
- syncUrl += `&gdpr=0&gdpr_consent=${gdprConsent.consentString}`;
- }
- }
- if (uspConsent && uspConsent.consentString) {
- syncUrl += `&ccpa_consent=${uspConsent.consentString}`;
- }
-
- const coppa = config.getConfig('coppa') ? 1 : 0;
- syncUrl += `&coppa=${coppa}`;
-
- return [{
- type: syncType,
- url: syncUrl
- }];
+ return buildUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent, SYNC_URL);
},
-
- onBidWon: (bid) => {
- const cpm = deepAccess(bid, 'adserverTargeting.hb_pb') || '';
- if (isStr(bid.nurl) && bid.nurl !== '') {
- bid.nurl = bid.nurl.replace(/\${AUCTION_PRICE}/, cpm);
- triggerPixel(bid.nurl);
- }
- }
+ onBidWon: bidWinReport
};
registerBidder(spec);
diff --git a/modules/precisoBidAdapter.js b/modules/precisoBidAdapter.js
index b4f1b665d91..6f6ab82eca2 100644
--- a/modules/precisoBidAdapter.js
+++ b/modules/precisoBidAdapter.js
@@ -1,205 +1,75 @@
-import { isFn, deepAccess, logInfo } from '../src/utils.js';
+import { logInfo } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
-import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js';
-import { config } from '../src/config.js';
-import { convertOrtbRequestToProprietaryNative } from '../src/native.js';
-
-const BIDDER_CODE = 'preciso';
-const AD_URL = 'https://ssp-bidder.mndtrk.com/bid_request/openrtb';
-const URL_SYNC = 'https://ck.2trk.info/rtb/user/usersync.aspx?';
-const SUPPORTED_MEDIA_TYPES = [BANNER, NATIVE, VIDEO];
+import { BANNER } from '../src/mediaTypes.js';
+import { getStorageManager } from '../src/storageManager.js';
+import { MODULE_TYPE_UID } from '../src/activities/modules.js';
+import { buildRequests, interpretResponse, onBidWon } from '../libraries/precisoUtils/bidUtils.js';
+import { buildUserSyncs } from '../libraries/precisoUtils/bidUtilsCommon.js';
+
+const BIDDER__CODE = 'preciso';
+export const storage = getStorageManager({ moduleType: MODULE_TYPE_UID, moduleName: BIDDER__CODE });
+// export const storage2 = getStorageManager({ moduleType: MODULE_TYPE_UID, moduleName: BIDDER__CODE });
+const SUPPORTED_MEDIA_TYPES = [BANNER];
const GVLID = 874;
-let userId = 'NA';
+let precisoId = 'NA';
+let sharedId = 'NA';
+
+const endpoint = 'https://ssp-bidder.mndtrk.com/bid_request/openrtb';
+let syncEndpoint = 'https://ck.2trk.info/rtb/user/usersync.aspx?';
export const spec = {
- code: BIDDER_CODE,
+ code: BIDDER__CODE,
supportedMediaTypes: SUPPORTED_MEDIA_TYPES,
gvlid: GVLID,
isBidRequestValid: (bid) => {
- return Boolean(bid.bidId && bid.params && !isNaN(bid.params.publisherId) && bid.params.host == 'prebid');
- },
-
- buildRequests: (validBidRequests = [], bidderRequest) => {
- // convert Native ORTB definition to old-style prebid native definition
- validBidRequests = convertOrtbRequestToProprietaryNative(validBidRequests);
- // userId = validBidRequests[0].userId.pubcid;
- let winTop = window;
- let location;
- var offset = new Date().getTimezoneOffset();
- logInfo('timezone ' + offset);
- var city = Intl.DateTimeFormat().resolvedOptions().timeZone;
- logInfo('location test' + city)
-
- const countryCode = getCountryCodeByTimezone(city);
- logInfo(`The country code for ${city} is ${countryCode}`);
-
- location = bidderRequest?.refererInfo ?? null;
-
- let request = {
- id: validBidRequests[0].bidderRequestId,
-
- imp: validBidRequests.map(request => {
- const { bidId, sizes, mediaType, ortb2 } = request
- const item = {
- id: bidId,
- region: request.params.region,
- traffic: mediaType,
- bidFloor: getBidFloor(request),
- ortb2: ortb2
-
- }
-
- if (request.mediaTypes.banner) {
- item.banner = {
- format: (request.mediaTypes.banner.sizes || sizes).map(size => {
- return { w: size[0], h: size[1] }
- }),
- }
- }
-
- if (request.schain) {
- item.schain = request.schain;
- }
-
- if (request.floorData) {
- item.bidFloor = request.floorData.floorMin;
- }
- return item
- }),
- auctionId: validBidRequests[0].auctionId,
- 'deviceWidth': winTop.screen.width,
- 'deviceHeight': winTop.screen.height,
- 'language': (navigator && navigator.language) ? navigator.language : '',
- geo: navigator.geolocation.getCurrentPosition(position => {
- const { latitude, longitude } = position.coords;
- return {
- latitude: latitude,
- longitude: longitude
- }
- // Show a map centered at latitude / longitude.
- }) || { utcoffset: new Date().getTimezoneOffset() },
- city: city,
- 'host': location?.domain ?? '',
- 'page': location?.page ?? '',
- 'coppa': config.getConfig('coppa') === true ? 1 : 0
- // userId: validBidRequests[0].userId
- };
-
- request.language.indexOf('-') != -1 && (request.language = request.language.split('-')[0])
- if (bidderRequest) {
- if (bidderRequest.uspConsent) {
- request.ccpa = bidderRequest.uspConsent;
- }
- if (bidderRequest.gdprConsent) {
- request.gdpr = bidderRequest.gdprConsent
- }
- if (bidderRequest.gppConsent) {
- request.gpp = bidderRequest.gppConsent;
+ sharedId = storage.getDataFromLocalStorage('_sharedid') || storage.getCookie('_sharedid');
+ let precisoBid = true;
+ const preCall = 'https://ssp-usersync.mndtrk.com/getUUID?sharedId=' + sharedId;
+ precisoId = storage.getDataFromLocalStorage('_pre|id');
+ if (Object.is(precisoId, 'NA') || Object.is(precisoId, null) || Object.is(precisoId, undefined)) {
+ if (!bid.precisoBid) {
+ precisoBid = false;
+ getapi(preCall);
}
}
- return {
- method: 'POST',
- url: AD_URL,
- data: request,
-
- };
+ return Boolean(bid.bidId && bid.params && bid.params.publisherId && precisoBid);
},
-
- interpretResponse: function (serverResponse) {
- const response = serverResponse.body
-
- const bids = []
-
- response.seatbid.forEach(seat => {
- seat.bid.forEach(bid => {
- bids.push({
- requestId: bid.impid,
- cpm: bid.price,
- width: bid.w,
- height: bid.h,
- creativeId: bid.crid,
- ad: bid.adm,
- currency: 'USD',
- netRevenue: true,
- ttl: 300,
- meta: {
- advertiserDomains: bid.adomain || [],
- },
- })
- })
- })
-
- return bids
- },
-
- getUserSyncs: (syncOptions, serverResponses = [], gdprConsent = {}, uspConsent = '', gppConsent = '') => {
- let syncs = [];
- let { gdprApplies, consentString = '' } = gdprConsent;
-
- if (serverResponses.length > 0) {
- logInfo('preciso bidadapter getusersync serverResponses:' + serverResponses.toString);
- }
- if (syncOptions.iframeEnabled) {
- syncs.push({
- type: 'iframe',
- url: `${URL_SYNC}id=${userId}&gdpr=${gdprApplies ? 1 : 0}&gdpr_consent=${consentString}&us_privacy=${uspConsent}&t=4`
- });
+ buildRequests: buildRequests(endpoint),
+ interpretResponse,
+ onBidWon,
+ getUserSyncs: (syncOptions, serverResponses, gdprConsent, uspConsent) => {
+ const isSpec = syncOptions.spec;
+ if (!Object.is(isSpec, true)) {
+ let syncId = storage.getCookie('_sharedid');
+ syncEndpoint = syncEndpoint + 'id=' + syncId;
} else {
- syncs.push({
- type: 'image',
- url: `${URL_SYNC}&gdpr=${gdprApplies ? 1 : 0}&gdpr_consent=${consentString}&us_privacy=${uspConsent}&t=2`
- });
+ syncEndpoint = syncEndpoint + 'id=NA';
}
- return syncs
+ return buildUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent, syncEndpoint);
}
-
};
-function getCountryCodeByTimezone(city) {
- try {
- const now = new Date();
- const options = {
- timeZone: city,
- timeZoneName: 'long',
- };
- const [timeZoneName] = new Intl.DateTimeFormat('en-US', options)
- .formatToParts(now)
- .filter((part) => part.type === 'timeZoneName');
+registerBidder(spec);
- if (timeZoneName) {
- // Extract the country code from the timezone name
- const parts = timeZoneName.value.split('-');
- if (parts.length >= 2) {
- return parts[1];
- }
- }
- } catch (error) {
- // Handle errors, such as an invalid timezone city
- logInfo(error);
- }
+async function getapi(url) {
+ try {
+ // Storing response
+ const response = await fetch(url);
- // Handle the case where the city is not found or an error occurred
- return 'Unknown';
-}
+ // Storing data in form of JSON
+ var data = await response.json();
-function getBidFloor(bid) {
- if (!isFn(bid.getFloor)) {
- return deepAccess(bid, 'params.bidFloor', 0);
- }
+ const dataMap = new Map(Object.entries(data));
+ const uuidValue = dataMap.get('UUID');
- try {
- const bidFloor = bid.getFloor({
- currency: 'USD',
- mediaType: '*',
- size: '*',
- });
- return bidFloor.floor;
- } catch (_) {
- return 0
+ if (!Object.is(uuidValue, null) && !Object.is(uuidValue, undefined)) {
+ storage.setDataInLocalStorage('_pre|id', uuidValue);
+ }
+ return data;
+ } catch (error) {
+ logInfo('Error in preciso precall' + error);
}
}
-
-registerBidder(spec);
diff --git a/modules/redtramBidAdapter.js b/modules/redtramBidAdapter.js
index 726b2d53f1c..bacc209f991 100644
--- a/modules/redtramBidAdapter.js
+++ b/modules/redtramBidAdapter.js
@@ -1,151 +1,21 @@
-import {
- isFn,
- deepAccess,
- getWindowTop,
- triggerNurlWithCpm
-} from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js';
-import { config } from '../src/config.js';
+import { bidWinReport, buildBidRequests, buildUserSyncs, interpretResponse, isBidRequestValid } from '../libraries/precisoUtils/bidUtilsCommon.js';
const BIDDER_CODE = 'redtram';
const AD_URL = 'https://prebid.redtram.com/pbjs';
const SYNC_URL = 'https://prebid.redtram.com/sync';
-function isBidResponseValid(bid) {
- if (!bid.requestId || !bid.cpm || !bid.creativeId ||
- !bid.ttl || !bid.currency || !bid.meta) {
- return false;
- }
-
- switch (bid.mediaType) {
- case BANNER:
- return Boolean(bid.width && bid.height && bid.ad);
- default:
- return false;
- }
-}
-
-function getBidFloor(bid) {
- if (!isFn(bid.getFloor)) {
- return deepAccess(bid, 'params.bidFloor', 0);
- }
-
- try {
- const bidFloor = bid.getFloor({
- currency: 'USD',
- mediaType: '*',
- size: '*',
- });
- return bidFloor.floor;
- } catch (_) {
- return 0
- }
-}
-
export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER],
-
- isBidRequestValid: (bid) => {
- return Boolean(bid.bidId && bid.params && bid.params.placementId);
- },
-
- buildRequests: (validBidRequests = [], bidderRequest) => {
- const winTop = getWindowTop();
- const location = winTop.location;
- const placements = [];
-
- const request = {
- deviceWidth: winTop.screen.width,
- deviceHeight: winTop.screen.height,
- language: (navigator && navigator.language) ? navigator.language.split('-')[0] : '',
- host: location.host,
- page: location.pathname,
- placements: placements
- };
-
- if (bidderRequest) {
- if (bidderRequest.uspConsent) {
- request.ccpa = bidderRequest.uspConsent;
- }
- if (bidderRequest.gdprConsent) {
- request.gdpr = bidderRequest.gdprConsent;
- }
- }
-
- const len = validBidRequests.length;
- for (let i = 0; i < len; i++) {
- const bid = validBidRequests[i];
- const placement = {
- placementId: bid.params.placementId,
- bidId: bid.bidId,
- schain: bid.schain || {},
- bidfloor: getBidFloor(bid)
- };
-
- if (typeof bid.userId !== 'undefined') {
- placement.userId = bid.userId;
- }
-
- const mediaType = bid.mediaTypes;
-
- if (mediaType && mediaType[BANNER] && mediaType[BANNER].sizes) {
- placement.sizes = mediaType[BANNER].sizes;
- placement.adFormat = BANNER;
- }
-
- placements.push(placement);
- }
-
- return {
- method: 'POST',
- url: AD_URL,
- data: request
- };
- },
-
- interpretResponse: (serverResponse) => {
- let response = [];
- for (let i = 0; i < serverResponse.body.length; i++) {
- let resItem = serverResponse.body[i];
- if (isBidResponseValid(resItem)) {
- const advertiserDomains = resItem.adomain && resItem.adomain.length ? resItem.adomain : [];
- resItem.meta = { ...resItem.meta, advertiserDomains };
-
- response.push(resItem);
- }
- }
- return response;
- },
-
+ isBidRequestValid: isBidRequestValid,
+ buildRequests: buildBidRequests(AD_URL),
+ interpretResponse: interpretResponse,
getUserSyncs: (syncOptions, serverResponses, gdprConsent, uspConsent) => {
- let syncType = syncOptions.iframeEnabled ? 'iframe' : 'image';
- let syncUrl = SYNC_URL + `/${syncType}?pbjs=1`;
- if (gdprConsent && gdprConsent.consentString) {
- if (typeof gdprConsent.gdprApplies === 'boolean') {
- syncUrl += `&gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`;
- } else {
- syncUrl += `&gdpr=0&gdpr_consent=${gdprConsent.consentString}`;
- }
- }
- if (uspConsent && uspConsent.consentString) {
- syncUrl += `&ccpa_consent=${uspConsent.consentString}`;
- }
-
- const coppa = config.getConfig('coppa') ? 1 : 0;
- syncUrl += `&coppa=${coppa}`;
-
- return [{
- type: syncType,
- url: syncUrl
- }];
+ return buildUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent, SYNC_URL);
},
-
- onBidWon: (bid) => {
- const cpm = deepAccess(bid, 'adserverTargeting.hb_pb') || '';
- triggerNurlWithCpm(bid, cpm)
- }
+ onBidWon: bidWinReport
};
registerBidder(spec);
diff --git a/test/spec/libraries/precisoUtils/bidUtilsCommon_spec.js b/test/spec/libraries/precisoUtils/bidUtilsCommon_spec.js
new file mode 100644
index 00000000000..754b104d96d
--- /dev/null
+++ b/test/spec/libraries/precisoUtils/bidUtilsCommon_spec.js
@@ -0,0 +1,267 @@
+import {expect} from 'chai';
+
+import { BANNER } from '../../../../src/mediaTypes.js';
+import * as utils from '../../../../src/utils.js';
+import { interpretResponse, isBidRequestValid, buildUserSyncs, buildBidRequests, bidWinReport } from '../../../../libraries/precisoUtils/bidUtilsCommon.js';
+
+const BIDDER_CODE = 'bidder';
+const TESTDOMAIN = 'test.org'
+const AD_URL = `https://${TESTDOMAIN}/pbjs`;
+const SYNC_URL = `https://${TESTDOMAIN}/sync`;
+
+describe('bidUtilsCommon', function () {
+ const bid = {
+ bidId: '23dc19818e5293',
+ bidder: BIDDER_CODE,
+ mediaTypes: {
+ [BANNER]: {
+ sizes: [[300, 250]]
+ }
+ },
+ params: {
+ placementId: 23611,
+ }
+ };
+
+ const bidderRequest = {
+ refererInfo: {
+ referer: 'test.com'
+ }
+ };
+
+ const spec = {
+ isBidRequestValid: isBidRequestValid,
+ buildRequests: buildBidRequests(AD_URL),
+ interpretResponse,
+ getUserSyncs: buildUserSyncs,
+ onBidWon: bidWinReport
+ };
+
+ describe('isBidRequestValid', function () {
+ it('Should return true if there are bidId, params and key parameters present', function () {
+ expect(spec.isBidRequestValid(bid)).to.be.true;
+ });
+ it('Should return false if at least one of parameters is not present', function () {
+ delete bid.params.placementId;
+ expect(spec.isBidRequestValid(bid)).to.be.false;
+ });
+ });
+
+ describe('buildRequests', function () {
+ let serverRequest = spec.buildRequests([bid], bidderRequest);
+ it('Creates a ServerRequest object with method, URL and data', function () {
+ expect(serverRequest).to.exist;
+ expect(serverRequest.method).to.exist;
+ expect(serverRequest.url).to.exist;
+ expect(serverRequest.data).to.exist;
+ });
+ it('Returns POST method', function () {
+ expect(serverRequest.method).to.equal('POST');
+ });
+ it('Returns valid data if array of bids is valid', function () {
+ let data = serverRequest.data;
+ expect(data).to.be.an('object');
+ expect(data).to.have.all.keys('deviceWidth', 'deviceHeight', 'language', 'host', 'page', 'placements');
+ expect(data.deviceWidth).to.be.a('number');
+ expect(data.deviceHeight).to.be.a('number');
+ expect(data.language).to.be.a('string');
+ expect(data.host).to.be.a('string');
+ expect(data.page).to.be.a('string');
+ expect(data.gdpr).to.not.exist;
+ expect(data.ccpa).to.not.exist;
+ let placement = data['placements'][0];
+ expect(placement).to.have.keys('placementId', 'bidId', 'adFormat', 'sizes', 'schain', 'bidfloor');
+ expect(placement.placementId).to.equal(23611);
+ expect(placement.bidId).to.equal('23dc19818e5293');
+ expect(placement.adFormat).to.equal(BANNER);
+ expect(placement.schain).to.be.an('object');
+ expect(placement.sizes).to.be.an('array');
+ expect(placement.bidfloor).to.exist.and.to.equal(0);
+ });
+
+ it('Returns data with gdprConsent and without uspConsent', function () {
+ bidderRequest.gdprConsent = 'test';
+ serverRequest = spec.buildRequests([bid], bidderRequest);
+ let data = serverRequest.data;
+ expect(data.gdpr).to.exist;
+ expect(data.gdpr).to.be.a('string');
+ expect(data.gdpr).to.equal(bidderRequest.gdprConsent);
+ expect(data.ccpa).to.not.exist;
+ delete bidderRequest.gdprConsent;
+ });
+
+ it('Returns data with uspConsent and without gdprConsent', function () {
+ bidderRequest.uspConsent = 'test';
+ serverRequest = spec.buildRequests([bid], bidderRequest);
+ let data = serverRequest.data;
+ expect(data.ccpa).to.exist;
+ expect(data.ccpa).to.be.a('string');
+ expect(data.ccpa).to.equal(bidderRequest.uspConsent);
+ expect(data.gdpr).to.not.exist;
+ });
+
+ it('Returns empty data if no valid requests are passed', function () {
+ serverRequest = spec.buildRequests([]);
+ let data = serverRequest.data;
+ expect(data.placements).to.be.an('array').that.is.empty;
+ });
+ });
+ describe('interpretResponse', function () {
+ it('Should interpret banner response', function () {
+ const banner = {
+ body: [{
+ mediaType: 'banner',
+ width: 300,
+ height: 250,
+ cpm: 0.4,
+ ad: 'Test',
+ requestId: '23dc19818e5293',
+ ttl: 120,
+ creativeId: '2',
+ netRevenue: true,
+ currency: 'USD',
+ dealId: '1',
+ meta: {}
+ }]
+ };
+ let bannerResponses = spec.interpretResponse(banner);
+ expect(bannerResponses).to.be.an('array').that.is.not.empty;
+ let dataItem = bannerResponses[0];
+ expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId',
+ 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta');
+ expect(dataItem.requestId).to.equal('23dc19818e5293');
+ expect(dataItem.cpm).to.equal(0.4);
+ expect(dataItem.width).to.equal(300);
+ expect(dataItem.height).to.equal(250);
+ expect(dataItem.ad).to.equal('Test');
+ expect(dataItem.ttl).to.equal(120);
+ expect(dataItem.creativeId).to.equal('2');
+ expect(dataItem.netRevenue).to.be.true;
+ expect(dataItem.currency).to.equal('USD');
+ expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains');
+ });
+ it('Should return an empty array if invalid banner response is passed', function () {
+ const invBanner = {
+ body: [{
+ width: 300,
+ cpm: 0.4,
+ ad: 'Test',
+ requestId: '23dc19818e5293',
+ ttl: 120,
+ creativeId: '2',
+ netRevenue: true,
+ currency: 'USD',
+ dealId: '1'
+ }]
+ };
+
+ let serverResponses = spec.interpretResponse(invBanner);
+ expect(serverResponses).to.be.an('array').that.is.empty;
+ });
+ it('Should return an empty array if invalid response is passed', function () {
+ const invalid = {
+ body: [{
+ ttl: 120,
+ creativeId: '2',
+ netRevenue: true,
+ currency: 'USD',
+ dealId: '1'
+ }]
+ };
+ let serverResponses = spec.interpretResponse(invalid);
+ expect(serverResponses).to.be.an('array').that.is.empty;
+ });
+ });
+
+ describe('getUserSyncs', function () {
+ it('should do nothing on getUserSyncs', function () {
+ const syncData = spec.getUserSyncs({}, {}, {
+ consentString: 'ALL',
+ gdprApplies: true
+ }, {}, SYNC_URL);
+ expect(syncData).to.be.an('array').which.is.not.empty;
+ expect(syncData[0]).to.be.an('object')
+ expect(syncData[0].type).to.be.a('string')
+ expect(syncData[0].type).to.equal('image')
+ expect(syncData[0].url).to.be.a('string')
+ expect(syncData[0].url).to.equal(`https://${TESTDOMAIN}/sync/image?pbjs=1&gdpr=1&gdpr_consent=ALL&coppa=0`)
+ });
+ });
+
+ describe('on bidWon', function () {
+ beforeEach(function() {
+ sinon.stub(utils, 'triggerPixel');
+ });
+ afterEach(function() {
+ utils.triggerPixel.restore();
+ });
+ it('should replace nurl for banner', function () {
+ const nurl = 'nurl/?ap=${' + 'AUCTION_PRICE}';
+ const bid = {
+ 'bidderCode': 'redtram',
+ 'width': 300,
+ 'height': 250,
+ 'statusMessage': 'Bid available',
+ 'adId': '5691dd18ba6ab6',
+ 'requestId': '23dc19818e5293',
+ 'transactionId': '948c716b-bf64-4303-bcf4-395c2f6a9770',
+ 'auctionId': 'a6b7c61f-15a9-481b-8f64-e859787e9c07',
+ 'mediaType': 'banner',
+ 'source': 'client',
+ 'ad': "\n",
+ 'cpm': 0.68,
+ 'nurl': nurl,
+ 'creativeId': 'test',
+ 'currency': 'USD',
+ 'dealId': '',
+ 'meta': {
+ 'advertiserDomains': [],
+ 'dchain': {
+ 'ver': '1.0',
+ 'complete': 0,
+ 'nodes': [
+ {
+ 'name': 'redtram'
+ }
+ ]
+ }
+ },
+ 'netRevenue': true,
+ 'ttl': 120,
+ 'metrics': {},
+ 'adapterCode': 'redtram',
+ 'originalCpm': 0.68,
+ 'originalCurrency': 'USD',
+ 'responseTimestamp': 1668162732297,
+ 'requestTimestamp': 1668162732292,
+ 'bidder': 'redtram',
+ 'adUnitCode': 'div-prebid',
+ 'timeToRespond': 5,
+ 'pbLg': '0.50',
+ 'pbMg': '0.60',
+ 'pbHg': '0.68',
+ 'pbAg': '0.65',
+ 'pbDg': '0.68',
+ 'pbCg': '',
+ 'size': '300x250',
+ 'adserverTargeting': {
+ 'hb_bidder': 'redtram',
+ 'hb_adid': '5691dd18ba6ab6',
+ 'hb_pb': '0.68',
+ 'hb_size': '300x250',
+ 'hb_source': 'client',
+ 'hb_format': 'banner',
+ 'hb_adomain': ''
+ },
+ 'status': 'rendered',
+ 'params': [
+ {
+ 'placementId': 23611
+ }
+ ]
+ };
+ spec.onBidWon(bid);
+ expect(bid.nurl).to.deep.equal('nurl/?ap=0.68');
+ });
+ });
+});
diff --git a/test/spec/libraries/precisoUtils/bidUtils_spec.js b/test/spec/libraries/precisoUtils/bidUtils_spec.js
new file mode 100644
index 00000000000..eecfea4b70e
--- /dev/null
+++ b/test/spec/libraries/precisoUtils/bidUtils_spec.js
@@ -0,0 +1,150 @@
+
+import { expect } from 'chai';
+import { buildRequests, interpretResponse } from '../../../../libraries/precisoUtils/bidUtils.js';
+
+const DEFAULT_PRICE = 1
+const DEFAULT_CURRENCY = 'USD'
+const DEFAULT_BANNER_WIDTH = 300
+const DEFAULT_BANNER_HEIGHT = 250
+const BIDDER_CODE = 'preciso';
+const TESTDOMAIN = 'test.org'
+const bidEndPoint = `https://${TESTDOMAIN}/bid_request/openrtb`;
+
+describe('bidderOperations', function () {
+ let bid = {
+ bidId: '23fhj33i987f',
+ bidder: BIDDER_CODE,
+ buyerUid: 'testuid',
+ mediaTypes: {
+ banner: {
+ sizes: [[DEFAULT_BANNER_WIDTH, DEFAULT_BANNER_HEIGHT]]
+ }
+ },
+ params: {
+ host: 'prebid',
+ sourceid: '0',
+ publisherId: '0',
+ mediaType: 'banner',
+ region: 'IND'
+
+ },
+ userId: {
+ pubcid: '12355454test'
+
+ },
+ user: {
+ geo: {
+ region: 'IND',
+ }
+ },
+ ortb2: {
+ device: {
+ w: 1920,
+ h: 166,
+ dnt: 0,
+ },
+ site: {
+ domain: 'localHost'
+ },
+ source: {
+ tid: 'eaff09b-a1ab-4ec6-a81e-c5a75bc1dde3'
+ }
+
+ }
+
+ };
+
+ const spec = {
+ // isBidRequestValid: isBidRequestValid(),
+ buildRequests: buildRequests(bidEndPoint),
+ interpretResponse,
+ // buildUserSyncs: buildUserSyncs(syncEndPoint)
+ };
+
+ describe('buildRequests', function () {
+ let serverRequest = spec.buildRequests([bid]);
+ it('Creates a ServerRequest object with method, URL and data', function () {
+ expect(serverRequest).to.exist;
+ expect(serverRequest.method).to.exist;
+ expect(serverRequest.url).to.exist;
+ expect(serverRequest.data).to.exist;
+ });
+ it('Returns POST method', function () {
+ expect(serverRequest.method).to.equal('POST');
+ });
+ it('Returns valid URL', function () {
+ expect(serverRequest.url).to.equal(`https://${TESTDOMAIN}/bid_request/openrtb`);
+ });
+ it('Returns valid data if array of bids is valid', function () {
+ let data = serverRequest.data;
+ expect(data).to.be.an('object');
+ expect(data.device).to.be.a('object');
+ expect(data.user).to.be.a('object');
+ expect(data.source).to.be.a('object');
+ expect(data.site).to.be.a('object');
+ });
+ it('Returns data.device is undefined if no valid device object is passed', function () {
+ delete bid.ortb2.device;
+ serverRequest = spec.buildRequests([bid]);
+ let data = serverRequest.data;
+ expect(data.device).to.be.undefined;
+ });
+ });
+
+ describe('interpretResponse', function () {
+ it('should get correct bid response', function () {
+ let response = {
+ bidderRequestId: 'f6adb85f-4e19-45a0-b41e-2a5b9a48f23a',
+ seatbid: [
+ {
+ bid: [
+ {
+ id: '123',
+ impid: 'b4f290d7-d4ab-4778-ab94-2baf06420b22',
+ price: DEFAULT_PRICE,
+ adm: 'hi',
+ cid: 'test_cid',
+ crid: 'test_banner_crid',
+ w: DEFAULT_BANNER_WIDTH,
+ h: DEFAULT_BANNER_HEIGHT,
+ adomain: [],
+ }
+ ],
+ seat: BIDDER_CODE
+ }
+ ],
+ }
+ let expectedResponse = [
+ {
+ requestId: 'b4f290d7-d4ab-4778-ab94-2baf06420b22',
+ cpm: DEFAULT_PRICE,
+ width: DEFAULT_BANNER_WIDTH,
+ height: DEFAULT_BANNER_HEIGHT,
+ creativeId: 'test_banner_crid',
+ ad: 'hi',
+ currency: DEFAULT_CURRENCY,
+ netRevenue: true,
+ ttl: 300,
+ meta: { advertiserDomains: [] },
+ }
+ ]
+ let result = spec.interpretResponse({ body: response })
+ expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0]))
+ })
+ });
+ // describe('getUserSyncs', function () {
+ // const syncUrl = `https://${TESTDOMAIN}/rtb/user/usersync.aspx?/iframe?pbjs=1&coppa=0`;
+ // const syncOptions = {
+ // iframeEnabled: true
+ // };
+ // let userSync = spec.buildUserSyncs(syncOptions);
+ // it('Returns valid URL and type', function () {
+ // expect(userSync).to.be.an('array').with.lengthOf(1);
+ // expect(userSync[0].type).to.exist;
+ // expect(userSync[0].url).to.exist;
+ // expect(userSync).to.deep.equal([
+ // { type: 'iframe', url: syncUrl }
+ // ]);
+ // });
+ // });
+});
diff --git a/test/spec/modules/precisoBidAdapter_spec.js b/test/spec/modules/precisoBidAdapter_spec.js
index 78a1615a02e..60cdd43504a 100644
--- a/test/spec/modules/precisoBidAdapter_spec.js
+++ b/test/spec/modules/precisoBidAdapter_spec.js
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import { spec } from '../../../modules/precisoBidAdapter.js';
-import { config } from '../../../src/config.js';
+// simport { config } from '../../../src/config.js';
const DEFAULT_PRICE = 1
const DEFAULT_CURRENCY = 'USD'
@@ -10,8 +10,10 @@ const BIDDER_CODE = 'preciso';
describe('PrecisoAdapter', function () {
let bid = {
+ precisoBid: true,
bidId: '23fhj33i987f',
bidder: 'preciso',
+ buyerUid: 'testuid',
mediaTypes: {
banner: {
sizes: [[DEFAULT_BANNER_WIDTH, DEFAULT_BANNER_HEIGHT]]
@@ -22,15 +24,33 @@ describe('PrecisoAdapter', function () {
sourceid: '0',
publisherId: '0',
mediaType: 'banner',
- region: 'prebid-eu'
+ region: 'IND'
},
userId: {
pubcid: '12355454test'
},
- geo: 'NA',
- city: 'Asia,delhi'
+ user: {
+ geo: {
+ region: 'IND',
+ }
+ },
+ ortb2: {
+ device: {
+ w: 1920,
+ h: 166,
+ dnt: 0,
+ },
+ site: {
+ domain: 'localHost'
+ },
+ source: {
+ tid: 'eaff09b-a1ab-4ec6-a81e-c5a75bc1dde3'
+ }
+
+ }
+
};
describe('isBidRequestValid', function () {
@@ -59,43 +79,17 @@ describe('PrecisoAdapter', function () {
});
it('Returns valid data if array of bids is valid', function () {
let data = serverRequest.data;
- // expect(data).to.be.an('object');
-
- // expect(data).to.have.all.keys('bidId', 'imp', 'site', 'deviceWidth', 'deviceHeight', 'language', 'secure', 'host', 'page', 'placements', 'coppa');
-
- expect(data.deviceWidth).to.be.a('number');
- expect(data.deviceHeight).to.be.a('number');
- expect(data.coppa).to.be.a('number');
- expect(data.language).to.be.a('string');
- // expect(data.secure).to.be.within(0, 1);
- expect(data.host).to.be.a('string');
- expect(data.page).to.be.a('string');
-
- expect(data.city).to.be.a('string');
- expect(data.geo).to.be.a('object');
- // expect(data.userId).to.be.a('string');
- // expect(data.imp).to.be.a('object');
- });
- // it('Returns empty data if no valid requests are passed', function () {
- /// serverRequest = spec.buildRequests([]);
- // let data = serverRequest.data;
- // expect(data.imp).to.be.an('array').that.is.empty;
- // });
- });
-
- describe('with COPPA', function () {
- beforeEach(function () {
- sinon.stub(config, 'getConfig')
- .withArgs('coppa')
- .returns(true);
+ expect(data).to.be.an('object');
+ expect(data.device).to.be.a('object');
+ expect(data.user).to.be.a('object');
+ expect(data.source).to.be.a('object');
+ expect(data.site).to.be.a('object');
});
- afterEach(function () {
- config.getConfig.restore();
- });
-
- it('should send the Coppa "required" flag set to "1" in the request', function () {
- let serverRequest = spec.buildRequests([bid]);
- expect(serverRequest.data.coppa).to.equal(1);
+ it('Returns empty data if no valid requests are passed', function () {
+ delete bid.ortb2.device;
+ serverRequest = spec.buildRequests([bid]);
+ let data = serverRequest.data;
+ expect(data.device).to.be.undefined;
});
});
@@ -147,7 +141,8 @@ describe('PrecisoAdapter', function () {
describe('getUserSyncs', function () {
const syncUrl = 'https://ck.2trk.info/rtb/user/usersync.aspx?id=NA&gdpr=0&gdpr_consent=&us_privacy=&t=4';
const syncOptions = {
- iframeEnabled: true
+ iframeEnabled: true,
+ spec: true
};
let userSync = spec.getUserSyncs(syncOptions);
it('Returns valid URL and type', function () {