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

Improve Digital adapter: support for latest RAZR creative tags #12

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
72 changes: 69 additions & 3 deletions modules/improvedigitalBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js';
import {Renderer} from '../src/Renderer.js';
import {createEidsArray} from './userId/eids.js';
import {hasPurpose1Consent} from '../src/utils/gpdr.js';
import {loadExternalScript} from '../src/adloader.js';

const BIDDER_CODE = 'improvedigital';
const CREATIVE_TTL = 300;
Expand Down Expand Up @@ -208,7 +209,13 @@ export const spec = {

ID_RESPONSE.buildAd(bid, bidRequest, bidObject);

ID_RAZR.addBidData({
ID_RAZR.forwardBid({
bidRequest,
bid
});

// to be phased out:
ID_RAZR_LEGACY.addBidData({
bidRequest,
bid
});
Expand Down Expand Up @@ -636,7 +643,66 @@ const ID_OUTSTREAM = {
};

const ID_RAZR = {
RENDERER_URL: 'https://razr.improvedigital.com/renderer.js',
RENDERER_URL: 'https://cdn.360yield.com/razr/tag.js',

forwardBid({bidRequest, bid}) {
if (bid.mediaType !== BANNER) {
return;
}

const cfg = {
prebid: {
bidRequest,
bid
}
};

const cfgStr = JSON.stringify(cfg).replace(/<\/script>/g, '\\x3C/script>');
const s = `<script>window.__razr_config = ${cfgStr};</script>`;
bid.ad = bid.ad.replace(/<body[^>]*>/, match => match + s);

this.installListener();
},

installListener() {
if (this._listenerInstalled) {
return;
}

window.addEventListener('message', function(e) {
const data = e.data && e.data.razr && e.data.razr.load;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be made shorter with the optional chaining syntax ?.

if (!data) {
return;
}

if (e.source) {
data.source = e.source;
if (data.id) {
e.source.postMessage({
razr: {
id: data.id
}
}, '*');
}
}

const ns = window.razr = window.razr || {};
ns.q = ns.q || [];
ns.q.push(data);

if (!ns.loaded) {
loadExternalScript(ID_RAZR.RENDERER_URL, BIDDER_CODE);
}
});

this._listenerInstalled = true;
}
};

// to be phased out:
const ID_RAZR_LEGACY = {
RENDERER_URL: 'https://cdn.360yield.com/razr/legacy/renderer.js',

addBidData({bid, bidRequest}) {
if (this.isValidBid(bid)) {
bid.renderer = Renderer.install({
Expand All @@ -648,7 +714,7 @@ const ID_RAZR = {
},

isValidBid(bid) {
return bid && /razr:\/\//.test(bid.ad);
return bid && /razr:\/\//.test(bid.ad) && !/data-razr-uri/.test(bid.ad);
},

render(bid) {
Expand Down
3 changes: 2 additions & 1 deletion src/adloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const _approvedLoadExternalJSList = [
'ftrackId',
'inskin',
'hadron',
'medianet'
'medianet',
'improvedigital'
]

/**
Expand Down