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

Symitri Analytics Adapter: initial release #12132

Merged
merged 1 commit into from
Aug 16, 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
61 changes: 61 additions & 0 deletions modules/symitriAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import adapterManager from '../src/adapterManager.js';
import { EVENTS } from '../src/constants.js';
import { logMessage } from '../src/utils.js';
import {ajax} from '../src/ajax.js';

const analyticsType = 'endpoint';
const url = 'https://ProdSymPrebidEventhub1.servicebus.windows.net/prebid-said-1/messages';

const { BID_WON } = EVENTS;

let initOptions;

let symitriAnalytics = Object.assign(adapter({url, analyticsType}), {
track({ eventType, args }) {
switch (eventType) {
case BID_WON:
logMessage('##### symitriAnalytics :: Event Triggered : ' + eventType);
sendEvent(args);
break;
default:
logMessage('##### symitriAnalytics :: Event Triggered : ' + eventType);
break;
}
}
});

function sendEvent(payload) {
try {
if (initOptions.apiAuthToken) {
const body = JSON.stringify(payload);
logMessage('##### symitriAnalytics :: sendEvent ', payload);
let cb = {
success: () => {
logMessage('##### symitriAnalytics :: Bid Reported Successfully');
},
error: (request, error) => {
logMessage('##### symitriAnalytics :: Bid Report Failed' + error);
}
};

ajax(url, cb, body, {
method: 'POST',
customHeaders: {'Content-Type': 'application/atom+xml;type=entry;charset=utf-8', 'Authorization': initOptions.apiAuthToken}
});
}
} catch (err) { logMessage('##### symitriAnalytics :: error' + err) }
}

symitriAnalytics.originEnableAnalytics = symitriAnalytics.enableAnalytics;
symitriAnalytics.enableAnalytics = function (config) {
initOptions = config.options;
symitriAnalytics.originEnableAnalytics(config);
};

adapterManager.registerAnalyticsAdapter({
adapter: symitriAnalytics,
code: 'symitri'
});

export default symitriAnalytics;
35 changes: 35 additions & 0 deletions modules/symitriAnalyticsAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
### Overview

Symitri Analytics Adapter.

### Integration

1) Build the symitriAnalyticsAdapter module into the Prebid.js package with:

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

2) Use `enableAnalytics` to instruct Prebid.js to initilaize the symitriAnalyticsAdapter module, as specified below.

### Configuration

```
pbjs.enableAnalytics({
provider: 'symitri',
options: {
'apiAuthToken': '<see your Symitri account rep>'
}
});
```

Please reach out to your Symitri account representative([email protected]) to get provisioned on the DAP platform.


### Testing
To view an example of available segments returned by dap:
```
‘gulp serve --modules=rtdModule,symitriDapRtdProvider,symitriAnalyticsAdapter,appnexusBidAdapter,sovrnBidAdapter’
```
and then point your browser at:
"http://localhost:9999/integrationExamples/gpt/symitridap_segments_example.html"
90 changes: 90 additions & 0 deletions test/spec/modules/symitriAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import symitriAnalyticsAdapter from 'modules/symitriAnalyticsAdapter.js';
import { expect } from 'chai';
import adapterManager from 'src/adapterManager.js';
import { server } from 'test/mocks/xhr.js';
import { EVENTS } from 'src/constants.js';

let events = require('src/events');

describe('symitri analytics adapter', function () {
beforeEach(function () {
sinon.stub(events, 'getEvents').returns([]);
});

afterEach(function () {
events.getEvents.restore();
});

describe('track', function () {
let initOptionsValid = {
apiAuthToken: 'TOKEN1234'
};
let initOptionsInValid = {
};

let bidWon = {
'bidderCode': 'appnexus',
'width': 300,
'height': 250,
'statusMessage': 'Bid available',
'adId': '393976d8770041',
'requestId': '263efc09896d0c',
'mediaType': 'banner',
'source': 'client',
'cpm': 0.5,
'creativeId': 96846035,
'currency': 'USD',
'netRevenue': true,
'ttl': 300,
'adUnitCode': 'div-gpt-ad-1460505748561-0',
'originalCpm': 0.5,
'originalCurrency': 'USD',
'auctionId': 'db377024-d866-4a24-98ac-5e430f881313',
'responseTimestamp': 1576823894050,
'requestTimestamp': 1576823893838,
'bidder': 'appnexus',
'timeToRespond': 212,
'status': 'rendered'
};

adapterManager.registerAnalyticsAdapter({
code: 'symitri',
adapter: symitriAnalyticsAdapter
});

afterEach(function () {
symitriAnalyticsAdapter.disableAnalytics();
});

it('Test with valid apiAuthToken', function () {
adapterManager.enableAnalytics({
provider: 'symitri',
options: initOptionsValid
});
events.emit(EVENTS.BID_WON, bidWon);
expect(server.requests.length).to.equal(1);
});

it('Test with missing apiAuthToken', function () {
adapterManager.enableAnalytics({
provider: 'symitri',
options: initOptionsInValid
});
events.emit(EVENTS.BID_WON, bidWon);
expect(server.requests.length).to.equal(0);
});

it('Test correct winning bid is sent to server', function () {
adapterManager.enableAnalytics({
provider: 'symitri',
options: initOptionsValid
});
events.emit(EVENTS.BID_WON, bidWon);
expect(server.requests.length).to.equal(1);
let winEventData = JSON.parse(server.requests[0].requestBody);
expect(winEventData).to.deep.equal(bidWon);
let authToken = server.requests[0].requestHeaders['Authorization'];
expect(authToken).to.equal(initOptionsValid.apiAuthToken);
});
});
});