forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaaxBlockmeterRtdProvider.js
60 lines (50 loc) · 1.81 KB
/
aaxBlockmeterRtdProvider.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import {isEmptyStr, isStr, logError, isFn, logWarn} from '../src/utils.js';
import {submodule} from '../src/hook.js';
import { loadExternalScript } from '../src/adloader.js';
import { MODULE_TYPE_RTD } from '../src/activities/modules.js';
export const _config = {
MODULE: 'aaxBlockmeter',
ADSERVER_TARGETING_KEY: 'atk',
BLOCKMETER_URL: 'c.aaxads.com/aax.js',
VERSION: '1.2'
};
window.aax = window.aax || {};
function loadBlockmeter(_rtdConfig) {
if (!(_rtdConfig.params && _rtdConfig.params.pub) || !isStr(_rtdConfig.params && _rtdConfig.params.pub) || isEmptyStr(_rtdConfig.params && _rtdConfig.params.pub)) {
logError(`${_config.MODULE}: params.pub should be a string`);
return false;
}
const params = [];
params.push(`pub=${_rtdConfig.params.pub}`);
params.push(`dn=${window.location.hostname}`);
let url = _rtdConfig.params.url;
if (!url || isEmptyStr(url)) {
logWarn(`${_config.MODULE}: params.url is missing, using default url.`);
url = `${_config.BLOCKMETER_URL}?ver=${_config.VERSION}`;
}
const scriptUrl = `https://${url}&${params.join('&')}`;
loadExternalScript(scriptUrl, MODULE_TYPE_RTD, _config.MODULE);
return true;
}
function markAdBlockInventory(codes, _rtdConfig, _userConsent) {
return codes.reduce((targets, code) => {
targets[code] = targets[code] || {};
const getAaxTargets = () => isFn(window.aax.getTargetingData)
? window.aax.getTargetingData(code, _rtdConfig, _userConsent)
: {};
targets[code] = {
[_config.ADSERVER_TARGETING_KEY]: code,
...getAaxTargets()
};
return targets;
}, {});
}
export const aaxBlockmeterRtdModule = {
name: _config.MODULE,
init: loadBlockmeter,
getTargetingData: markAdBlockInventory,
};
function registerSubModule() {
submodule('realTimeData', aaxBlockmeterRtdModule);
}
registerSubModule();