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

prebid / Prebid.js / #304

24 Jun 2025 05:14PM UTC coverage: 90.422% (+0.02%) from 90.403%
#304

push

travis-ci

prebidjs-release
Prebid 9.51.0 release

43346 of 54399 branches covered (79.68%)

64092 of 70881 relevant lines covered (90.42%)

174.66 hits per line

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

92.16
/libraries/liveIntentId/externalIdSystem.js
1
import { logError } from '../../src/utils.js';
2
import { gdprDataHandler, uspDataHandler, gppDataHandler } from '../../src/adapterManager.js';
3
import { submodule } from '../../src/hook.js';
4
import { DEFAULT_AJAX_TIMEOUT, MODULE_NAME, parseRequestedAttributes, composeResult, eids, GVLID, PRIMARY_IDS, makeSourceEventToSend, setUpTreatment } from './shared.js'
5

6
// Reference to the client for the liQHub.
7
let cachedClientRef
8

9
/**
10
 * This function is used in tests.
11
 */
12
export function resetSubmodule() {
13
  cachedClientRef = undefined
46✔
14
}
15

16
window.liQHub = window.liQHub ?? []
1✔
17

18
function initializeClient(configParams) {
19
  // Only initialize once.
20
  if (cachedClientRef != null) return cachedClientRef
47✔
21

22
  const clientRef = {}
46✔
23

24
  const clientDetails = { name: 'prebid', version: '$prebid.version$' }
46✔
25

26
  const collectConfig = configParams.liCollectConfig ?? {};
46✔
27

28
  let integration
29
  if (collectConfig.appId != null) {
46✔
30
    integration = { type: 'application', appId: collectConfig.appId, publisherId: configParams.publisherId }
2✔
31
  } else if (configParams.distributorId != null && configParams.publisherId == null) {
44!
32
    integration = { type: 'distributor', distributorId: configParams.distributorId }
×
33
  } else {
34
    integration = { type: 'custom', publisherId: configParams.publisherId, distributorId: configParams.distributorId }
44✔
35
  }
36

37
  const partnerCookies = new Set(configParams.identifiersToResolve ?? []);
46✔
38

39
  const collectSettings = { timeout: collectConfig.ajaxTimeout ?? DEFAULT_AJAX_TIMEOUT }
46✔
40

41
  let identityPartner
42
  if (collectConfig.appId == null && configParams.distributorId != null) {
46✔
43
    identityPartner = configParams.distributorId
2✔
44
  } else if (configParams.partner != null) {
44!
45
    identityPartner = configParams.partner
×
46
  } else {
47
    identityPartner = 'prebid'
44✔
48
  }
49

50
  const resolveSettings = {
46✔
51
    identityPartner,
52
    timeout: configParams.ajaxTimeout ?? DEFAULT_AJAX_TIMEOUT
92✔
53
  }
54

55
  function loadConsent() {
56
    const consent = {}
46✔
57
    const usPrivacyString = uspDataHandler.getConsentData();
46✔
58
    if (usPrivacyString != null) {
46✔
59
      consent.usPrivacy = { consentString: usPrivacyString }
2✔
60
    }
61
    const gdprConsent = gdprDataHandler.getConsentData()
46✔
62
    if (gdprConsent != null) {
46✔
63
      consent.gdpr = gdprConsent
2✔
64
    }
65
    const gppConsent = gppDataHandler.getConsentData();
46✔
66
    if (gppConsent != null) {
46✔
67
      consent.gpp = { consentString: gppConsent.gppString, applicableSections: gppConsent.applicableSections }
2✔
68
    }
69

70
    return consent
46✔
71
  }
72
  const consent = loadConsent()
46✔
73

74
  window.liQHub.push({
46✔
75
    type: 'register_client',
76
    clientRef,
77
    clientDetails,
78
    integration,
79
    consent,
80
    partnerCookies,
81
    collectSettings,
82
    resolveSettings
83
  })
84

85
  let sourceEvent = makeSourceEventToSend(configParams)
46✔
86
  if (sourceEvent != null) {
46✔
87
    window.liQHub.push({ type: 'collect', clientRef, sourceEvent })
5✔
88
  }
89

90
  cachedClientRef = clientRef
46✔
91
  return clientRef
46✔
92
}
93

94
/**
95
 * Create requestedAttributes array to pass to LiveConnect.
96
 * @function
97
 * @param {Object} overrides - object with boolean values that will override defaults { 'foo': true, 'bar': false }
98
 * @returns {Array}
99
 */
100

101
function resolve(configParams, clientRef, callback) {
102
  function onFailure(error) {
103
    logError(`${MODULE_NAME}: ID fetch encountered an error: `, error);
×
104
    callback();
×
105
  }
106

107
  const onSuccess = [{ type: 'callback', callback }]
11✔
108

109
  window.liQHub.push({
11✔
110
    type: 'resolve',
111
    clientRef,
112
    requestedAttributes: parseRequestedAttributes(configParams.requestedAttributesOverrides),
113
    onFailure,
114
    onSuccess
115
  })
116
}
117

118
/**
119
 * @typedef {import('../../modules/userId/index.js').Submodule} Submodule
120
 */
121

122
/** @type {Submodule} */
123
export const liveIntentExternalIdSubmodule = {
1✔
124
  /**
125
   * Used to link submodule with config.
126
   * @type {string}
127
   */
128
  name: MODULE_NAME,
129
  gvlid: GVLID,
130

131
  /**
132
   * Decode the stored id value for passing to bid requests.
133
   * @function
134
   */
135
  decode(value, config) {
136
    const configParams = config?.params ?? {};
36!
137
    setUpTreatment(configParams);
36✔
138

139
    // Ensure client is initialized and we fired at least one collect request.
140
    initializeClient(configParams)
36✔
141

142
    return composeResult(value, configParams)
36✔
143
  },
144

145
  /**
146
   * Performs action to obtain id and return a value in the callback's response argument.
147
   * @function
148
   */
149
  getId(config) {
150
    const configParams = config?.params ?? {};
11!
151
    setUpTreatment(configParams);
11✔
152

153
    const clientRef = initializeClient(configParams)
11✔
154

155
    return { callback: function(cb) { resolve(configParams, clientRef, cb); } };
11✔
156
  },
157
  primaryIds: PRIMARY_IDS,
158
  eids
159
};
160

161
submodule('userId', liveIntentExternalIdSubmodule);
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