• 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

94.12
/modules/euidIdSystem.js
1
/**
1✔
2
 * This module adds EUID ID support to the User ID module. It shares significant functionality with the UID2 module.
3
 * The {@link module:modules/userId} module is required.
4
 * @module modules/euidIdSystem
5
 * @requires module:modules/userId
6
 */
7

8
import { logInfo, logWarn, deepAccess } 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

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

22
const MODULE_NAME = 'euid';
1✔
23
const MODULE_REVISION = Uid2CodeVersion;
1✔
24
const PREBID_VERSION = '$prebid.version$';
1✔
25
const EUID_CLIENT_ID = `PrebidJS-${PREBID_VERSION}-EUIDModule-${MODULE_REVISION}`;
1✔
26
const GVLID_TTD = 21; // The Trade Desk
1✔
27
const LOG_PRE_FIX = 'EUID: ';
1✔
28
const ADVERTISING_COOKIE = '__euid_advertising_token';
1✔
29

30
// eslint-disable-next-line no-unused-vars
31
const EUID_TEST_URL = 'https://integ.euid.eu';
1✔
32
const EUID_PROD_URL = 'https://prod.euid.eu';
1✔
33
const EUID_BASE_URL = EUID_PROD_URL;
1✔
34

35
function createLogger(logger, prefix) {
36
  return function (...strings) {
2✔
37
    logger(prefix + ' ', ...strings);
77✔
38
  }
39
}
40
const _logInfo = createLogger(logInfo, LOG_PRE_FIX);
1✔
41
const _logWarn = createLogger(logWarn, LOG_PRE_FIX);
1✔
42

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

45
function hasWriteToDeviceConsent(consentData) {
46
  const gdprApplies = consentData?.gdprApplies === true;
8✔
47
  const localStorageConsent = deepAccess(consentData, `vendorData.purpose.consents.1`)
8✔
48
  const prebidVendorConsent = deepAccess(consentData, `vendorData.vendor.consents.${GVLID_TTD.toString()}`)
8✔
49
  if (gdprApplies && (!localStorageConsent || !prebidVendorConsent)) {
8✔
50
    return false;
1✔
51
  }
52
  return true;
7✔
53
}
54

55
/** @type {Submodule} */
56
export const euidIdSubmodule = {
1✔
57
  /**
58
   * used to link submodule with config
59
   * @type {string}
60
   */
61
  name: MODULE_NAME,
62

63
  /**
64
   * Vendor id of The Trade Desk
65
   * @type {Number}
66
   */
67
  gvlid: GVLID_TTD,
68
  /**
69
   * decode the stored id value for passing to bid requests
70
   * @function
71
   * @param {string} value
72
   * @returns {{euid:{ id: string } }} or undefined if value doesn't exists
73
   */
74
  decode(value) {
75
    const result = decodeImpl(value);
6✔
76
    _logInfo('EUID decode returned', result);
6✔
77
    return result;
6✔
78
  },
79

80
  /**
81
   * performs action to obtain id and return a value.
82
   * @function
83
   * @param {SubmoduleConfig} [config]
84
   * @param {ConsentData|undefined} consentData
85
   * @returns {IdResponse}
86
   */
87
  getId(config, consentData) {
88
    if (consentData?.gdpr?.gdprApplies !== true) {
8!
89
      logWarn('EUID is intended for use within the EU. The module will not run when GDPR does not apply.');
×
90
      return;
×
91
    }
92
    if (!hasWriteToDeviceConsent(consentData?.gdpr)) {
8✔
93
      // The module cannot operate without this permission.
94
      _logWarn(`Unable to use EUID module due to insufficient consent. The EUID module requires storage permission.`)
1✔
95
      return;
1✔
96
    }
97

98
    const mappedConfig = {
7✔
99
      apiBaseUrl: config?.params?.euidApiBase ?? EUID_BASE_URL,
14✔
100
      paramToken: config?.params?.euidToken,
101
      serverCookieName: config?.params?.euidCookie,
102
      storage: config?.params?.storage ?? 'localStorage',
8✔
103
      clientId: EUID_CLIENT_ID,
104
      internalStorage: ADVERTISING_COOKIE
105
    };
106

107
    if (FEATURES.UID2_CSTG) {
7!
108
      mappedConfig.cstg = {
7✔
109
        serverPublicKey: config?.params?.serverPublicKey,
110
        subscriptionId: config?.params?.subscriptionId,
111
        ...extractIdentityFromParams(config?.params ?? {})
8✔
112
      }
113
    }
114
    _logInfo(`EUID configuration loaded and mapped.`, mappedConfig);
7✔
115
    const result = Uid2GetId(mappedConfig, storage, _logInfo, _logWarn);
7✔
116
    _logInfo(`EUID getId returned`, result);
7✔
117
    return result;
7✔
118
  },
119
  eids: {
120
    'euid': {
121
      source: 'euid.eu',
122
      atype: 3,
123
      getValue: function(data) {
124
        return data.id;
15✔
125
      }
126
    },
127
  },
128
};
129

130
function decodeImpl(value) {
131
  if (typeof value === 'string') {
6✔
132
    _logInfo('Found server-only token. Refresh is unavailable for this token.');
1✔
133
    const result = { euid: { id: value } };
1✔
134
    return result;
1✔
135
  }
136
  if (value.latestToken === 'optout') {
5✔
137
    _logInfo('Found optout token.  Refresh is unavailable for this token.');
1✔
138
    return { euid: { optout: true } };
1✔
139
  }
140
  if (Date.now() < value.latestToken.identity_expires) {
4!
141
    return { euid: { id: value.latestToken.advertising_token } };
4✔
142
  }
143
  return null;
×
144
}
145

146
// Register submodule for userId
147
submodule('userId', euidIdSubmodule);
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