Skip to content

Commit

Permalink
Onetag update (#5503)
Browse files Browse the repository at this point in the history
* Cambia nome variabile us privacy in getUserSyncs

* package-lock

* Fixes bugs, adds version

* Revert "package-lock"

This reverts commit f1b0ede

* Corrects initial adapter version

* Converts bare localStorage access into provided helper's call

Co-authored-by: valentino <v.v@v.v>
Co-authored-by: Nicola <ciao@ciao>
Co-authored-by: francesco <f.orazini@onetag.com>
  • Loading branch information
4 people committed Jul 23, 2020
1 parent 4bd0d32 commit 8786b06
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
51 changes: 34 additions & 17 deletions modules/onetagBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { INSTREAM, OUTSTREAM } from '../src/video.js';
import { Renderer } from '../src/Renderer.js';
import find from 'core-js-pure/features/array/find.js';
const { registerBidder } = require('../src/adapters/bidderFactory.js');
import { getStorageManager } from '../src/storageManager.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';

const storage = getStorageManager();

const ENDPOINT = 'https://onetag-sys.com/prebid-request';
const USER_SYNC_ENDPOINT = 'https://onetag-sys.com/usync/';
Expand Down Expand Up @@ -62,14 +65,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 (storage.hasLocalStorage()) {
payload.onetagSid = storage.getDataFromLocalStorage('onetag_sid');
}
} catch (e) {}
return {
method: 'POST',
url: ENDPOINT,
data: payloadString
data: JSON.stringify(payload)
}
}

Expand Down Expand Up @@ -161,17 +165,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 +207,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 +228,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 +272,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 +343,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
7 changes: 4 additions & 3 deletions test/spec/modules/onetagBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ describe('onetag', function () {
const data = JSON.parse(d);
it('Should contain all keys', 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).to.include.all.keys('location', 'referrer', 'masked', 'sHeight', 'sWidth', 'docHeight', 'wHeight', 'wWidth', 'oHeight', 'oWidth', 'aWidth', 'aHeight', 'sLeft', 'sTop', 'hLength', 'bids', 'docHidden', 'xOffset', 'yOffset', 'timing', 'version');
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

0 comments on commit 8786b06

Please sign in to comment.