Skip to content

ff0000-ad-tech/ad-useragent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RED Interactive Agency - Ad Technology

npm (tag) GitHub issues npm downloads

GitHub contributors GitHub commit-activity npm license PRs Welcome


ad-useragent

Collection of methods and vars that parse the useragent to reveal information about the device on which the code is currently executing. Developed for the digital ad environment, lightwieght is the focus without sacrificing accuracy. If utilizing the entire package, it still comes in at ~2k babel/minified.

API

agentString : string

Current user agent of browser, unmodified or parsed.

import { agentString } from 'ad-useragent'
console.log(agentString) // 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36'

Kind: global variable

pixelRatio : string

Pixel ratio of device viewport.

import { pixelRatio } from 'ad-useragent'
console.log(pixelRatio) // 1

Kind: global variable

ad-useragent : object

Kind: global namespace

getOrientation() ⇒ string

Orientaion of device viewport: landscape or portrait.

import { getOrientation } from 'ad-useragent'
getOrientation() // 'landscape'

Kind: global function

getDimensions() ⇒ object

The current dimensions of the device's viewport, returns an object with a width & height value that are direct returns of windowWidth and windowHeight.

import { getDimensions } from 'ad-useragent'
getDimensions() // '{ width: 1024, height: 768 }'

Kind: global function
Properties

Name Type Description
width number window inner-width
height number window inner-height

report()

Called from within the pipeline, logs out the useragent string & all available pasered data for brand, product, device, OS & version, browser & version, dimensions, orientation, & pixel ratio

import { report } from 'ad-useragent'
report() // full output in console

Kind: global function

getBrand() ⇒ string

Brand of device, possible values are: microsoft, apple, android, rim, unknown.

import { getBrand } from 'ad-useragent'
getBrand() // 'apple'

Kind: global function

getProduct() ⇒ string

Brand subtype, possible values are?: windows phone, windows, iphone, ipad, ipod, mac, android, pixel 2, blackberry.

import { getProduct } from 'ad-useragent'
getProduct() // 'mac'

Kind: global function

getOS() ⇒ string

Operating system of device.

import { getOS } from 'ad-useragent'
getOS() // 'osx'

Kind: global function

getOSVersion() ⇒ string

Version of operating system of device.

import { getOSVersion } from 'ad-useragent'
getOSVersion() // '10.12.6'

Kind: global function

isOS() ⇒ boolean

Shorthand for getOS(), then check if is equal to string

import { isOS } from 'ad-useragent'
isDevice('ios') // false

Kind: global function

isBrowser(name) ⇒ boolean

Shorthand for getBrowser(), then check if is equal to string

import { isBrowser } from 'ad-useragent'
isBrowser('ie') // false

Kind: global function

Param Type Description
name string The browser name as a string, eg: 'chrome', 'ie'

getBrowser() ⇒ string

Brand of browser, eg: chrome, safari, ie, firefox, edge

import { getBrowser } from 'ad-useragent'
getBrowser() // 'chrome'

Kind: global function

getBrowserVersion() ⇒ string

Version of the browser.

import { getBrowserVersion } from 'ad-useragent'
getBrowserVersion() // '73.0.3683.103'

Kind: global function

isDevice(type) ⇒ boolean

Shorthand for getDevice(), then check if is equal to string

import { isDevice } from 'ad-useragent'
const isDesktop = isDevice('desktop') // true

Kind: global function

Param Type Description
type string The device type as a string, eg: 'mobile', 'tablet', or 'desktop'

getDevice() ⇒ string

The device type as a string, possible values are: mobile, tablet, desktop.

Windows > 8 currently returns tablet, currently no way to differentiate from desktop.

import { getDevice } from 'ad-useragent'
getDevice() // 'desktop'

Kind: global function

isDualGestureIE() ⇒ boolean

Special test case method. When on a hybrid tablet-laptop running Windows 7 or 8 using Internet Explorer 11 or under, getDevice() will return "tablet", however that can lead to conflicting desired results when wanting mouse based interactions rather than touch. Run this BEFORE using getDevice() as it will re-assign device type to 'desktop' if all conditions are met.

NOTE: This test required the entire package to test against the device, os, os version, browser, and browser version

import { isDualGestureIE, getDevice } from 'ad-useragent'
isDualGestureIE()
getDevice() // 'desktop'

Kind: global function


About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published