Skip to content

Commit 02df81f

Browse files
osazossa1omon
authored andcommitted
Adagio: update with external js (prebid#4217)
* 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
1 parent 29c2249 commit 02df81f

File tree

7 files changed

+1088
-119
lines changed

7 files changed

+1088
-119
lines changed

modules/adagioAnalyticsAdapter.js

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,53 @@
44

55
import adapter from '../src/AnalyticsAdapter';
66
import adapterManager from '../src/adapterManager';
7+
import CONSTANTS from '../src/constants.json';
8+
import * as utils from '../src/utils';
79

8-
// This config makes Prebid.js call this function on each event:
9-
// `window['AdagioPrebidAnalytics']('on', eventType, args)`
10-
// If it is missing, then Prebid.js will immediately log an error,
11-
// instead of queueing the events until the function appears.
12-
var adagioAdapter = adapter({
13-
global: 'AdagioPrebidAnalytics',
14-
handler: 'on',
15-
analyticsType: 'bundle'
10+
const emptyUrl = '';
11+
const analyticsType = 'endpoint';
12+
const events = Object.keys(CONSTANTS.EVENTS).map(key => CONSTANTS.EVENTS[key]);
13+
const VERSION = '2.0.0';
14+
15+
const adagioEnqueue = function adagioEnqueue(action, data) {
16+
utils.getWindowTop().ADAGIO.queue.push({ action, data, ts: Date.now() });
17+
}
18+
19+
function canAccessTopWindow() {
20+
try {
21+
if (utils.getWindowTop().location.href) {
22+
return true;
23+
}
24+
} catch (error) {
25+
return false;
26+
}
27+
}
28+
29+
let adagioAdapter = Object.assign(adapter({ emptyUrl, analyticsType }), {
30+
track: function({ eventType, args }) {
31+
if (typeof args !== 'undefined' && events.indexOf(eventType) !== -1) {
32+
adagioEnqueue('pb-analytics-event', { eventName: eventType, args });
33+
}
34+
}
1635
});
1736

37+
adagioAdapter.originEnableAnalytics = adagioAdapter.enableAnalytics;
38+
39+
adagioAdapter.enableAnalytics = config => {
40+
if (!canAccessTopWindow()) {
41+
return;
42+
}
43+
44+
const w = utils.getWindowTop();
45+
46+
w.ADAGIO = w.ADAGIO || {};
47+
w.ADAGIO.queue = w.ADAGIO.queue || [];
48+
w.ADAGIO.versions = w.ADAGIO.versions || {};
49+
w.ADAGIO.versions.adagioAnalyticsAdapter = VERSION;
50+
51+
adagioAdapter.originEnableAnalytics(config);
52+
}
53+
1854
adapterManager.registerAnalyticsAdapter({
1955
adapter: adagioAdapter,
2056
code: 'adagio'

modules/adagioAnalyticsAdapter.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Overview
22

33
Module Name: Adagio Analytics Adapter
4-
Module Type: Adagio Adapter
4+
Module Type: Analytics Adapter
55
Maintainer: [email protected]
66

77
# Description

0 commit comments

Comments
 (0)