Skip to content

Commit

Permalink
Merge pull request #16 from nathan-pubx/PTOW-2-review-actions
Browse files Browse the repository at this point in the history
switching from sessionStorage to localStorage
  • Loading branch information
pnhegde authored Jun 11, 2024
2 parents f0ab6c0 + 2be6c09 commit 89ae0b3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
20 changes: 6 additions & 14 deletions modules/pubxaiAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ import {
getGptSlotInfoForAdUnitCode,
getGptSlotForAdUnitCode,
} from '../libraries/gptUtils/gptUtils.js';
import { getStorageManager } from '../src/storageManager.js';
import { MODULE_TYPE_ANALYTICS } from '../src/activities/modules.js';

let initOptions;

const emptyUrl = '';
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 })

/**
* The sendCache is a global cache object which tracks the pending sends
Expand Down Expand Up @@ -75,7 +79,7 @@ export const auctionCache = new Proxy(
consentDetail: {
consentTypes: Object.keys(getGlobal().getConsentMetadata?.() || {}),
},
pmacDetail: JSON.parse(getStorage()?.getItem('pubx:pmac')) || {}, // {auction_1: {floor:0.23,maxBid:0.34,bidCount:3},auction_2:{floor:0.13,maxBid:0.14,bidCount:2}
pmacDetail: JSON.parse(storage.getDataFromLocalStorage('pubx:pmac')) || {}, // {auction_1: {floor:0.23,maxBid:0.34,bidCount:3},auction_2:{floor:0.13,maxBid:0.14,bidCount:2}
initOptions: {
...initOptions,
auctionId: name, // back-compat
Expand Down Expand Up @@ -121,18 +125,6 @@ const getAdServerDataForBid = (bid) => {
return {}; // TODO: support more ad servers
};

/**
* Access sessionStorage
* @returns {Storage}
*/
const getStorage = () => {
try {
return window.top['sessionStorage'];
} catch (e) {
return null;
}
};

/**
* extracts and derives valuable data from a prebid bidder bidResponse object
* @param {object} bidResponse a prebid bidder bidResponse (see
Expand Down Expand Up @@ -424,7 +416,7 @@ pubxaiAnalyticsAdapter.enableAnalytics = (config) => {

adapterManager.registerAnalyticsAdapter({
adapter: pubxaiAnalyticsAdapter,
code: 'pubxai',
code: adapterCode,
});

export default pubxaiAnalyticsAdapter;
13 changes: 6 additions & 7 deletions test/spec/modules/pubxaiAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ describe('pubxai analytics adapter', () => {
let originalVS;

let location = utils.getWindowLocation();
let storage = window.top['sessionStorage'];

const replaceProperty = (obj, params) => {
let strObj = JSON.stringify(obj);
Expand Down Expand Up @@ -601,7 +600,7 @@ describe('pubxai analytics adapter', () => {
consentDetail: {
consentTypes: Object.keys(getGlobal().getConsentMetadata?.() || {}),
},
pmacDetail: JSON.parse(storage.getItem('pbx:pmac')) || {},
pmacDetail: {},
initOptions: {
...initOptions,
auctionId: 'bc3806e4-873e-453c-8ae5-204f35e923b4',
Expand Down Expand Up @@ -695,7 +694,7 @@ describe('pubxai analytics adapter', () => {
consentDetail: {
consentTypes: Object.keys(getGlobal().getConsentMetadata?.() || {}),
},
pmacDetail: JSON.parse(storage.getItem('pbx:pmac')) || {},
pmacDetail: {},
initOptions: {
...initOptions,
auctionId: 'bc3806e4-873e-453c-8ae5-204f35e923b4',
Expand Down Expand Up @@ -767,7 +766,7 @@ describe('pubxai analytics adapter', () => {
expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({
auctionTimestamp: '1616654312804',
pubxaiAnalyticsVersion: 'v2.0.0',
prebidVersion: getGlobal()?.version,
prebidVersion: String(getGlobal().version),
});
expect(expectedData.type).to.equal('text/json');
expect(JSON.parse(await readBlobSafariCompat(expectedData))).to.deep.equal([
Expand Down Expand Up @@ -810,7 +809,7 @@ describe('pubxai analytics adapter', () => {
expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({
auctionTimestamp: '1616654312804',
pubxaiAnalyticsVersion: 'v2.0.0',
prebidVersion: getGlobal()?.version,
prebidVersion: String(getGlobal().version),
});

// Step 9: check that the data sent in the request is correct
Expand Down Expand Up @@ -935,7 +934,7 @@ describe('pubxai analytics adapter', () => {
expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({
auctionTimestamp: '1616654312804',
pubxaiAnalyticsVersion: 'v2.0.0',
prebidVersion: getGlobal()?.version,
prebidVersion: String(getGlobal().version),
});
expect(expectedData.type).to.equal('text/json');
expect(JSON.parse(await readBlobSafariCompat(expectedData))).to.deep.equal([
Expand Down Expand Up @@ -1051,7 +1050,7 @@ describe('pubxai analytics adapter', () => {
expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({
auctionTimestamp: '1616654312804',
pubxaiAnalyticsVersion: 'v2.0.0',
prebidVersion: getGlobal()?.version,
prebidVersion: String(getGlobal().version),
});
expect(expectedData.type).to.equal('text/json');
expect(JSON.parse(await readBlobSafariCompat(expectedData))).to.deep.equal([
Expand Down

0 comments on commit 89ae0b3

Please sign in to comment.