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

prebid / Prebid.js / 16523546236

25 Jul 2025 01:47PM UTC coverage: 96.268% (+0.004%) from 96.264%
16523546236

push

github

web-flow
add new appnews alias newdream (#13670)

Co-authored-by: Damian <dares@gtsur.com>

39403 of 48408 branches covered (81.4%)

194817 of 202370 relevant lines covered (96.27%)

83.36 hits per line

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

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

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

13
const GVL_ID = 898;
1✔
14
const MODULE_NAME = 'mobkoiId';
1✔
15
/**
16
 * The base URL for the mobkoi integration. It should provide the following endpoints:
17
 * - /pixeliframe
18
 * - /getPixel
19
 */
20
export const PROD_PREBID_JS_INTEGRATION_BASE_URL = 'https://pbjs.mobkoi.com';
1✔
21
export const EQUATIV_BASE_URL = 'https://sync.smartadserver.com';
1✔
22
export const EQUATIV_NETWORK_ID = '5290';
1✔
23

24
/**
25
 * The parameters that the publisher defined in the userSync.userIds[].params
26
 */
27
const USER_SYNC_PARAMS = {
1✔
28
  /**
29
   * !IMPORTANT: This value must match the value in mobkoiAnalyticsAdapter.js
30
   * The name of the parameter that the publisher can use to specify the integration endpoint.
31
   */
32
  PARAM_NAME_PREBID_JS_INTEGRATION_ENDPOINT: 'integrationEndpoint',
33
}
34

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

37
export const mobkoiIdSubmodule = {
1✔
38
  name: MODULE_NAME,
39
  gvlid: GVL_ID,
40

41
  decode(value) {
42
    return value ? { [MODULE_NAME]: value } : undefined;
2✔
43
  },
44

45
  getId(userSyncOptions, consentObject) {
46
    logInfo('Getting Equativ SAS ID.');
4✔
47

48
    if (!storage.cookiesAreEnabled()) {
4✔
49
      logError('Cookies are not enabled. Module will not work.');
1✔
50
      return {
1✔
51
        id: null
52
      };
53
    }
54

55
    const storageName = userSyncOptions && userSyncOptions.storage && userSyncOptions.storage.name;
3✔
56
    if (!storageName) {
3!
57
      logError('Storage name is not defined. Module will not work.');
×
58
      return {
×
59
        id: null
60
      };
61
    }
62

63
    const existingId = storage.getCookie(storageName);
3✔
64

65
    if (existingId) {
3✔
66
      logInfo(`Found "${storageName}" from local cookie: "${existingId}"`);
1✔
67
      return { id: existingId };
1✔
68
    }
69

70
    logInfo(`Cannot found "${storageName}" in local cookie with name.`);
2✔
71
    return {
2✔
72
      callback: () => {
73
        return new Promise((resolve, _reject) => {
1✔
74
          utils.requestEquativSasId(
1✔
75
            userSyncOptions,
76
            consentObject,
77
            (sasId) => {
78
              if (!sasId) {
1!
79
                logError('Equativ SAS ID is empty');
×
80
                resolve({ id: null });
×
81
                return;
×
82
              }
83

84
              logInfo(`Fetched Equativ SAS ID: "${sasId}"`);
1✔
85
              storage.setCookie(storageName, sasId, userSyncOptions.storage.expires);
1✔
86
              logInfo(`Stored Equativ SAS ID in local cookie with name: "${storageName}"`);
1✔
87
              resolve({ id: sasId });
1✔
88
            }
89
          );
90
        });
91
      }
92
    };
93
  },
94
  eids: {
95
    'mobkoiId': {
96
      source: 'mobkoi.com',
97
      atype: 1
98
    },
99
  }
100
};
101

102
submodule('userId', mobkoiIdSubmodule);
1✔
103

104
export const utils = {
1✔
105
  requestEquativSasId(syncUserOptions, consentObject, onCompleteCallback) {
106
    logInfo('Start requesting Equativ SAS ID');
1✔
107
    const integrationBaseUrl = deepAccess(
1✔
108
      syncUserOptions,
109
      `params.${USER_SYNC_PARAMS.PARAM_NAME_PREBID_JS_INTEGRATION_ENDPOINT}`) || PROD_PREBID_JS_INTEGRATION_BASE_URL;
110

111
    const equativPixelUrl = utils.buildEquativPixelUrl(syncUserOptions, consentObject);
1✔
112
    logInfo('Equativ SAS ID request URL:', equativPixelUrl);
1✔
113

114
    const url = integrationBaseUrl + '/pixeliframe?' +
1✔
115
      'pixelUrl=' + encodeURIComponent(equativPixelUrl) +
116
      '&cookieName=sas_uid';
117

118
    /**
119
     * Listen for messages from the iframe with automatic cleanup
120
     */
121
    const messageHandler = function(event) {
1✔
122
      switch (event.data.type) {
8!
123
        case 'MOBKOI_PIXEL_SYNC_COMPLETE':
124
          const sasUid = event.data.syncData;
×
125
          logInfo('Parent window Sync completed. SAS ID:', sasUid);
×
126
          window.removeEventListener('message', messageHandler);
×
127
          onCompleteCallback(sasUid);
×
128
          break;
×
129
        case 'MOBKOI_PIXEL_SYNC_ERROR':
130
          logError('Parent window Sync failed:', event.data.error);
×
131
          window.removeEventListener('message', messageHandler);
×
132
          onCompleteCallback(null);
×
133
          break;
×
134
      }
135
    };
136

137
    window.addEventListener('message', messageHandler);
1✔
138

139
    insertUserSyncIframe(url, () => {
1✔
140
      logInfo('insertUserSyncIframe loaded');
×
141
    });
142

143
    // Return the URL for testing purposes
144
    return url;
1✔
145
  },
146

147
  /**
148
   * Build a pixel URL that will be placed in an iframe to fetch the Equativ SAS ID
149
   */
150
  buildEquativPixelUrl(syncUserOptions, consentObject) {
151
    logInfo('Generating Equativ SAS ID request URL');
6✔
152
    const integrationBaseUrl =
153
      deepAccess(
6✔
154
        syncUserOptions,
155
        `params.${USER_SYNC_PARAMS.PARAM_NAME_PREBID_JS_INTEGRATION_ENDPOINT}`) || PROD_PREBID_JS_INTEGRATION_BASE_URL;
156

157
    const gdprConsentString = consentObject && consentObject.gdpr && consentObject.gdpr.consentString ? consentObject.gdpr.consentString : '';
6✔
158
    const smartServerUrl = EQUATIV_BASE_URL + '/getuid?' +
6✔
159
      `url=` + encodeURIComponent(`${integrationBaseUrl}/getPixel?value=`) + '[sas_uid]' +
160
      `&gdpr_consent=${gdprConsentString}` +
161
      `&nwid=${EQUATIV_NETWORK_ID}`;
162

163
    return smartServerUrl;
6✔
164
  }
165
};
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