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

Onetag update #5503

Merged
merged 13 commits into from
Jul 23, 2020
46 changes: 30 additions & 16 deletions modules/onetagBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,15 @@ function buildRequests(validBidRequests, bidderRequest) {
if (bidderRequest && bidderRequest.userId) {
payload.userId = bidderRequest.userId;
}
if (window.localStorage) {
payload.onetagSid = window.localStorage.getItem('onetag_sid');
}
const payloadString = JSON.stringify(payload);
try {
if (window.localStorage) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Prebid offers a storageManager class to deal with localStorage or cookies. check out, for example, bidder widespaceBidAdapter (https://github.com/prebid/Prebid.js/blob/master/modules/widespaceBidAdapter.js#L9) and how they use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello @musikele , we just pushed the requested changes. Hope you have time enough to review them before your holidays :)

payload.onetagSid = window.localStorage.getItem('onetag_sid');
}
} catch (e) {}
return {
method: 'POST',
url: ENDPOINT,
data: payloadString
data: JSON.stringify(payload)
}
}

Expand Down Expand Up @@ -161,17 +162,22 @@ function onetagRenderer({renderer, width, height, vastXml, adUnitCode}) {
}

function getFrameNesting() {
let frame = window;
let topmostFrame = window;
let parent = window.parent;
let currentFrameNesting = 0;
try {
while (frame !== frame.top) {
while (topmostFrame !== topmostFrame.parent) {
parent = topmostFrame.parent;
// eslint-disable-next-line no-unused-expressions
frame.location.href;
frame = frame.parent;
parent.location.href;
topmostFrame = topmostFrame.parent;
}
} catch (e) {}
} catch (e) {
currentFrameNesting = parent === topmostFrame.top ? 1 : 2;
}
return {
topmostFrame: frame,
currentFrameNesting: frame.top === frame ? 1 : 2
topmostFrame,
currentFrameNesting
}
}

Expand All @@ -198,8 +204,11 @@ function getDocumentVisibility(window) {
function getPageInfo() {
const { topmostFrame, currentFrameNesting } = getFrameNesting();
return {
location: encodeURIComponent(topmostFrame.location.href),
referrer: encodeURIComponent(topmostFrame.document.referrer) || '0',
location: topmostFrame.location.href,
referrer:
topmostFrame.document.referrer !== ''
? topmostFrame.document.referrer
: null,
masked: currentFrameNesting,
wWidth: topmostFrame.innerWidth,
wHeight: topmostFrame.innerHeight,
Expand All @@ -216,7 +225,11 @@ function getPageInfo() {
docHidden: getDocumentVisibility(topmostFrame),
docHeight: topmostFrame.document.body ? topmostFrame.document.body.scrollHeight : null,
hLength: history.length,
timing: getTiming()
timing: getTiming(),
version: {
prebid: '$prebid.version$',
adapter: '1.0.0'
}
};
}

Expand Down Expand Up @@ -256,6 +269,7 @@ function setGeneralInfo(bidRequest) {
this['auctionId'] = bidRequest.auctionId;
this['transactionId'] = bidRequest.transactionId;
this['pubId'] = params.pubId;
this['ext'] = params.ext;
if (params.pubClick) {
this['click'] = params.pubClick;
}
Expand Down Expand Up @@ -326,7 +340,7 @@ function parseSizes(bid) {

function getSizes(sizes) {
const ret = [];
for (let i = 0, lenght = sizes.length; i < lenght; i++) {
for (let i = 0; i < sizes.length; i++) {
const size = sizes[i];
ret.push({width: size[0], height: size[1]})
}
Expand Down
5 changes: 3 additions & 2 deletions test/spec/modules/onetagBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ describe('onetag', function () {
expect(data).to.be.an('object');
expect(data).to.include.all.keys('location', 'referrer', 'masked', 'sHeight', 'sWidth', 'docHeight', 'wHeight', 'wWidth', 'oHeight', 'oWidth', 'aWidth', 'aHeight', 'sLeft', 'sTop', 'hLength', 'bids', 'docHidden', 'xOffset', 'yOffset', 'onetagSid');
expect(data.location).to.be.a('string');
expect(data.masked).to.be.a('number');
expect(data.referrer).to.be.a('string');
expect(data.masked).to.be.oneOf([0, 1, 2]);
expect(data.referrer).to.satisfy(referrer => referrer === null || typeof referrer === 'string');
expect(data.sHeight).to.be.a('number');
expect(data.sWidth).to.be.a('number');
expect(data.wWidth).to.be.a('number');
Expand All @@ -148,6 +148,7 @@ describe('onetag', function () {
expect(data.sTop).to.be.a('number');
expect(data.hLength).to.be.a('number');
expect(data.bids).to.be.an('array');
expect(data.version).to.have.all.keys('prebid', 'adapter');
const bids = data['bids'];
for (let i = 0; i < bids.length; i++) {
const bid = bids[i];
Expand Down