Skip to content

Commit

Permalink
Adagio: update with external js (prebid#4217)
Browse files Browse the repository at this point in the history
* Add external loader in AdagioBidAdapter

* Change adagioAnalyticsAdapter to "endpoint" type

* Change _setPredictions for a generic method

* Improve AdagioBidAdapter test coverage

* Add features detection in Adagio adapter

* Fix adagioBidAdapter tests

* Add featuresVersion field to bidRequest

* Refacto adagio.queue

* Expose versions in ADAGIO namespace

* Generate a ADAGIO.pageviewId if missing

* Move ad-server events tracking to adagioBidAdapter

* Store adUnitCodes in ADAGIO namespace

* Update documentation

Better description of test parameters.

* Add internal array to prevent empty pbjs.adUnits

* Be sure to access to window.top - does not work in safe-frame env

* Add PrintNumber feature

* Be sure to compute features on window.top

* Bump versions

* Add Post-Bid support

- ad-server events are listen in current window (instead of window.top)
- a new "outerAdUnitElementId" property is set to ADAGIO.pbjsAdUnits array in case of Post-Bid scenario. This property is the 1st parent element id attribute of the iframe in window.top.

* Set pagetype param as optional

* Add AdThink ad-server support

* Improve internal `pbjsAdUnits.sizes` detection

Use the adUnit `mediaTypes.banner.sizes` property if exists to build the `ADAGIO.pbjsAdUnits.sizes`.
The use of the `sizes` root property is deprecated.

* adagioAnalyticsAdapter: add and improve tests

* adagioBidAdapter: add and improve tests

# Conflicts:
#	modules/adagioBidAdapter.js
#	test/spec/modules/adagioBidAdapter_spec.js

* adagioBidAdapter: Bump version 1.5

* Adagio: fix import path

* PostBid: insure window.top is accessible for specifics functions

* Consistency: use Prebid.js utils and fix deprecated

* PostBid: do not build a request if in safeframe

* Bump version 2.0.0

* Try to fix tests without UA stubing

* Try to fix adagioAnalytics failling tests on CI

* Consistency: use Prebid loadExternalScript()

* Add "adagio" to Prebid.js adloader vendor whitelist

* Remove proprietary ad-server listeners

* Add RSA validation to adagio external script
  • Loading branch information
osazos authored and sa1omon committed Nov 28, 2019
1 parent 29c2249 commit 02df81f
Show file tree
Hide file tree
Showing 7 changed files with 1,088 additions and 119 deletions.
52 changes: 44 additions & 8 deletions modules/adagioAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,53 @@

import adapter from '../src/AnalyticsAdapter';
import adapterManager from '../src/adapterManager';
import CONSTANTS from '../src/constants.json';
import * as utils from '../src/utils';

// This config makes Prebid.js call this function on each event:
// `window['AdagioPrebidAnalytics']('on', eventType, args)`
// If it is missing, then Prebid.js will immediately log an error,
// instead of queueing the events until the function appears.
var adagioAdapter = adapter({
global: 'AdagioPrebidAnalytics',
handler: 'on',
analyticsType: 'bundle'
const emptyUrl = '';
const analyticsType = 'endpoint';
const events = Object.keys(CONSTANTS.EVENTS).map(key => CONSTANTS.EVENTS[key]);
const VERSION = '2.0.0';

const adagioEnqueue = function adagioEnqueue(action, data) {
utils.getWindowTop().ADAGIO.queue.push({ action, data, ts: Date.now() });
}

function canAccessTopWindow() {
try {
if (utils.getWindowTop().location.href) {
return true;
}
} catch (error) {
return false;
}
}

let adagioAdapter = Object.assign(adapter({ emptyUrl, analyticsType }), {
track: function({ eventType, args }) {
if (typeof args !== 'undefined' && events.indexOf(eventType) !== -1) {
adagioEnqueue('pb-analytics-event', { eventName: eventType, args });
}
}
});

adagioAdapter.originEnableAnalytics = adagioAdapter.enableAnalytics;

adagioAdapter.enableAnalytics = config => {
if (!canAccessTopWindow()) {
return;
}

const w = utils.getWindowTop();

w.ADAGIO = w.ADAGIO || {};
w.ADAGIO.queue = w.ADAGIO.queue || [];
w.ADAGIO.versions = w.ADAGIO.versions || {};
w.ADAGIO.versions.adagioAnalyticsAdapter = VERSION;

adagioAdapter.originEnableAnalytics(config);
}

adapterManager.registerAnalyticsAdapter({
adapter: adagioAdapter,
code: 'adagio'
Expand Down
2 changes: 1 addition & 1 deletion modules/adagioAnalyticsAdapter.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Overview

Module Name: Adagio Analytics Adapter
Module Type: Adagio Adapter
Module Type: Analytics Adapter
Maintainer: dev@adagio.io

# Description
Expand Down
Loading

0 comments on commit 02df81f

Please sign in to comment.