Skip to content

Commit

Permalink
required changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kodi committed Sep 22, 2021
1 parent ee3bcb9 commit e1733b6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 31 deletions.
37 changes: 12 additions & 25 deletions modules/cwireBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {registerBidder} from '../src/adapters/bidderFactory.js';
import { getRefererInfo } from '../src/refererDetection.js';
import { getStorageManager } from '../src/storageManager.js';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
import { OUTSTREAM } from '../src/video.js';
import { Renderer } from '../src/Renderer.js';
Expand All @@ -15,6 +16,8 @@ export const CW_PAGE_VIEW_ID = utils.generateUUID();
const LS_CWID_KEY = 'cw_cwid';
const CW_GROUPS_QUERY = 'cwgroups';

const storage = getStorageManager();

/**
* ------------------------------------
* ------------------------------------
Expand All @@ -32,7 +35,6 @@ export function getSlotSizes(bid) {
* @returns {*[]}
*/
export function getAllMediaSizes(bid) {
// eslint-disable-next-line no-debugger
let playerSizes = utils.deepAccess(bid, 'mediaTypes.video.playerSize');
let videoSizes = utils.deepAccess(bid, 'mediaTypes.video.sizes');
let bannerSizes = utils.deepAccess(bid, 'mediaTypes.banner.sizes');
Expand Down Expand Up @@ -60,15 +62,11 @@ export function getAllMediaSizes(bid) {
}

const getQueryVariable = (variable) => {
const query = window.top.location.search.substring(1);
const vars = query.split('&');
for (let i = 0; i < vars.length; i += 1) {
const pair = vars[i].split('=');
if (decodeURIComponent(pair[0]) === variable) {
return decodeURIComponent(pair[1]);
}
let value = utils.getParameterByName(variable);
if (value === '') {
value = null;
}
return null;
return value;
};

/**
Expand Down Expand Up @@ -120,12 +118,12 @@ export const spec = {
}

if (!bid.params.placementId || !utils.isNumber(bid.params.placementId)) {
utils.logError('[CWIRE] placementId not provided or invalid');
utils.logError('placementId not provided or invalid');
return false;
}

if (!bid.params.pageId || !utils.isNumber(bid.params.pageId)) {
utils.logError('[CWIRE] pageId not provided');
utils.logError('pageId not provided');
return false;
}

Expand All @@ -147,7 +145,6 @@ export const spec = {
referer = getRefererInfo().referer;
slots = mapSlotsData(validBidRequests);
} catch (e) {
// eslint-disable-next-line no-console
utils.logWarn(e);
}

Expand All @@ -158,8 +155,10 @@ export const spec = {
refgroups = rgQuery.split(',');
}

const localStorageCWID = storage.localStorageIsEnabled() ? storage.getDataFromLocalStorage(LS_CWID_KEY) : null;

const payload = {
cwid: localStorage.getItem(LS_CWID_KEY),
cwid: localStorageCWID,
refgroups,
slots: slots,
httpRef: referer || '',
Expand Down Expand Up @@ -187,7 +186,6 @@ export const spec = {
bidRequest.data = JSON.parse(bidRequest.data);
}
const serverBody = serverResponse.body;
// const headerValue = serverResponse.headers.get('some-response-header');
serverBody.bids.forEach((br) => {
const bidReq = find(bidRequest.data.slots, bid => bid.bidId === br.requestId);

Expand Down Expand Up @@ -222,8 +220,6 @@ export const spec = {
if (utils.deepAccess(bidReq, 'mediaTypes.video')) {
mediaType = VIDEO;
bidResponse.vastXml = br.vastXml;
// bidResponse.vastUrl = 'data:text/xml;charset=utf-8;base64,' + btoa(br.vastXml.replace(/\\"/g, '"'));
// bidResponse.adResponse = serverBody;
bidResponse.videoScript = br.html;
const mediaTypeContext = utils.deepAccess(bidReq, 'mediaTypes.video.context');
if (mediaTypeContext === OUTSTREAM) {
Expand Down Expand Up @@ -253,7 +249,6 @@ export const spec = {
}

bidResponse.mediaType = mediaType;

bidResponses.push(bidResponse);
});
} catch (e) {
Expand All @@ -262,13 +257,5 @@ export const spec = {

return bidResponses;
},

/**
* Register bidder specific code, which will execute when the adserver targeting has been set for a bid from this bidder
* @param {Bid} The bid of which the targeting has been set
*/
onSetTargeting: function(bid) {
// Bidder specific code
},
}
registerBidder(spec);
14 changes: 8 additions & 6 deletions modules/cwireBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ Connects to C-WIRE demand source to fetch bids.

Below, the list of C-WIRE params and where they can be set.

| Param name | Global config | AdUnit config | Type |
| ---------- | ------------- | ------------- | ---- |
| pageId | | x | number |
| placementId | | x | number |
| Param name | Global config | AdUnit config | Type | Required |
| ---------- | ------------- | ------------- | ---- | ---------|
| pageId | | x | number | YES |
| placementId | | x | number | YES |
| adUnitElementId | | x | string | NO |

### adUnit configuration

Expand All @@ -32,8 +33,9 @@ var adUnits = [
}
},
params: {
pageid: 1422, // required - number
placementid: 2211521, // required - number
pageId: 1422, // required - number
placementId: 2211521, // required - number
adUnitElementId: 'other_div', // optional, div id to write to, if not set it will default to ad unit code
}
}]
}
Expand Down

0 comments on commit e1733b6

Please sign in to comment.