• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

prebid / Prebid.js / #294

01 May 2025 06:47PM UTC coverage: 90.113% (+0.09%) from 90.019%
#294

push

travis-ci

prebidjs-release
Prebid 9.42.0 release

42642 of 53640 branches covered (79.5%)

63333 of 70282 relevant lines covered (90.11%)

179.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.5
/modules/uid2IdSystem.js
1
/**
1✔
2
 * This module adds uid2 ID support to the User ID module
3
 * The {@link module:modules/userId} module is required.
4
 * @module modules/uid2IdSystem
5
 * @requires module:modules/userId
6
 */
7

8
import { logInfo, logWarn } from '../src/utils.js';
9
import { submodule } from '../src/hook.js';
10
import {getStorageManager} from '../src/storageManager.js';
11
import {MODULE_TYPE_UID} from '../src/activities/modules.js';
12

13
import { Uid2GetId, Uid2CodeVersion, extractIdentityFromParams } from '../libraries/uid2IdSystemShared/uid2IdSystem_shared.js';
14
import {UID2_EIDS} from '../libraries/uid2Eids/uid2Eids.js';
15

16
/**
17
 * @typedef {import('../modules/userId/index.js').Submodule} Submodule
18
 * @typedef {import('../modules/userId/index.js').SubmoduleConfig} SubmoduleConfig
19
 * @typedef {import('../modules/userId/index.js').ConsentData} ConsentData
20
 * @typedef {import('../modules/userId/index.js').uid2Id} uid2Id
21
 */
22

23
const MODULE_NAME = 'uid2';
1✔
24
const MODULE_REVISION = Uid2CodeVersion;
1✔
25
const PREBID_VERSION = '$prebid.version$';
1✔
26
const UID2_CLIENT_ID = `PrebidJS-${PREBID_VERSION}-UID2Module-${MODULE_REVISION}`;
1✔
27
const LOG_PRE_FIX = 'UID2: ';
1✔
28
const ADVERTISING_COOKIE = '__uid2_advertising_token';
1✔
29

30
// eslint-disable-next-line no-unused-vars
31
const UID2_TEST_URL = 'https://operator-integ.uidapi.com';
1✔
32
const UID2_PROD_URL = 'https://prod.uidapi.com';
1✔
33
const UID2_BASE_URL = UID2_PROD_URL;
1✔
34

35
function createLogger(logger, prefix) {
36
  return function (...strings) {
2✔
37
    logger(prefix + ' ', ...strings);
1,349✔
38
  }
39
}
40

41
const _logInfo = createLogger(logInfo, LOG_PRE_FIX);
1✔
42
const _logWarn = createLogger(logWarn, LOG_PRE_FIX);
1✔
43

44
export const storage = getStorageManager({moduleType: MODULE_TYPE_UID, moduleName: MODULE_NAME});
1✔
45

46
/** @type {Submodule} */
47
export const uid2IdSubmodule = {
1✔
48
  /**
49
   * used to link submodule with config
50
   * @type {string}
51
   */
52
  name: MODULE_NAME,
53

54
  /**
55
   * decode the stored id value for passing to bid requests
56
   * @function
57
   * @param {string} value
58
   * @returns {{uid2:{ id: string } }} or undefined if value doesn't exists
59
   */
60
  decode(value) {
61
    const result = decodeImpl(value);
66✔
62
    _logInfo('UID2 decode returned', result);
66✔
63
    return result;
66✔
64
  },
65

66
  /**
67
   * performs action to obtain id and return a value.
68
   * @function
69
   * @param {SubmoduleConfig} config
70
   * @param {ConsentData|undefined} consentData
71
   * @returns {uid2Id}
72
   */
73
  getId(config, consentData) {
74
    if (consentData?.gdpr?.gdprApplies === true) {
133✔
75
      _logWarn('UID2 is not intended for use where GDPR applies. The UID2 module will not run.');
6✔
76
      return;
6✔
77
    }
78

79
    const mappedConfig = {
127✔
80
      apiBaseUrl: config?.params?.uid2ApiBase ?? UID2_BASE_URL,
253✔
81
      paramToken: config?.params?.uid2Token,
82
      serverCookieName: config?.params?.uid2Cookie ?? config?.params?.uid2ServerCookie,
253✔
83
      storage: config?.params?.storage ?? 'localStorage',
130✔
84
      clientId: UID2_CLIENT_ID,
85
      internalStorage: ADVERTISING_COOKIE
86
    }
87

88
    if (FEATURES.UID2_CSTG) {
127!
89
      mappedConfig.cstg = {
127✔
90
        serverPublicKey: config?.params?.serverPublicKey,
91
        subscriptionId: config?.params?.subscriptionId,
92
        ...extractIdentityFromParams(config?.params ?? {})
127!
93
      }
94
    }
95
    _logInfo(`UID2 configuration loaded and mapped.`, mappedConfig);
127✔
96
    const result = Uid2GetId(mappedConfig, storage, _logInfo, _logWarn);
127✔
97
    _logInfo(`UID2 getId returned`, result);
127✔
98
    return result;
127✔
99
  },
100
  eids: UID2_EIDS
101
};
102

103
function decodeImpl(value) {
104
  if (typeof value === 'string') {
66✔
105
    _logInfo('Found server-only token. Refresh is unavailable for this token.');
4✔
106
    const result = { uid2: { id: value } };
4✔
107
    return result;
4✔
108
  }
109
  if (value.latestToken === 'optout') {
62✔
110
    _logInfo('Found optout token.  Refresh is unavailable for this token.');
1✔
111
    return { uid2: { optout: true } };
1✔
112
  }
113
  if (Date.now() < value.latestToken.identity_expires) {
61!
114
    return { uid2: { id: value.latestToken.advertising_token } };
61✔
115
  }
116
  return null;
×
117
}
118

119
// Register submodule for userId
120
submodule('userId', uid2IdSubmodule);
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc