API Docs for: 2.1.0
Show:

DeviceApi Class

The DeviceAtlas device detection API provides a way to detect devices based on the HTTP headers. Using the headers, the API returns device properties such as screen width, screen height, is mobile, vendor, model etc. The DeviceApiWeb is preferred when you want to get the properties from a real-time detection on user's device in a nodejs http server. The DeviceApi is preferred when you want to get the properties outside a nodejs http server or from an off-line user-agent list or header set.

Constructor

DeviceApi

(
  • configuration
)

Parameters:

Example:

var deviceApi = new DeviceApi();

var deviceApi = new DeviceApi({});

var deviceApi = new DeviceApi({ cookieName: 'newCookieName', includeUaProps: false, includeLangProps: false, includeMatchInfo: false, maxCacheEntries: 0 });

var deviceApi = new DeviceApi(new Config({ cookieName: 'newCookieName', includeUaProps: false, includeLangProps: false, includeMatchInfo: false, maxCacheEntries: 0 }));

Methods

getApiVersion

()

Get the Api version

getProperties

(
  • userAgentOrHeaders
  • clientSideProperties
  • callback
)
Properties

Get properties asynchronously for user agent and/or headers with the client-side properties

The contents of this cookie must be passed to this method. The client properties will over-ride any properties discovered from the main JSON data file.

Parameters:

  • userAgentOrHeaders Object

    <p>User Agent string or object of headers</p>

  • clientSideProperties Object

    <p>String of client side properties, alternatively, the callback if no clientside properties are passed</p>

  • callback Function(Error, Properties)

    <p>. Callback function containing errors if any, and properties</p>

Returns:

Properties:

<p>Properties object containing device properties if no callback given</p>

Example:

getProperties('userAgent', 'clientside', function(err, properties) { if (properties.contains('isMobilePhone', true)) { //it is a mobile } });

getProperties('userAgent', function(err, properties) { if (properties.contains('isMobilePhone', true)) { //it is a mobile } });

getProperties({'accept-language': '...','user-agent': '...', 'cookie': 'cookkieName=cookieValue;q=r;'}, 'clientside', function(err, properties) { if (properties.contains('isMobilePhone', true)) { //it is a mobile } });

getProperties({'accept-language': '...','user-agent': '...', 'cookie': 'cookkieName=cookieValue;q=r;'}, function(err, properties) { if (properties.contains('isMobilePhone', true)) { //it is a mobile } });

getPropertiesSync

(
  • userAgentOrHeaders
  • clientSideProperties
)
Properties

Get properties synchronously for user agent and/or headers with the client-side properties

The contents of this cookie must be passed to this method. The client properties will over-ride any properties discovered from the main JSON data file.

Parameters:

  • userAgentOrHeaders Object

    <p>User Agent string or object of headers</p>

  • clientSideProperties String

    <p>of client side properties</p>

Returns:

Properties:

<p>Properties object containing device properties if no callback given</p>

Example:

var properties = getPropertiesSync('userAgent', 'clientside'); if (properties.contains('isMobilePhone', true)) { //it is a mobile }

var properties = getPropertiesSync('userAgent'); if (properties.contains('isMobilePhone', true)) { //it is a mobile }

var properties = getPropertiesSync({'accept-language': '...','user-agent': '...', 'cookie': 'cookkieName=cookieValue;q=r;'}, 'clientside'); if (properties.contains('isMobilePhone', true)) { //it is a mobile }

var properties = getPropertiesSync({'accept-language': '...','user-agent': '...', 'cookie': 'cookkieName=cookieValue;q=r;'}); if (properties.contains('isMobilePhone', true)) { //it is a mobile }

getPropertyNames

() Array

Get a set of all possible property names. Note that the client-side properties are not included in this set.

Returns:

Array:

<p>A set of all possible device property names as PropertyNameType objects. A PropertyNameType object holds a property-name and it is a data-type</p>

loadData

(
  • json
)

Loads in data from a string

Parameters:

  • json String

    <p>String representation of json tree</p>