Skip to content

Commit

Permalink
Liveintent id module doesn't fall back to the default implementations…
Browse files Browse the repository at this point in the history
… of ajax, pixel and storage. (prebid#5859)

Liveintent id module reads an email hash that is provided in the configuration.
  • Loading branch information
Yevhenii Melnyk authored and stsepelin committed May 28, 2021
1 parent 52af4b8 commit 9469d14
Show file tree
Hide file tree
Showing 5 changed files with 276 additions and 65 deletions.
56 changes: 42 additions & 14 deletions modules/liveIntentIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,32 @@
* @requires module:modules/userId
*/
import * as utils from '../src/utils.js';
import { ajax } from '../src/ajax.js';
import { triggerPixel } from '../src/utils.js';
import { ajaxBuilder } from '../src/ajax.js';
import { submodule } from '../src/hook.js';
import { LiveConnect } from 'live-connect-js/cjs/live-connect.js';
import { uspDataHandler } from '../src/adapterManager.js';
import { gdprDataHandler, uspDataHandler } from '../src/adapterManager.js';
import { getStorageManager } from '../src/storageManager.js';

const MODULE_NAME = 'liveIntentId';
export const storage = getStorageManager(null, MODULE_NAME);
const calls = {
ajaxGet: (url, onSuccess, onError, timeout) => {
ajaxBuilder(timeout)(
url,
{
success: onSuccess,
error: onError
},
undefined,
{
method: 'GET',
withCredentials: true
}
)
},
pixelGet: (url, onload) => triggerPixel(url, onload)
}

let eventFired = false;
let liveConnect = null;
Expand Down Expand Up @@ -64,18 +82,30 @@ function initializeLiveConnect(configParams) {
if (configParams.partner) {
identityResolutionConfig.source = configParams.partner
}
if (configParams.ajaxTimeout) {
identityResolutionConfig.ajaxTimeout = configParams.ajaxTimeout;
}

const liveConnectConfig = parseLiveIntentCollectorConfig(configParams.liCollectConfig);
liveConnectConfig.wrapperName = 'prebid';
liveConnectConfig.identityResolutionConfig = identityResolutionConfig;
liveConnectConfig.identifiersToResolve = configParams.identifiersToResolve || [];
if (configParams.emailHash) {
liveConnectConfig.eventSource = { hash: configParams.emailHash }
}
const usPrivacyString = uspDataHandler.getConsentData();
if (usPrivacyString) {
liveConnectConfig.usPrivacyString = usPrivacyString;
}
const gdprConsent = gdprDataHandler.getConsentData()
if (gdprConsent) {
liveConnectConfig.gdprApplies = gdprConsent.gdprApplies;
liveConnectConfig.gdprConsent = gdprConsent.consentString;
}

// The second param is the storage object, which means that all LS & Cookie manipulation will go through PBJS utils.
liveConnect = LiveConnect(liveConnectConfig, storage);
// The second param is the storage object, LS & Cookie manipulation uses PBJS utils.
// The third param is the ajax and pixel object, the ajax and pixel use PBJS utils.
liveConnect = LiveConnect(liveConnectConfig, storage, calls);
return liveConnect;
}

Expand Down Expand Up @@ -132,11 +162,9 @@ export const liveIntentIdSubmodule = {
return;
}
tryFireEvent();
// Don't do the internal ajax call, but use the composed url and fire it via PBJS ajax module
const url = liveConnect.resolutionCallUrl();
const result = function (callback) {
const callbacks = {
success: response => {
const result = function(callback) {
liveConnect.resolve(
response => {
let responseObj = {};
if (response) {
try {
Expand All @@ -147,14 +175,14 @@ export const liveIntentIdSubmodule = {
}
callback(responseObj);
},
error: error => {
error => {
utils.logError(`${MODULE_NAME}: ID fetch encountered an error: `, error);
callback();
}
};
ajax(url, callbacks, undefined, { method: 'GET', withCredentials: true });
};
return {callback: result};
)
}

return { callback: result };
}
};

Expand Down
2 changes: 1 addition & 1 deletion modules/userId/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@
* @property {(string|undefined)} publisherId - the unique identifier of the publisher in question
* @property {(string|undefined)} ajaxTimeout - the number of milliseconds a resolution request can take before automatically being terminated
* @property {(array|undefined)} identifiersToResolve - the identifiers from either ls|cookie to be attached to the getId query
* @property {(string|undefined)} providedIdentifierName - defines the name of an identifier that can be found in local storage or in the cookie jar that can be sent along with the getId request. This parameter should be used whenever a customer is able to provide the most stable identifier possible
* @property {(LiveIntentCollectConfig|undefined)} liCollectConfig - the config for LiveIntent's collect requests
* @property {(string|undefined)} pd - publisher provided data for reconciling ID5 IDs
* @property {(string|undefined)} emailHash - if provided, the hashed email address of a user
*/

/**
Expand Down
158 changes: 153 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@
"fun-hooks": "^0.9.9",
"jsencrypt": "^3.0.0-rc.1",
"just-clone": "^1.0.2",
"live-connect-js": "1.1.10"
"live-connect-js": "^1.1.23"
}
}
Loading

0 comments on commit 9469d14

Please sign in to comment.