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.
- agentString :
string
- pixelRatio :
string
- getOrientation() ⇒
string
- getDimensions() ⇒
object
- report()
- getBrand() ⇒
string
- getProduct() ⇒
string
- getOS() ⇒
string
- getOSVersion() ⇒
string
- isOS() ⇒
boolean
- isBrowser(name) ⇒
boolean
- getBrowser() ⇒
string
- getBrowserVersion() ⇒
string
- isDevice(type) ⇒
boolean
- getDevice() ⇒
string
- isDualGestureIE() ⇒
boolean
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'
Pixel ratio of device viewport.
import { pixelRatio } from 'ad-useragent' console.log(pixelRatio) // 1
Orientaion of device viewport: landscape or portrait.
import { getOrientation } from 'ad-useragent' getOrientation() // 'landscape'
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 |
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
Brand of device, possible values are:
microsoft
,
apple
,
android
,
rim
,
unknown
.
import { getBrand } from 'ad-useragent' getBrand() // 'apple'
Brand subtype, possible values are?:
windows phone
,
windows
,
iphone
,
ipad
,
ipod
,
mac
,
android
,
pixel 2
,
blackberry
.
import { getProduct } from 'ad-useragent' getProduct() // 'mac'
Operating system of device.
import { getOS } from 'ad-useragent' getOS() // 'osx'
Version of operating system of device.
import { getOSVersion } from 'ad-useragent' getOSVersion() // '10.12.6'
Shorthand for getOS(), then check if is equal to string
import { isOS } from 'ad-useragent' isDevice('ios') // false
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' |
Brand of browser, eg: chrome, safari, ie, firefox, edge
import { getBrowser } from 'ad-useragent' getBrowser() // 'chrome'
Version of the browser.
import { getBrowserVersion } from 'ad-useragent' getBrowserVersion() // '73.0.3683.103'
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' |
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'
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