forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfreepassIdSystem.js
65 lines (50 loc) · 1.88 KB
/
freepassIdSystem.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
import { submodule } from '../src/hook.js';
import { logMessage } from '../src/utils.js';
import { getCoreStorageManager } from '../src/storageManager.js';
const MODULE_NAME = 'freepassId';
export const FREEPASS_COOKIE_KEY = '_f_UF8cCRlr';
export const storage = getCoreStorageManager(MODULE_NAME);
export const freepassIdSubmodule = {
name: MODULE_NAME,
decode: function (value, config) {
logMessage('Decoding FreePass ID: ', value);
return { [MODULE_NAME]: value };
},
getId: function (config, consent, cachedIdObject) {
logMessage('Getting FreePass ID using config: ' + JSON.stringify(config));
const freepassData = config.params !== undefined ? (config.params.freepassData || {}) : {}
const idObject = {};
const userId = storage.getCookie(FREEPASS_COOKIE_KEY);
if (userId !== null) {
idObject.userId = userId;
}
if (freepassData.commonId !== undefined) {
idObject.commonId = config.params.freepassData.commonId;
}
if (freepassData.userIp !== undefined) {
idObject.userIp = config.params.freepassData.userIp;
}
return {id: idObject};
},
extendId: function (config, consent, cachedIdObject) {
const freepassData = config.params.freepassData;
const hasFreepassData = freepassData !== undefined;
if (!hasFreepassData) {
logMessage('No Freepass Data. CachedIdObject will not be extended: ' + JSON.stringify(cachedIdObject));
return {
id: cachedIdObject
};
}
const currentCookieId = storage.getCookie(FREEPASS_COOKIE_KEY);
logMessage('Extending FreePass ID object: ' + JSON.stringify(cachedIdObject));
logMessage('Extending FreePass ID using config: ' + JSON.stringify(config));
return {
id: {
commonId: freepassData.commonId,
userIp: freepassData.userIp,
userId: currentCookieId
}
};
}
};
submodule('userId', freepassIdSubmodule);