Skip to content

Commit

Permalink
prebid#24 Code review improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
cosenmarco committed May 27, 2021
1 parent 5dc03f8 commit 99a2f5b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 16 deletions.
26 changes: 15 additions & 11 deletions modules/id5AnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import buildAdapter from '../src/AnalyticsAdapter.js';
import CONSTANTS from '../src/constants.json';
import adapterManager from '../src/adapterManager.js';
import { ajax } from '../src/ajax.js';
import { logWarn, logInfo, logError } from '../src/utils.js';
import { logInfo, logError } from '../src/utils.js';
import events from '../src/events.js';

const {
Expand All @@ -23,7 +23,7 @@ const STANDARD_EVENTS_TO_TRACK = [
BID_WON,
];

// These events cause the buffer ed events to be sent over
// These events cause the buffered events to be sent over
const FLUSH_EVENTS = [
TCF2_ENFORCEMENT,
AUCTION_END,
Expand Down Expand Up @@ -67,7 +67,7 @@ let id5Analytics = Object.assign(buildAdapter({analyticsType: 'endpoint'}), {
que.push = (pushedEvent) => _this.sendEvents([pushedEvent]);
}
} catch (error) {
logError('id5Analytics', error);
logError('id5Analytics: ERROR', error);
_this.sendErrorEvent(error);
}
},
Expand Down Expand Up @@ -115,26 +115,30 @@ const ENABLE_FUNCTION = (config) => {

const partnerId = _this.options.partnerId;
if (typeof partnerId !== 'number') {
logWarn('id5Analytics: cannot find partnerId in config.options');
logError('id5Analytics: partnerId in config.options must be a number representing the id5 partner ID');
return;
}

ajax(`${CONFIG_URL_PREFIX}/${partnerId}/pbjs`, (result) => {
logInfo('id5Analytics: Received from configuration endpoint', result);

const configFromServer = JSON.parse(result);

const sampling = _this.options.id5Sampling =
typeof configFromServer.sampling === 'number' ? configFromServer.sampling : 0;

if (typeof configFromServer.ingestUrl !== 'string') {
logWarn('id5Analytics: cannot find ingestUrl in config endpoint response');
logError('id5Analytics: cannot find ingestUrl in config endpoint response; no analytics will be available');
return;
}
_this.options.ingestUrl = configFromServer.ingestUrl;

// 3-way fallback for which events to track: server >= config >= standard
// 3-way fallback for which events to track: server > config > standard
_this.eventsToTrack = configFromServer.eventsToTrack || _this.options.eventsToTrack || STANDARD_EVENTS_TO_TRACK;
_this.eventsToTrack = isArray(_this.eventsToTrack) ? _this.eventsToTrack : STANDARD_EVENTS_TO_TRACK;

logInfo('id5Analytics: Configuration is ' + JSON.stringify(_this.options));
logInfo('id5Analytics: Configuration is', _this.options);
logInfo('id5Analytics: Tracking events', _this.eventsToTrack);
if (sampling > 0 && _this.random() < (1 / sampling)) {
// Init the module only if we got lucky
logInfo('id5Analytics: Selected by sampling. Starting up!')
Expand All @@ -144,8 +148,8 @@ const ENABLE_FUNCTION = (config) => {

// Replay all events until now
if (!config.disablePastEventsProcessing) {
events.getEvents().forEach(event => {
if (!!event && _this.eventsToTrack.indexOf(event.eventType) >= 0) {
events.getEvents().forEach((event) => {
if (event && _this.eventsToTrack.indexOf(event.eventType) >= 0) {
_this.track(event);
}
});
Expand All @@ -162,7 +166,7 @@ const ENABLE_FUNCTION = (config) => {
isArray(eventRules.match) &&
(eventRules.apply in TRANSFORM_FUNCTIONS))
) {
logInfo('id5Analytics: merging additional cleanup rules for event' + key);
logInfo('id5Analytics: merging additional cleanup rules for event ' + key);
CLEANUP_RULES[key].push(...newRules[key]);
}
});
Expand Down Expand Up @@ -284,7 +288,7 @@ function transformFnFromCleanupRules(eventType) {
}
for (let fragment = 0; fragment < ruleMatcher.length && match; fragment++) {
const choices = makeSureArray(ruleMatcher[fragment]);
match = !choices.every(choice => choice !== '*' && path[fragment] !== choice);
match = !choices.every((choice) => choice !== '*' && path[fragment] !== choice);
}
if (match) {
const transformfn = TRANSFORM_FUNCTIONS[transformation];
Expand Down
34 changes: 30 additions & 4 deletions modules/id5AnalyticsAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,36 @@ Maintainer: [id5.io](https://id5.io)

# ID5 Universal ID

The ID5 Universal ID is a shared, neutral identifier that publishers and ad tech platforms can use to recognise users even in environments where 3rd party cookies are not available. The ID5 Universal ID is designed to respect users' privacy choices and publishers’ preferences throughout the advertising value chain. For more information about the ID5 Universal ID and detailed integration docs, please visit [our documentation](https://wiki.id5.io/x/BIAZ). We also recommend that you sign up for our [release notes](https://id5.io/universal-id/release-notes) to stay up-to-date with any changes to the implementation of the ID5 Universal ID in Prebid.
The ID5 Universal ID is a shared, neutral identifier that publishers and ad tech platforms can use to recognise users even in environments where 3rd party cookies are not available. The ID5 Universal ID is designed to respect users' privacy choices and publishers’ preferences throughout the advertising value chain. For more information about the ID5 Universal ID and detailed integration docs, please visit [our documentation](https://support.id5.io/portal/en/kb/articles/prebid-js-user-id-module).

## ID5 Universal ID Registration
# ID5 Analytics Registration

The ID5 Universal ID is free to use, but requires a simple registration with ID5. Please visit [id5.io/universal-id](https://id5.io/universal-id) to sign up and request your ID5 Partner Number to get started.
The ID5 Analytics Adapter is free to use during our Beta period, but requires a simple registration with ID5. Please visit [id5.io/universal-id](https://id5.io/universal-id) to sign up and request your ID5 Partner Number to get started. If you're already using the ID5 Universal ID, you may use your existing Partner Number with the analytics adapter.

The ID5 privacy policy is at [https://www.id5.io/platform-privacy-policy](https://www.id5.io/platform-privacy-policy).
The ID5 privacy policy is at [https://www.id5.io/platform-privacy-policy](https://www.id5.io/platform-privacy-policy).

## ID5 Analytics Configuration

First, make sure to add the ID5 Analytics submodule to your Prebid.js package with:

```
gulp build --modules=...,id5AnalyticsAdapter
```

The following configuration parameters are available:

```javascript
pbjs.enableAnalytics({
provider: 'id5Analytics',
options: {
partnerId: 1234, // change to the Partner Number you received from ID5
eventsToTrack: ['auctionEnd','bidWon']
}
});
```

| Parameter | Scope | Type | Description | Example |
| --- | --- | --- | --- | --- |
| provider | Required | String | The name of this module: `id5Analytics` | `id5Analytics` |
| options.partnerId | Required | Number | This is the ID5 Partner Number obtained from registering with ID5. | `1234` |
| options.eventsToTrack | Optional | Array of strings | Overrides the set of tracked events | `['auctionEnd','bidWon']` |
2 changes: 1 addition & 1 deletion test/spec/modules/id5AnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import events from '../../../src/events.js';
import constants from '../../../src/constants.json';
import { generateUUID } from '../../../src/utils.js';

const CONFIG_URL = 'https://127.0.0.1:8443/analytics/12349/pbjs';
const CONFIG_URL = 'https://api.id5-sync.com/analytics/12349/pbjs';
const INGEST_URL = 'https://test.me/ingest';

describe('ID5 analytics adapter', () => {
Expand Down

0 comments on commit 99a2f5b

Please sign in to comment.