Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTA-386 Use pbjs implementation of the cookies, localstorage, ajax and pixel … #3

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
melgenek marked this conversation as resolved.
Show resolved Hide resolved
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) {
melgenek marked this conversation as resolved.
Show resolved Hide resolved
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
44 changes: 34 additions & 10 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