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

prebid / Prebid.js / #283

20 Feb 2025 06:08PM UTC coverage: 90.519% (-0.005%) from 90.524%
#283

push

travis-ci

prebidjs-release
Prebid 9.31.0 release

41886 of 52458 branches covered (79.85%)

62085 of 68588 relevant lines covered (90.52%)

203.0 hits per line

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

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

8
import {submodule} from '../src/hook.js';
9
import {getStorageManager} from '../src/storageManager.js';
10
import {ajax} from '../src/ajax.js';
11
import { parseUrl, buildUrl, logError } from '../src/utils.js';
12
import {MODULE_TYPE_UID} from '../src/activities/modules.js';
13

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

21
const MODULE_NAME = 'publinkId';
1✔
22
const GVLID = 24;
1✔
23
const PUBLINK_COOKIE = '_publink';
1✔
24
const PUBLINK_S2S_COOKIE = '_publink_srv';
1✔
25
const PUBLINK_REQUEST_PATH = '/cvx/client/sync/publink';
1✔
26
const PUBLINK_REFRESH_PATH = '/cvx/client/sync/publink/refresh';
1✔
27

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

30
function isHex(s) {
31
  return /^[A-F0-9]+$/i.test(s);
5✔
32
}
33

34
function publinkIdUrl(params, consentData, storedId) {
35
  let url = parseUrl('https://proc.ad.cpe.dotomi.com' + PUBLINK_REFRESH_PATH);
5✔
36
  url.search = {
5✔
37
    mpn: 'Prebid.js',
38
    mpv: '$prebid.version$',
39
  };
40

41
  if (consentData?.gdpr) {
5✔
42
    url.search.gdpr = (consentData.gdpr.gdprApplies) ? 1 : 0;
1!
43
    url.search.gdpr_consent = consentData.gdpr.consentString;
1✔
44
  }
45

46
  if (params) {
5✔
47
    if (params.e) {
4!
48
      // if there's an email parameter call the request path
49
      url.search.deh = params.e;
4✔
50
      url.pathname = PUBLINK_REQUEST_PATH;
4✔
51
    }
52

53
    if (params.site_id) { url.search.sid = params.site_id; }
4✔
54

55
    if (params.api_key) { url.search.apikey = params.api_key; }
4✔
56
  }
57

58
  if (storedId) {
5✔
59
    url.search.publink = storedId;
2✔
60
  }
61

62
  const usPrivacyString = consentData?.usp;
5✔
63
  if (usPrivacyString && typeof usPrivacyString === 'string') {
5✔
64
    url.search.us_privacy = usPrivacyString;
1✔
65
  }
66

67
  return buildUrl(url);
5✔
68
}
69

70
function makeCallback(config = {}, consentData, storedId) {
1✔
71
  return function(prebidCallback) {
7✔
72
    const options = {method: 'GET', withCredentials: true};
6✔
73
    let handleResponse = function(responseText, xhr) {
6✔
74
      if (xhr.status === 200) {
5✔
75
        let response = JSON.parse(responseText);
4✔
76
        if (response) {
4!
77
          prebidCallback(response.publink);
4✔
78
        }
79
      }
80
    };
81
    if ((config.params && config.params.e && isHex(config.params.e)) || storedId) {
6✔
82
      ajax(publinkIdUrl(config.params, consentData, storedId), handleResponse, undefined, options);
5✔
83
    } else if (config.params.e) {
1!
84
      logError('params.e must be a hex string');
1✔
85
    }
86
  }
87
}
88

89
function getlocalValue() {
90
  let result;
91
  function getData(key) {
92
    let value;
93
    if (storage.hasLocalStorage()) {
23!
94
      value = storage.getDataFromLocalStorage(key);
23✔
95
    }
96
    if (!value) {
23✔
97
      value = storage.getCookie(key);
21✔
98
    }
99

100
    if (typeof value === 'string') {
23✔
101
      // if it's a json object parse it and return the publink value, otherwise assume the value is the id
102
      if (value.charAt(0) === '{') {
6✔
103
        try {
5✔
104
          const obj = JSON.parse(value);
5✔
105
          if (obj) {
5!
106
            return obj.publink;
5✔
107
          }
108
        } catch (e) {
109
          logError(e);
×
110
        }
111
      } else {
112
        return value;
1✔
113
      }
114
    }
115
  }
116
  result = getData(PUBLINK_S2S_COOKIE);
13✔
117
  if (!result) {
13✔
118
    result = getData(PUBLINK_COOKIE);
10✔
119
  }
120
  return result;
13✔
121
}
122

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

132
  /**
133
   * decode the stored id value for passing to bid requests
134
   * @function
135
   * @param {string} publinkId encrypted userid
136
   * @returns {{publinkId: string} | undefined}
137
   */
138
  decode(publinkId) {
139
    return {publinkId: publinkId};
1✔
140
  },
141

142
  /**
143
   * performs action to obtain id
144
   * Use a publink cookie first if it is present, otherwise use prebids copy, if neither are available callout to get a new id
145
   * @function
146
   * @param {SubmoduleConfig} [config] Config object with params and storage properties
147
   * @param {ConsentData|undefined} consentData GDPR consent
148
   * @param {(Object|undefined)} storedId Previously cached id
149
   * @returns {IdResponse}
150
   */
151
  getId: function(config, consentData, storedId) {
152
    const localValue = getlocalValue();
13✔
153
    if (localValue) {
13✔
154
      return {id: localValue};
6✔
155
    }
156
    return {callback: makeCallback(config, consentData, storedId)};
7✔
157
  },
158
  eids: {
159
    'publinkId': {
160
      source: 'epsilon.com',
161
      atype: 3
162
    },
163
  },
164
};
165
submodule('userId', publinkIdSubmodule);
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