forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlmpIdSystem.js
61 lines (52 loc) · 1.45 KB
/
lmpIdSystem.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
/**
* This module adds lmpId support to the User ID module
* The {@link module:modules/userId} module is required.
* @module modules/lmpIdSystem
* @requires module:modules/userId
*/
import { submodule } from '../src/hook.js';
import { MODULE_TYPE_UID } from '../src/activities/modules.js';
import { getStorageManager } from '../src/storageManager.js';
const MODULE_NAME = 'lmpid';
const STORAGE_KEY = '__lmpid';
export const storage = getStorageManager({ moduleType: MODULE_TYPE_UID, moduleName: MODULE_NAME });
function readFromLocalStorage() {
return storage.localStorageIsEnabled() ? storage.getDataFromLocalStorage(STORAGE_KEY) : null;
}
function getLmpid() {
return window[STORAGE_KEY] || readFromLocalStorage();
}
/** @type {Submodule} */
export const lmpIdSubmodule = {
/**
* used to link submodule with config
* @type {string}
*/
name: MODULE_NAME,
/**
* decode the stored id value for passing to bid requests
* @function
* @param { string | undefined } value
* @return { {lmpid: string} | undefined }
*/
decode(value) {
return value ? { lmpid: value } : undefined;
},
/**
* Retrieve the LMPID
* @function
* @param {SubmoduleConfig} config
* @return {{id: string | undefined} | undefined}
*/
getId(config) {
const id = getLmpid();
return id ? { id } : undefined;
},
eids: {
'lmpid': {
source: 'loblawmedia.ca',
atype: 3
},
}
};
submodule('userId', lmpIdSubmodule);