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

prebid / Prebid.js / 22938484646

11 Mar 2026 05:36AM UTC coverage: 96.325% (-0.005%) from 96.33%
22938484646

Pull #14576

github

8256e6
tccdeniz
Adplus ID: Fixed codex review issues
Pull Request #14576: Adplus id v2 updates

57001 of 69728 branches covered (81.75%)

71 of 93 new or added lines in 3 files covered. (76.34%)

1 existing line in 1 file now uncovered.

217581 of 225881 relevant lines covered (96.33%)

70.51 hits per line

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

68.92
/modules/adplusIdSystem.js
1
/**
1✔
2
 * This module adds AdPlus ID system to the User ID module
3
 * The {@link module:modules/userId} module is required
4
 * @module modules/adplusIdSystem
5
 * @requires module:modules/userId
6
 */
7
import {
8
  logError,
9
  logWarn,
10
  isPlainObject,
11
} from '../src/utils.js';
12
import {
13
  ajax
14
} from '../src/ajax.js'
15
import {
16
  submodule
17
} from '../src/hook.js';
18
import {
19
  getStorageManager
20
} from '../src/storageManager.js';
21
import { MODULE_TYPE_UID } from '../src/activities/modules.js';
22

23
const MODULE_NAME = 'adplusId';
1✔
24

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

27
export const ADPLUS_UID_NAME = '_adplus_uid_v2';
1✔
28
export const ADPLUS_PB_CLIENT_ID = 'xqkDY946ohWmBm3gWXDTfD';
1✔
29
export const API_URL = `https://id.ad-plus.com.tr/v2?client_id=${ADPLUS_PB_CLIENT_ID}`;
1✔
30
export const ROTATION_INTERVAL = 1 * 60 * 60 * 1000; // 1 Hour
1✔
31
const LOG_PREFIX = 'User ID - adplusId submodule: ';
1✔
32

33
/**
34
 * @returns {Object} -
35
 */
36
function getIdFromStorage() {
37
  try {
2✔
38
    const lsDt = storage.getDataFromLocalStorage(ADPLUS_UID_NAME);
2✔
39

40
    if (lsDt) {
2!
NEW
41
      return JSON.parse(lsDt);
×
42
    }
43

44
    const cookieDt = storage.getCookie(ADPLUS_UID_NAME);
2✔
45

46
    if (cookieDt) {
2✔
47
      return JSON.parse(cookieDt);
1✔
48
    }
49
  } catch (error) {
NEW
50
    logError(LOG_PREFIX + error);
×
NEW
51
    clearStorage();
×
52
  }
53
}
54

55
/**
56
 * clears adplus id values from storage
57
 * @returns {void} -
58
 */
59
function clearStorage() {
NEW
60
  storage.removeDataFromLocalStorage(ADPLUS_UID_NAME)
×
NEW
61
  storage.setCookie(
×
62
    ADPLUS_UID_NAME,
63
    "",
64
    "Thu, 01 Jan 1970 00:00:00 UTC",
65
    'none'
66
  );
67
}
68

69
/**
70
 * set uid to cookie.
71
 * @param {string} value -
72
 * @returns {void} -
73
 */
74
function setAdplusIdToCookie(value) {
75
  if (value) {
1✔
76
    if (value.expiresIn === -1) {
1!
77
      // Uid expired
NEW
78
      logWarn(LOG_PREFIX + 'AdPlus ID expired');
×
NEW
79
      clearStorage();
×
NEW
80
      return;
×
81
    }
82

83
    let expiresIn = 0;
1✔
84

85
    if (value.expiresIn == null || value.expiresIn === -2) {
1!
NEW
86
      expiresIn = (ROTATION_INTERVAL * 3) - 1000
×
87
    } else {
88
      expiresIn = value.expiresIn * 1000
1✔
89
    }
90

91
    const now = Date.now();
1✔
92

93
    let data = {
1✔
94
      uid: value.uid,
95
      atype: value.atype,
96
      expiresAt: now + expiresIn,
97
      rotateAt: now + ROTATION_INTERVAL,
98
    };
99

100
    const json = JSON.stringify(data);
1✔
101

102
    storage.setDataInLocalStorage(ADPLUS_UID_NAME, json);
1✔
103

104
    const expires = new Date(data.expiresAt).toUTCString()
1✔
105
    storage.setCookie(
1✔
106
      ADPLUS_UID_NAME,
107
      json,
108
      expires,
109
      'none'
110
    );
111
  }
112
}
113

