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

LiveIntent UserId Module: add IP and User Agent Configuration Parameters #12402

Merged
merged 5 commits into from
Nov 8, 2024
Merged
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
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Prebid.js is open source software that is offered for free as a convenience. Whi

*Note:* Requires Prebid.js v1.38.0+

Prebid.js depends on Babel and some Babel Plugins in order to run correctly in the browser. Here are some examples for
Prebid.js depends on Babel and some Babel Plugins in order to run correctly in the browser. Here are some examples for
configuring webpack to work with Prebid.js.

With Babel 7:
Expand All @@ -37,7 +37,7 @@ module.exports = {
mode: 'production',
module: {
rules: [

// this rule can be excluded if you don't require babel-loader for your other application files
{
test: /\.m?js$/,
Expand All @@ -46,7 +46,7 @@ module.exports = {
loader: 'babel-loader',
}
},

// this separate rule is required to make sure that the Prebid.js files are babel-ified. this rule will
// override the regular exclusion from above (for being inside node_modules).
{
Expand All @@ -71,15 +71,15 @@ Or for Babel 6:
// you must manually install and specify the presets and plugins yourself
options: {
plugins: [
"transform-object-assign", // required (for IE support) and "babel-plugin-transform-object-assign"
"transform-object-assign", // required (for IE support) and "babel-plugin-transform-object-assign"
// must be installed as part of your package.
require('prebid.js/plugins/pbjsGlobals.js') // required!
],
presets: [
["env", { // you can use other presets if you wish.
"targets": { // this example is using "babel-presets-env", which must be installed if you
"browsers": [ // follow this example.
... // your browser targets. they should probably match the targets you're using for the rest
... // your browser targets. they should probably match the targets you're using for the rest
// of your application
]
}
Expand Down Expand Up @@ -143,7 +143,7 @@ This will run testing but not linting. A web server will start at `http://localh

Development may be a bit slower but if you prefer linting and additional watch files you can also still run just:

$ gulp serve
$ gulp serve


### Build Optimization
Expand All @@ -162,11 +162,11 @@ Building with just these adapters will result in a smaller bundle which should a
- Then run the build:

$ gulp build --modules=openxBidAdapter,rubiconBidAdapter,sovrnBidAdapter

Alternatively, a `.json` file can be specified that contains a list of modules you would like to include.

$ gulp build --modules=modules.json

With `modules.json` containing the following
```json modules.json
[
Expand Down Expand Up @@ -202,7 +202,7 @@ gulp bundle --tag one --modules=one.json
gulp bundle --tag two --modules=two.json
```

This generates slightly larger files, but has the advantage of being much faster to run (after the initial `gulp build`). It's also the method used by [the Prebid.org download page](https://docs.prebid.org/download.html).
This generates slightly larger files, but has the advantage of being much faster to run (after the initial `gulp build`). It's also the method used by [the Prebid.org download page](https://docs.prebid.org/download.html).

<a name="Run"></a>

Expand Down Expand Up @@ -378,7 +378,7 @@ For instructions on writing tests for Prebid.js, see [Testing Prebid.js](https:/

### Supported Browsers

Prebid.js is supported on IE11 and modern browsers until 5.x. 6.x+ transpiles to target >0.25%; not Opera Mini; not IE11.
Prebid.js is supported on IE11 and modern browsers until 5.x. 6.x+ transpiles to target >0.25%; not Opera Mini; not IE11.

### Governance
Review our governance model [here](https://github.com/prebid/Prebid.js/tree/master/governance.md).
Expand Down
7 changes: 4 additions & 3 deletions libraries/liveIntentId/externalIdSystem.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { logError } from '../../src/utils.js';
import { gdprDataHandler, uspDataHandler, gppDataHandler } from '../../src/adapterManager.js';
import { submodule } from '../../src/hook.js';
import { DEFAULT_AJAX_TIMEOUT, MODULE_NAME, parseRequestedAttributes, composeIdObject, eids, GVLID, PRIMARY_IDS } from './shared.js'
import { DEFAULT_AJAX_TIMEOUT, MODULE_NAME, parseRequestedAttributes, composeIdObject, eids, GVLID, PRIMARY_IDS, makeSourceEventToSend } from './shared.js'

// Reference to the client for the liQHub.
let cachedClientRef
Expand Down Expand Up @@ -97,8 +97,9 @@ function initializeClient(configParams) {
resolveSettings
})

if (configParams.emailHash != null) {
window.liQHub.push({ type: 'collect', clientRef, sourceEvent: { hash: configParams.emailHash } })
let sourceEvent = makeSourceEventToSend(configParams)
if (sourceEvent != null) {
window.liQHub.push({ type: 'collect', clientRef, sourceEvent })
}

cachedClientRef = clientRef
Expand Down
19 changes: 13 additions & 6 deletions libraries/liveIntentId/idSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { submodule } from '../../src/hook.js';
import { LiveConnect } from 'live-connect-js'; // eslint-disable-line prebid/validate-imports
import { getStorageManager } from '../../src/storageManager.js';
import { MODULE_TYPE_UID } from '../../src/activities/modules.js';
import { DEFAULT_AJAX_TIMEOUT, MODULE_NAME, composeIdObject, eids, GVLID, DEFAULT_DELAY, PRIMARY_IDS, parseRequestedAttributes } from './shared.js'
import { DEFAULT_AJAX_TIMEOUT, MODULE_NAME, composeIdObject, eids, GVLID, DEFAULT_DELAY, PRIMARY_IDS, parseRequestedAttributes, makeSourceEventToSend } from './shared.js'

/**
* @typedef {import('../modules/userId/index.js').Submodule} Submodule
Expand All @@ -23,7 +23,7 @@ const EVENTS_TOPIC = 'pre_lips';

export const storage = getStorageManager({moduleType: MODULE_TYPE_UID, moduleName: MODULE_NAME});
const calls = {
ajaxGet: (url, onSuccess, onError, timeout) => {
ajaxGet: (url, onSuccess, onError, timeout, headers) => {
ajaxBuilder(timeout)(
url,
{
Expand All @@ -33,7 +33,8 @@ const calls = {
undefined,
{
method: 'GET',
withCredentials: true
withCredentials: true,
customHeaders: headers
}
)
},
Expand Down Expand Up @@ -92,7 +93,11 @@ function initializeLiveConnect(configParams) {
const publisherId = configParams.publisherId || 'any';
const identityResolutionConfig = {
publisherId: publisherId,
requestedAttributes: parseRequestedAttributes(configParams.requestedAttributesOverrides)
requestedAttributes: parseRequestedAttributes(configParams.requestedAttributesOverrides),
extraAttributes: {
ipv4: configParams.ipv4,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why make these config params instead of just gathering from where the publisher already set them? in ortb2.device.ip and ipv6?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will get back to you

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @patmmccann, ortb2 seems currently not to be accessible for the user ID submodules. That was the reason for implementing it that way. If you are fine with it, we can change that and pass ortb2 to every user ID submodule during initialization.

ipv6: configParams.ipv6
}
};
if (configParams.url) {
identityResolutionConfig.url = configParams.url;
Expand Down Expand Up @@ -136,8 +141,10 @@ function initializeLiveConnect(configParams) {
// The second param is the storage object, LS & Cookie manipulation uses PBJS.
// The third param is the ajax and pixel object, the AJAX and pixel use PBJS.
liveConnect = liveIntentIdSubmodule.getInitializer()(liveConnectConfig, storage, calls);
if (configParams.emailHash) {
liveConnect.push({ hash: configParams.emailHash });

const sourceEvent = makeSourceEventToSend(configParams)
if (sourceEvent != null) {
liveConnect.push(sourceEvent);
}
return liveConnect;
}
Expand Down
25 changes: 25 additions & 0 deletions libraries/liveIntentId/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,31 @@ export function parseRequestedAttributes(overrides) {
}
}

export function makeSourceEventToSend(configParams) {
const sourceEvent = {}
let nonEmpty = false
if (typeof configParams.emailHash === 'string') {
nonEmpty = true
sourceEvent.emailHash = configParams.emailHash
}
if (typeof configParams.ipv4 === 'string') {
nonEmpty = true
sourceEvent.ipv4 = configParams.ipv4
}
if (typeof configParams.ipv6 === 'string') {
nonEmpty = true
sourceEvent.ipv6 = configParams.ipv6
}
if (typeof configParams.userAgent === 'string') {
nonEmpty = true
sourceEvent.userAgent = configParams.userAgent
}

if (nonEmpty) {
return sourceEvent
}
}

export function composeIdObject(value) {
const result = {};

Expand Down
34 changes: 17 additions & 17 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 @@ -143,7 +143,7 @@
"fun-hooks": "^0.9.9",
"gulp-wrap": "^0.15.0",
"klona": "^2.0.6",
"live-connect-js": "^6.7.3"
"live-connect-js": "^7.1.0"
},
"optionalDependencies": {
"fsevents": "^2.3.2"
Expand Down
37 changes: 33 additions & 4 deletions test/spec/modules/liveIntentExternalIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('LiveIntentExternalId', function() {
},
{
clientRef: {},
sourceEvent: { hash: '123' },
sourceEvent: { emailHash: '123' },
type: 'collect'
}])
});
Expand Down Expand Up @@ -120,7 +120,7 @@ describe('LiveIntentExternalId', function() {

expect(window.liQHub[1]).to.eql({
clientRef: {},
sourceEvent: { hash: '58131bc547fb87af94cebdaf3102321f' },
sourceEvent: { emailHash: '58131bc547fb87af94cebdaf3102321f' },
type: 'collect'
})

Expand Down Expand Up @@ -179,7 +179,7 @@ describe('LiveIntentExternalId', function() {
},
{
clientRef: {},
sourceEvent: { hash: '123' },
sourceEvent: { emailHash: '123' },
type: 'collect'
}])
});
Expand All @@ -205,7 +205,36 @@ describe('LiveIntentExternalId', function() {
},
{
clientRef: {},
sourceEvent: { hash: '123' },
sourceEvent: { emailHash: '123' },
type: 'collect'
}])
});

it('should include the identifier data if it is present in config', function() {
const configParams = {
params: {
...defaultConfigParams.params,
distributorId: 'did-1111',
emailHash: '123',
ipv4: 'foov4',
ipv6: 'foov6',
userAgent: 'bar'
}
}
liveIntentExternalIdSubmodule.decode({}, configParams);
expect(window.liQHub).to.eql([{
clientDetails: { name: 'prebid', version: '$prebid.version$' },
clientRef: {},
collectSettings: { timeout: DEFAULT_AJAX_TIMEOUT },
consent: {},
integration: { distributorId: 'did-1111', publisherId: defaultConfigParams.params.publisherId, type: 'custom' },
partnerCookies: new Set(),
resolveSettings: { identityPartner: 'did-1111', timeout: DEFAULT_AJAX_TIMEOUT },
type: 'register_client'
},
{
clientRef: {},
sourceEvent: { emailHash: '123', ipv4: 'foov4', ipv6: 'foov6', userAgent: 'bar' },
type: 'collect'
}])
});
Expand Down
15 changes: 15 additions & 0 deletions test/spec/modules/liveIntentIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,21 @@ describe('LiveIntentId', function() {
expect(callBackSpy.calledOnce).to.be.true;
});

it('should include ip4,ip6,userAgent if it\'s present', function(done) {
liveIntentIdSubmodule.getId({ params: {
...defaultConfigParams,
ipv4: 'foov4',
ipv6: 'foov6',
userAgent: 'boo'
}});
setTimeout(() => {
let request = rpRequests()[0];
expect(request.url).to.match(/^https:\/\/rp\.liadm\.com\/j?.*pip=.*&pip6=.*$/)
expect(request.requestHeaders['X-LI-Provided-User-Agent']).to.be.eq('boo')
done();
}, 300);
});

it('should send an error when the cookie jar throws an unexpected error', function() {
getCookieStub.throws('CookieError', 'A message');
liveIntentIdSubmodule.getId({ params: defaultConfigParams });
Expand Down