Skip to content

Commit

Permalink
Merge pull request #11 from tej656/master
Browse files Browse the repository at this point in the history
linting changes
  • Loading branch information
pnhegde authored May 7, 2024
2 parents f394949 + 96baeb0 commit 8eabf25
Showing 1 changed file with 57 additions and 65 deletions.
122 changes: 57 additions & 65 deletions modules/pubxaiAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@ import {
getWindowLocation,
buildUrl,
cyrb53Hash,
} from "../src/utils.js";
import adapter from "../libraries/analyticsAdapter/AnalyticsAdapter.js";
import adapterManager from "../src/adapterManager.js";
import CONSTANTS from "../src/constants.json";
import { getGlobal } from "../src/prebidGlobal.js";
} from '../src/utils.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import adapterManager from '../src/adapterManager.js';
import CONSTANTS from '../src/constants.js';
import { getGlobal } from '../src/prebidGlobal.js';
import {
getGptSlotInfoForAdUnitCode,
getGptSlotForAdUnitCode,
} from "../libraries/gptUtils/gptUtils.js";

} from '../libraries/gptUtils/gptUtils.js';

let initOptions;

const emptyUrl = "";
const analyticsType = "endpoint";
const pubxaiAnalyticsVersion = "v2.0.0";
const defaultHost = "api.pbxai.com";
const auctionPath = "/analytics/auction";
const winningBidPath = "/analytics/bidwon";
const emptyUrl = '';
const analyticsType = 'endpoint';
const pubxaiAnalyticsVersion = 'v2.0.0';
const defaultHost = 'api.pbxai.com';
const auctionPath = '/analytics/auction';
const winningBidPath = '/analytics/bidwon';

/**
* The sendCache is a global cache object which tracks the pending sends
Expand Down Expand Up @@ -76,7 +75,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(getStorage()?.getItem('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 @@ -113,8 +112,8 @@ const getAdServerDataForBid = (bid) => {
.getTargetingKeys()
.filter(
(key) =>
key.startsWith("pubx-") ||
(key.startsWith("hb_") && (key.match(/_/g) || []).length === 1)
key.startsWith('pubx-') ||
(key.startsWith('hb_') && (key.match(/_/g) || []).length === 1)
)
.map((key) => [key, gptSlot.getTargeting(key)])
);
Expand All @@ -128,7 +127,7 @@ const getAdServerDataForBid = (bid) => {
*/
const getStorage = () => {
try {
return window.top["sessionStorage"];
return window.top['sessionStorage'];
} catch (e) {
return null;
}
Expand Down Expand Up @@ -163,12 +162,11 @@ const extractBid = (bidResponse) => {
transactionId: bidResponse.transactionId,
bidId: bidResponse.bidId || bidResponse.requestId,
placementId: bidResponse.params
? deepAccess(bidResponse, "params.0.placementId")
? deepAccess(bidResponse, 'params.0.placementId')
: null,
};
};


/**
* Track the events emitted by prebid and handle each case. See https://docs.prebid.org/dev-docs/publisher-api-reference/getEvents.html for more info
* @param {object} event the prebid event emmitted
Expand Down Expand Up @@ -246,56 +244,50 @@ export const getDeviceType = () => {
navigator.userAgent.toLowerCase()
)
) {
return "tablet";
return 'tablet';
}
if (
/iphone|ipod|android|blackberry|opera|mini|windows\sce|palm|smartphone|iemobile/i.test(
navigator.userAgent.toLowerCase()
)
) {
return "mobile";
return 'mobile';
}
return "desktop";
return 'desktop';
};

/**
* Get the approximate browser type from the user agent (or vendor if available)
* @returns {string}
*/
export const getBrowser = () => {
if (/Edg/.test(navigator.userAgent)) return "Microsoft Edge";
if (/Edg/.test(navigator.userAgent)) return 'Microsoft Edge';
else if (
/Chrome/.test(navigator.userAgent) &&
/Google Inc/.test(navigator.vendor)
)
return "Chrome";
else if (navigator.userAgent.match("CriOS")) return "Chrome";
else if (/Firefox/.test(navigator.userAgent)) return "Firefox";
) { return 'Chrome'; } else if (navigator.userAgent.match('CriOS')) return 'Chrome';
else if (/Firefox/.test(navigator.userAgent)) return 'Firefox';
else if (
/Safari/.test(navigator.userAgent) &&
/Apple Computer/.test(navigator.vendor)
)
return "Safari";
else if (
) { return 'Safari'; } else if (
/Trident/.test(navigator.userAgent) ||
/MSIE/.test(navigator.userAgent)
)
return "Internet Explorer";
else return "Others";
) { return 'Internet Explorer'; } else return 'Others';
};

