diff --git a/modules/pubxaiAnalyticsAdapter.js b/modules/pubxaiAnalyticsAdapter.js index cef6989006f..c0526db0fcf 100644 --- a/modules/pubxaiAnalyticsAdapter.js +++ b/modules/pubxaiAnalyticsAdapter.js @@ -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 @@ -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 @@ -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)]) ); @@ -128,7 +127,7 @@ const getAdServerDataForBid = (bid) => { */ const getStorage = () => { try { - return window.top["sessionStorage"]; + return window.top['sessionStorage']; } catch (e) { return null; } @@ -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 @@ -246,16 +244,16 @@ 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'; }; /** @@ -263,25 +261,19 @@ export const getDeviceType = () => { * @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'; }; /** @@ -289,13 +281,13 @@ export const getBrowser = () => { * @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'; }; /** @@ -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( @@ -359,7 +351,7 @@ const prepareSend = (auctionId) => { return; } const pubxaiAnalyticsRequestUrl = buildUrl({ - protocol: "https", + protocol: 'https', hostname: (auctionData.initOptions && auctionData.initOptions.hostName) || defaultHost, @@ -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; @@ -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(); } }); @@ -425,7 +417,7 @@ pubxaiAnalyticsAdapter.enableAnalytics = (config) => { adapterManager.registerAnalyticsAdapter({ adapter: pubxaiAnalyticsAdapter, - code: "pubxai", + code: 'pubxai', }); export default pubxaiAnalyticsAdapter;