forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admixerIdSystem.js
107 lines (101 loc) · 3.17 KB
/
admixerIdSystem.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* This module adds AdmixerId to the User ID module
* The {@link module:modules/userId} module is required
* @module modules/admixerIdSubmodule
* @requires module:modules/userId
*/
import { logError, logInfo } from '../src/utils.js'
import { ajax } from '../src/ajax.js';
import { submodule } from '../src/hook.js';
import {getStorageManager} from '../src/storageManager.js';
import {MODULE_TYPE_UID} from '../src/activities/modules.js';
/**
* @typedef {import('../modules/userId/index.js').Submodule} Submodule
* @typedef {import('../modules/userId/index.js').SubmoduleConfig} SubmoduleConfig
* @typedef {import('../modules/userId/index.js').ConsentData} ConsentData
* @typedef {import('../modules/userId/index.js').IdResponse} IdResponse
*/
const NAME = 'admixerId';
export const storage = getStorageManager({moduleType: MODULE_TYPE_UID, moduleName: NAME});
/** @type {Submodule} */
export const admixerIdSubmodule = {
/**
* used to link submodule with config
* @type {string}
*/
name: NAME,
/**
* used to specify vendor id
* @type {number}
*/
gvlid: 511,
/**
* decode the stored id value for passing to bid requests
* @function
* @param {string} value
* @returns {{admixerId:string}}
*/
decode(value) {
return { 'admixerId': value }
},
/**
* performs action to obtain id and return a value in the callback's response argument
* @function
* @param {SubmoduleConfig} [config]
* @param {ConsentData} [consentData]
* @returns {IdResponse|undefined}
*/
getId(config, consentData) {
const {e, p, pid} = (config && config.params) || {};
if (!pid || typeof pid !== 'string') {
logError('admixerId submodule requires partner id to be defined');
return;
}
const gdpr = (consentData && typeof consentData.gdprApplies === 'boolean' && consentData.gdprApplies) ? 1 : 0;
const consentString = gdpr ? consentData.consentString : '';
if (gdpr && !consentString) {
logInfo('Consent string is required to call admixer id.');
return;
}
const url = `https://inv-nets.admixer.net/cntcm.aspx?ssp=${pid}${e ? `&e=${e}` : ''}${p ? `&p=${p}` : ''}${consentString ? `&cs=${consentString}` : ''}`;
const resp = function(callback) {
if (window.admixTMLoad && window.admixTMLoad.push) {
window.admixTMLoad.push(function() {
window.admixTM.retrieveVisitorId(function(visitorId) {
if (visitorId) {
callback(visitorId);
} else {
callback();
}
});
});
} else {
retrieveVisitorId(url, callback);
}
};
return { callback: resp };
},
eids: {
'admixerId': {
source: 'admixer.net',
atype: 3
},
}
};
function retrieveVisitorId(url, callback) {
ajax(url, {
success: response => {
const {setData: {visitorid} = {}} = JSON.parse(response || '{}');
if (visitorid) {
callback(visitorid);
} else {
callback();
}
},
error: error => {
logInfo(`admixerId: fetch encountered an error`, error);
callback();
}
}, undefined, { method: 'GET', withCredentials: true });
}
submodule('userId', admixerIdSubmodule);