114
/**
115
 * @param {boolean} isRotate - Determines whether the request is for rotation
116
 * @param {string} uid - UID to rotate
117
 * @param {function} callback - Callback
118
 * @returns {{callback: function}} - Callback function
119
 */
120
function fetchAdplusId(isRotate, uid, callback) {
121
  let apiUrl = API_URL;
1✔
122

123
  const storageOk = storage.cookiesAreEnabled() || storage.localStorageIsEnabled();
1✔
124
  apiUrl = `${apiUrl}&storage_ok=${storageOk ? "1" : "0"}`;
1!
125

126
  if (isRotate && uid) {
1!
NEW
127
    apiUrl = `${apiUrl}&old_uid=${uid}`;
×
128
  }
129

130
  ajax(apiUrl, {
1✔
131
    success: (response) => {
132
      if (response) {
1!
133
        try {
1✔
134
          const data = JSON.parse(response);
1✔
135
          if (data == null || !data.uid) {
1!
136
            logWarn(LOG_PREFIX + 'AdPlus ID is null');
×
137
            return callback();
×
138
          }
139
          setAdplusIdToCookie(data);
1✔
140
          callback(data);
1✔
141
        } catch (error) {
142
          logError(LOG_PREFIX + error);
×
143
          callback();
×
144
        }
145
      } else {
NEW
146
        logError(LOG_PREFIX + 'No uid returned.');
×
NEW
147
        callback();
×
148
      }
149
    },
150
    error: (error) => {
151
      logError(LOG_PREFIX + error);
×
152
      callback();
×
153
    }
154
  }, undefined, {
155
    method: 'GET',
156
    withCredentials: true
157
  });
158
}
159

160
export const adplusIdSystemSubmodule = {
1✔
161
  /**
162
   * used to link submodule with config
163
   * @type {string}
164
   */
165
  name: MODULE_NAME,
166

167
  /**
168
   * decode the stored id value for passing to bid requests
169
   * @function
170
   * @returns {{adplusId: string} | undefined}
171
   */
172
  decode(value) {
173
    if (value && isPlainObject(value)) {
5✔
174
      return { 'adplusId': { id: value.uid, atype: value.atype } };
3✔
175
    }
176
  },
177

178
  /**
179
   * performs action to obtain id
180
   * @function
181
   * @returns {{id: string | undefined }}
182
   */
183
  getId(config, consentData) {
184
    const dt = getIdFromStorage();
2✔
185

186
    if (dt) {
2✔
187
      const now = Date.now();
1✔
188
      if (dt.expiresAt && dt.expiresAt <= now) {
1!
NEW
189
        clearStorage();
×
NEW
190
        return {
×
191
          callback: function (callback) {
NEW
192
            fetchAdplusId(false, "", callback);
×
193
          }
194
        };
195
      }
196

197
      const rotate = dt.rotateAt && dt.rotateAt <= now;
1✔
198
      if (rotate) {
1!
NEW
199
        return {
×
200
          id: dt,
201
          callback: function (callback) {
NEW
202
            fetchAdplusId(true, dt.uid, callback);
×
203
          }
204
        };
205
      }
206

207
      return {
1✔
208
        id: dt,
209
      };
210
    }
211

212
    return {
1✔
213
      callback: function (callback) {
214
        fetchAdplusId(false, "", callback);
1✔
215
      }
216
    };
217
  },
218
  eids: {
219
    adplusId: function (values, _) {
220
      return [
1✔
221
        {
222
          source: 'ad-plus.com.tr',
223
          uids: values.map(function (value) {
224
            return {
1✔
225
              id: value.id,
226
              atype: value.atype
227
            };
228
          })
229
        }
230
      ];
231
    }
232
  }
233
};
234

235
submodule('userId', adplusIdSystemSubmodule);
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