Skip to content

Commit

Permalink
PubxAi Analytics Adapter : code cleanup and additional data collection (
Browse files Browse the repository at this point in the history
prebid#11425)

* PTOW-2; updates to the pubx analytics adapter

* PTOW-2 review actions

* PTOW-2 Review actions

* PTOW-2 updating pubx.ai analytics version

* remove empty line

* linting changes

* PTOW-2; updates to the pubx analytics adapter

* PTOW-2 review actions

* PTOW-2 Review actions

* PTOW-2 updating pubx.ai analytics version

* PTOW-2 resolving conflicts

* PTOW-2-fix-linting-errors

* PTOW-2 fixing tests

* fixing bugs, modifying blob behaviour, addressing browser compatibility

* add source field

* switching from sessionStorage to localStorage

* fixing tests

* modifying functions to avoid prebid duplication checker

* implementing enums

* moving user agent code to libraries

* updated return types

* switching to macro substitution for prebid version

* adding centralised sendBeacon wrapper

* 'fixing' tests

---------

Co-authored-by: Nathan Oliver <[email protected]>
Co-authored-by: tej656 <[email protected]>
Co-authored-by: Tej <[email protected]>
Co-authored-by: nathan-pubx <[email protected]>
  • Loading branch information
5 people authored and DecayConstant committed Jul 18, 2024
1 parent 120a449 commit b5f8ac1
Show file tree
Hide file tree
Showing 7 changed files with 1,489 additions and 767 deletions.
58 changes: 58 additions & 0 deletions libraries/userAgentUtils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { deviceTypes, browserTypes, osTypes } from './userAgentTypes.enums.js';

/**
* Get the approximate device type enum from the user agent
* @returns {number}
*/
export const getDeviceType = () => {
if (
/ipad|android 3.0|xoom|sch-i800|playbook|tablet|kindle/i.test(
navigator.userAgent.toLowerCase()
)
) return deviceTypes.TABLET;
if (
/iphone|ipod|android|blackberry|opera|mini|windows\sce|palm|smartphone|iemobile/i.test(
navigator.userAgent.toLowerCase()
)
) return deviceTypes.MOBILE;
return deviceTypes.DESKTOP;
};

/**
* Get the approximate browser type enum from the user agent (or vendor
* if available)
* @returns {number}
*/
export const getBrowser = () => {
if (/Edg/.test(navigator.userAgent)) return browserTypes.EDGE;
else if (
/Chrome/.test(navigator.userAgent) &&
/Google Inc/.test(navigator.vendor)
) return browserTypes.CHROME;
else if (navigator.userAgent.match('CriOS')) return browserTypes.CHROME;
else if (/Firefox/.test(navigator.userAgent)) return browserTypes.FIREFOX;
else if (
/Safari/.test(navigator.userAgent) &&
/Apple Computer/.test(navigator.vendor)
) return browserTypes.SAFARI;
else if (
/Trident/.test(navigator.userAgent) ||
/MSIE/.test(navigator.userAgent)
) return browserTypes.INTERNET_EXPLORER;
else return browserTypes.OTHER;
};

/**
* Get the approximate OS enum from the user agent (or app version,
* if available)
* @returns {number}
*/
export const getOS = () => {
if (navigator.userAgent.indexOf('Android') != -1) return osTypes.ANDROID;
if (navigator.userAgent.indexOf('like Mac') != -1) return osTypes.IOS;
if (navigator.userAgent.indexOf('Win') != -1) return osTypes.WINDOWS;
if (navigator.userAgent.indexOf('Mac') != -1) return osTypes.MAC;
if (navigator.userAgent.indexOf('Linux') != -1) return osTypes.LINUX;
if (navigator.appVersion.indexOf('X11') != -1) return osTypes.UNIX;
return osTypes.OTHER;
};
22 changes: 22 additions & 0 deletions libraries/userAgentUtils/userAgentTypes.enums.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export const deviceTypes = Object.freeze({
DESKTOP: 0,
MOBILE: 1,
TABLET: 2,
})
export const browserTypes = Object.freeze({
CHROME: 0,
FIREFOX: 1,
SAFARI: 2,
EDGE: 3,
INTERNET_EXPLORER: 4,
OTHER: 5
})
export const osTypes = Object.freeze({
WINDOWS: 0,
MAC: 1,
LINUX: 2,
UNIX: 3,
IOS: 4,
ANDROID: 5,
OTHER: 6
})
Loading

0 comments on commit b5f8ac1

Please sign in to comment.