Skip to content

Commit

Permalink
send pubx_id as query param
Browse files Browse the repository at this point in the history
  • Loading branch information
tej656 committed Jul 31, 2024
1 parent 4c0b581 commit 5bfc260
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
8 changes: 5 additions & 3 deletions modules/pubxaiAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const analyticsType = 'endpoint';
const adapterCode = 'pubxai';
const pubxaiAnalyticsVersion = 'v2.0.0';
const defaultHost = 'api.pbxai.com';
const auctionPath = '/analytics/auction';
const winningBidPath = '/analytics/bidwon';
const storage = getStorageManager({ moduleType: MODULE_TYPE_ANALYTICS, moduleName: adapterCode })

/**
Expand Down Expand Up @@ -234,10 +236,9 @@ const prepareSend = (auctionId) => {
if (!shouldFireEventRequest(auctionId, initOptions.samplingRate)) {
return;
}
const pubxID = initOptions.pubxId;
[
{
path: `/analytics/${pubxID}/bidwon`,
path: winningBidPath,
requiredKeys: [
'winningBid',
'pageDetail',
Expand All @@ -252,7 +253,7 @@ const prepareSend = (auctionId) => {
eventType: 'win',
},
{
path: `/analytics/${pubxID}/auction`,
path: auctionPath,
requiredKeys: [
'bids',
'pageDetail',
Expand Down Expand Up @@ -286,6 +287,7 @@ const prepareSend = (auctionId) => {
auctionTimestamp: auctionData.auctionDetail.timestamp,
pubxaiAnalyticsVersion: pubxaiAnalyticsVersion,
prebidVersion: '$prebid.version$',
pubxId: initOptions.pubxId,
},
});
sendCache[pubxaiAnalyticsRequestUrl].push(data);
Expand Down
14 changes: 9 additions & 5 deletions test/spec/modules/pubxaiAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('pubxai analytics adapter', () => {
});

describe('track', () => {
const pubxId = '6c415fc0-8b0e-4cf5-be73-01526a4db625'
const pubxId = '6c415fc0-8b0e-4cf5-be73-01526a4db625';
let initOptions = {
samplingRate: '1',
pubxId: pubxId,
Expand Down Expand Up @@ -759,12 +759,13 @@ describe('pubxai analytics adapter', () => {
const [expectedUrl, expectedData] = arg;
const parsedUrl = new URL(expectedUrl);
expect(parsedUrl.pathname).to.equal(
[`/analytics/${pubxId}/bidwon`, `/analytics/${pubxId}/auction`][index]
['/analytics/bidwon', '/analytics/auction'][index]
);
expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({
auctionTimestamp: '1616654312804',
pubxaiAnalyticsVersion: 'v2.0.0',
prebidVersion: '$prebid.version$',
pubxId: pubxId,
});
expect(expectedData.type).to.equal('text/json');
expect(JSON.parse(await readBlobSafariCompat(expectedData))).to.deep.equal([
Expand Down Expand Up @@ -801,13 +802,14 @@ describe('pubxai analytics adapter', () => {
// Step 7: check the pathname of the calls is correct (sent only to the auction endpoint)
const [expectedUrl, expectedData] = navigator.sendBeacon.args[0];
const parsedUrl = new URL(expectedUrl);
expect(parsedUrl.pathname).to.equal(`/analytics/${pubxId}/auction`);
expect(parsedUrl.pathname).to.equal('/analytics/auction');

// Step 8: check that the meta information in the call is correct
expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({
auctionTimestamp: '1616654312804',
pubxaiAnalyticsVersion: 'v2.0.0',
prebidVersion: '$prebid.version$',
pubxId: pubxId,
});

// Step 9: check that the data sent in the request is correct
Expand Down Expand Up @@ -927,12 +929,13 @@ describe('pubxai analytics adapter', () => {
const parsedUrl = new URL(expectedUrl);
const auctionIdMapFn = index < 2 ? (i, _) => i : replaceProperty;
expect(parsedUrl.pathname).to.equal(
[`/analytics/${pubxId}/bidwon`, `/analytics/${pubxId}/auction`][index % 2]
['/analytics/bidwon', '/analytics/auction'][index % 2]
);
expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({
auctionTimestamp: '1616654312804',
pubxaiAnalyticsVersion: 'v2.0.0',
prebidVersion: '$prebid.version$',
pubxId: pubxId,
});
expect(expectedData.type).to.equal('text/json');
expect(JSON.parse(await readBlobSafariCompat(expectedData))).to.deep.equal([
Expand Down Expand Up @@ -1043,12 +1046,13 @@ describe('pubxai analytics adapter', () => {
const [expectedUrl, expectedData] = arg;
const parsedUrl = new URL(expectedUrl);
expect(parsedUrl.pathname).to.equal(
[`/analytics/${pubxId}/bidwon`, `/analytics/${pubxId}/auction`][index]
['/analytics/bidwon', '/analytics/auction'][index]
);
expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({
auctionTimestamp: '1616654312804',
pubxaiAnalyticsVersion: 'v2.0.0',
prebidVersion: '$prebid.version$',
pubxId: pubxId,
});
expect(expectedData.type).to.equal('text/json');
expect(JSON.parse(await readBlobSafariCompat(expectedData))).to.deep.equal([
Expand Down

0 comments on commit 5bfc260

Please sign in to comment.