/**
* Get the approximate OS from the user agent (or app version, if available)
* @returns {string}
*/
export const getOS = () => {
if (navigator.userAgent.indexOf("Android") != -1) return "Android";
if (navigator.userAgent.indexOf("like Mac") != -1) return "iOS";
if (navigator.userAgent.indexOf("Win") != -1) return "Windows";
if (navigator.userAgent.indexOf("Mac") != -1) return "Macintosh";
if (navigator.userAgent.indexOf("Linux") != -1) return "Linux";
if (navigator.appVersion.indexOf("X11") != -1) return "Unix";
return "Others";
if (navigator.userAgent.indexOf('Android') != -1) return 'Android';
if (navigator.userAgent.indexOf('like Mac') != -1) return 'iOS';
if (navigator.userAgent.indexOf('Win') != -1) return 'Windows';
if (navigator.userAgent.indexOf('Mac') != -1) return 'Macintosh';
if (navigator.userAgent.indexOf('Linux') != -1) return 'Linux';
if (navigator.appVersion.indexOf('X11') != -1) return 'Unix';
return 'Others';
};

/**
Expand All @@ -321,32 +313,32 @@ const prepareSend = (auctionId) => {
{
path: winningBidPath,
requiredKeys: [
"winningBid",
"pageDetail",
"deviceDetail",
"floorDetail",
"auctionDetail",
"userDetail",
"consentDetail",
"pmacDetail",
"initOptions",
'winningBid',
'pageDetail',
'deviceDetail',
'floorDetail',
'auctionDetail',
'userDetail',
'consentDetail',
'pmacDetail',
'initOptions',
],
eventType: "win",
eventType: 'win',
},
{
path: auctionPath,
requiredKeys: [
"bids",
"pageDetail",
"deviceDetail",
"floorDetail",
"auctionDetail",
"userDetail",
"consentDetail",
"pmacDetail",
"initOptions",
'bids',
'pageDetail',
'deviceDetail',
'floorDetail',
'auctionDetail',
'userDetail',
'consentDetail',
'pmacDetail',
'initOptions',
],
eventType: "auction",
eventType: 'auction',
},
].forEach(({ path, requiredKeys, eventType }) => {
const data = Object.fromEntries(
Expand All @@ -359,7 +351,7 @@ const prepareSend = (auctionId) => {
return;
}
const pubxaiAnalyticsRequestUrl = buildUrl({
protocol: "https",
protocol: 'https',
hostname:
(auctionData.initOptions && auctionData.initOptions.hostName) ||
defaultHost,
Expand All @@ -376,7 +368,7 @@ const prepareSend = (auctionId) => {
};

const send = () => {
const toBlob = (d) => new Blob([JSON.stringify(d)], { type: "text/json" });
const toBlob = (d) => new Blob([JSON.stringify(d)], { type: 'text/json' });

Object.entries(sendCache).forEach(([requestUrl, events]) => {
let payloadStart = 0;
Expand All @@ -400,8 +392,8 @@ const send = () => {

// register event listener to send logs when user leaves page
if (hasSendBeaconSupport()) {
document.addEventListener("visibilitychange", () => {
if (document.visibilityState === "hidden") {
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'hidden') {
send();
}
});
Expand All @@ -425,7 +417,7 @@ pubxaiAnalyticsAdapter.enableAnalytics = (config) => {

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

export default pubxaiAnalyticsAdapter;

0 comments on commit 8eabf25

Please sign in to comment.