Client-side Component - Full Documentation

DeviceAtlas provides an optional client-side JavaScript library for gathering additional properties using Javascript. This library can send the gathered properties back to the DeviceAtlas API running on a web server.

The JavaScript properties are then used to augment the regular DeviceAtlas properties and allow for additional capabilities like fine-grained Apple device detection.

The client properties are also available to other JavaScript libraries. The DeviceAtlas client detection file needs to be included on your web page for this to function. Full documentation and example code are included in the API packages.

Introduction

DeviceAtlas uses HTTP headers to accurately identify devices. This is achieved by passing the headers to a server-side DeviceAtlas API. The API then uses the headers to determine the correct set of properties for the request. These properties are then returned to the calling application.

This approach is suitable for the vast majority of cases except for two situations:

  1. Apple Devices: The data passed from Apple devices in the HTTP headers does not contain any information to indicate which specific model is accessing the server. It only shows if it is an iPhone, iPad or iPod Touch but not, for example, if it's an iPhone 4 or an iPhone 7. This is a large problem if device specific data is required for these devices. Client-side data can be used to augment the server-side DeviceAtlas data to more accurately identify Apple devices.

  2. Contextual information: Client-side data can help indicate the current context of the user/device such as the current device orientation of the device or if the user has cookies enabled. It can also improve the server-side property set for JavaScript and HTML5 properties for less well-known browsers.

Client-side Component

The DeviceAtlas client-side component is a small JavaScript library that can be included on a webpage. The library gathers client-side properties and optionally creates a cookie containing the data. The cookie is used as a means of transferring the client-side data to the server but alternative approaches can be used such as sending the data in an Ajax request. The client-side data sent to the server must then be passed to the DeviceAtlas API along with the device HTTP headers. The API will use the HTTP headers and the client-side properties to detect Apple Devices. The resulting property set contains the merged server and client side properties.

Client-side Access to Properties

The properties gathered by the client-side component are available to other JavaScript functions and can be accessed on the client-side by using the "DeviceAtlas" namespace.

Example:

// Does the browser support Web GL ?
var supportsWebGl = DeviceAtlas.js.webGl;

The normal DeviceAtlas property name should be used to access the client-side property. A full list of the client side properties can be found on the DeviceAtlas website.

Server-side Access to Properties

The client-side component creates a special cookie with the detected client properties. This cookie is used as a way to transmit the properties back to the server. Other approaches such as AJAX could also be used. The usage of the properties via the cookie is different in the Enterprise and Cloud APIs.

By default, the cookie containing the properties is called "DAPROPS".

Use with Enterprise API

If the cookie is available and the DeviceApiWeb extension is used, the API will automatically use the cookie contents as a part of the detection. However it is also possible to pass the client-side properties manually to the APIs. Please refer to the technical API development documentation for details.

Apache / NGINX / IIS web server modules handle the cookie automatically.

Compatibility requirements

For correct functionality an up-to-date JSON file and the following Enterprise API versions are required.

  • Java: 1.6 or later
  • Node.js: 2.1 or later
  • PHP: 1.6 or later
  • .NET: 1.6 or later
  • Python: 1.6 or later
  • Ruby: 1.6 or later
  • C++: 2.1.2 or later
  • C: 2.1.2 or later

Use with Cloud API

If the cookie is available and the API is configured to use the cookie, the API will automatically forward the cookie contents to the Cloud service and will be used as a part of the detection. Please refer to the technical API development documentation for details.

Compatibility requirements

For correct functionality the Cloud API 1.3 version or later is required.

Basic Server-side Usage

  1. Include the https://cs.deviceatlas-cdn.com/dacs.js javascript file on a web page.
  2. In the server-side web application, pass the contents of the DeviceAtlas cookie to the DeviceAtlas API.

NOTE: the cookie contents will only be set after the first request. It is recommended to not rely on the client-side properties for the very first page load.

Please see the Example code bundled with the API for more information.

Custom Configuration

To customize the cookie name or other cookie parameters like domain or a path you can use the configuration code below - this code must be included before the client-side javascript file. In case of restricted cookies access usage of onPropertiesUpdate field is strongly recommended in order to retrieve the complete set of properties - when detecting iPhone audioRef property is required.

<script type="text/javascript">
var DeviceAtlas = {
cookieName: 'DAPROPS', // the cookie name
cookieExpiryDays: 1, // the time cookie expires in days
cookieDomain: '.yourdomain.tld', // custom domain
cookiePath: '/', // custom path
debug: false, // expects bool|function - default false, pass true to use console.log or pass any callback function
cacheType: 'cookie', // cache type to store test results - available options 'cookie', 'local-storage', 'none'
cacheKey: 'DAPROPS', // cache key for storing client-side test results on browser
cacheExpiryDays: 1, // the time cache expires in days
waitMilliSecondsToBulkSendProperties: 3000, // max wait (to get properties resolved) in miliseconds before firing onPropertiesUpdate
dontStopPropertyUpdateEvents: false, // only one onPropertiesUpdate event is sent, set true to keep getting onPropertiesUpdate
onPropertiesUpdate: function(properties, propertiesAsString) { // expects function - default undefined, pass function to capture properties updates
// properties will be object containing all properties detected by DeviceAtlas client-side
// propertiesAsString would have properties as string acceptable by DeviceAtlas API
},
}
</script>
<script type="text/javascript" src="https://cs.deviceatlas-cdn.com/dacs.js" async></script>

Browser Results Cache Types

Cookies or Local Storage works as cache to avoid re-running tests. Few differences when using cookie or local storage.

  • Using cacheType=cookie tests are saved in cookie, cookie name can be configured in cookieName config,
    • on every page load client-side library will determine tests to run/skip based on results saved in cookies from previous runs.
    • all further requests from browser will have Cookie string attached to request (in Cookie header) automatically by browser, to be passed to DeviceAtlas API on server side.
    • user can also use onPropertiesUpdate callback function to pass client-side string to DeviceAtlas API on server side.
  • Using cacheType=local-storage tests are saved in local-storage, local sorage key can be configured in cacheKey config,
    • on every page load client-side library will determine tests to run/skip based on results saved in local-storage from previous runs.
    • to results back to DeviceAtlas API on server side users will have to use onPropertiesUpdate callback function.
  • Using cacheType=none tests results are evalulated on every page load.
    • on every page load client-side library will re-run tests.
    • to results back to DeviceAtlas API on server side users will have to use onPropertiesUpdate callback function.

Sending client-side data

In a restricted environment where cookies are not allowed it is possible to get the client-side data using the onPropertiesUpdate event method and passing propertiesAsString as a URL parameter. onPropertiesUpdate event will be fired - if all properties required for Apple Devices Detection are resolved - if max wait time exceeds when waiting on required for Apple Devices Detection to be resolved check configs waitMilliSecondsToBulkSendProperties, dontStopPropertyUpdateEvents

Local Storage can be used to cache client side test results on user's browser, check cacheType config.

NOTE: When integrating with a web application, the value should be fetched from the URL and passed to the DeviceAtlas API.

Example:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script type="text/javascript">
var DeviceAtlas = {
onPropertiesUpdate: function(properties, propertiesAsString) {
// user-agent and other headers are automatically added by browser on request to server side
// if using cookie as cache, Cookie header is automatically added to requests by browser
// for local-storage or no cache, client-side properties can be passed via header or GET/POST parameter to server side running DeviceAtlas API
// below client-side string is being passed via DeviceAtlas-Client-Side-String header
// DeviceAtlas API on server-side would need to read the header and pass client-side properties in API's getProperties method

var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if (req.readyState == XMLHttpRequest.DONE) {
// req.responseText here would hold detected device properties
// from DeviceAtlas API lookup on server side
console.log(req.responseText);
}
}
req.open('GET', './deviceatlas-api-on-server-side', true);
req.setRequestHeader('DeviceAtlas-Client-Side-String', propertiesAsString);
req.send(null);
}
}
</script>
<script type="text/javascript" src="https://cs.deviceatlas-cdn.com/dacs.js" async></script>
</body>
</html>

Identification of Apple devices

The DeviceAtlas Client-side Component augments the server side properties and allows for accurate identification of Apple devices. The following variants of iPhone and iPad models are identified. Please note there is a small selection of older devices that cannot be identified fully. In this case, all of the possible model names are returned.

Model Model Identifiers Without client-side With client-side
iPhone 12 Mini iPhone13,1 iPhone iPhone 12 Mini
iPhone 12 Pro Max iPhone13,4 iPhone iPhone 12 Pro Max
iPhone 12 Pro iPhone13,3 iPhone iPhone 12/iPhone 12 Pro
iPhone 12 iPhone13,2 iPhone iPhone 12/iPhone 12 Pro
iPhone SE (2nd generation) iPhone12,8 iPhone iPhone SE (2nd generation)
iPad Pro (12.9 4th Gen) iPad8,12, iPad8,11 iPad iPad Pro (12.9 3rd Gen)/iPad Pro (12.9 4th Gen)
iPad Pro (11 2nd Gen) iPad8,10, iPad8,9 iPad iPad Pro (11)/iPad Pro (11 2nd Gen)
iPad Air 4 iPad13,2, iPad13,1 iPad iPad Air 4
iPad (8th Gen) iPad11,7, iPad11,6 iPad iPad (8th Gen)
iPhone 11 Pro Max iPhone12,5 iPhone iPhone 11 Pro Max
iPhone 11 Pro iPhone12,3 iPhone iPhone 11 Pro
iPhone 11 iPhone11,8, iPhone11,6, iPhone12,1 iPhone iPhone 11
iPad mini 5 iPad11,2, iPad11,1 iPad iPad mini 5
iPad Air 3 iPad11,4, iPad11,3 iPad iPad Air 3
iPad (7th Gen) iPad7,12, iPad7,11 iPad iPad (7th Gen)
iPhone XS Max iPhone11,6, iphone11,6, iPhone11,4 iPhone iPhone XS Max
iPhone XS iPhone11,2, iphone11,2 iPhone iPhone XS
iPhone XR iPhone11,8, iphone11,8 iPhone iPhone XR
iPad Pro (12.9 3rd Gen) iPad8,5, iPad8,8, iPad8,6, iPad8,7 iPad iPad Pro (12.9 3rd Gen)/iPad Pro (12.9 4th Gen)
iPad Pro (11) iPad8,2, iPad8,3, iPad8,4, iPad8,1 iPad iPad Pro (11)/iPad Pro (11 2nd Gen)
iPad (6th Gen) ipad7,5, iPad7,6, iPad7,5 iPad iPad (5th Gen)/iPad (6th Gen)
iPhone X iPhone10,6, iphone10,6, iphone10,3, iPhone10,3 iPhone iPhone X
iPhone 8 Plus iphone10,5, iphone10,2, iPhone10,2, iPhone10,5 iPhone iPhone 8 Plus
iPhone 8 iphone10,4, iphone10,1, iPhone10,1, iPhone10,4 iPhone iPhone 8
iPad Pro (12.9 2nd Gen) iPad7,1, iPad7,2 iPad iPad Pro (12.9 2nd Gen)
iPad Pro (10.5) iPad7,4, iPad7,3 iPad iPad Pro (10.5)
iPad (5th Gen) ipad6,12, iPad6,12, iPad6,11 iPad iPad (5th Gen)/iPad (6th Gen)
iPhone SE iphone8,4, iPhone8,4 iPhone iPhone SE
iPhone 7 Plus iphone9,4, iphone9,2, iPhone9,4, iPhone9,2 iPhone iPhone 7 Plus
iPhone 7 iPhone9,1, iphone9,1, iPhone9,3, iphone9,3 iPhone iPhone 7
iPad Pro (9.7) iPad6,4, iPad6,3 iPad iPad Pro (9.7)
iPhone 6S Plus iphone8,2, iPhone8,2 iPhone iPhone 6S Plus
iPhone 6S iphone8,1, iPhone8,1 iPhone iPhone 6S
iPad Pro iPad6,8, iPad6,7 iPad iPad Pro
iPad mini 4 iPad5,1, ipad5,2, iPad5,2 iPad iPad Air 2/iPad mini 4
iPhone 6 Plus iPhone7,1 iPhone iPhone 6 Plus
iPhone 6 iPhone7,2, iphone7,2 iPhone iPhone 6
iPad mini 3 iPad4,8, iPad4,9, iPad4,7 iPad iPad Air/iPad mini 2/iPad mini 3
iPad Air 2 iPad5,3, iPad5,4, ipad5,3 iPad iPad Air 2/iPad mini 4
iPhone 5S iPhone6,2, iPhone6,1 iPhone iPhone 5S
iPhone 5C iPhone5,4, iPhone5,3 iPhone iPhone 5/iPhone 5C
iPad mini Retina iPad4,4, iPad4,5, iPad4,6 iPad iPad Air/iPad mini 2/iPad mini 3
iPad Air iPad4,2, iPad4,3, iPad4,1 iPad iPad Air/iPad mini 2/iPad mini 3
iPhone 5 iPhone5,1, iPhone5,2 iPhone iPhone 5/iPhone 5C
iPad Retina (4th Gen) iPad3,5, iPad3,4, iPad3,6 iPad iPad Retina (4th Gen)
iPad mini iPad2,6, iPad2,5, iPad2,7 iPad iPad 2/iPad mini
iPad /retina display iPad3,5, iPad3,1, iPad3,4, iPad3,3, iPad3,2, iPad3,6 iPad iPad /retina display
iPhone 4S iPhone4,1 iPhone iPhone 4S
iPad 2 iPad2,1, iPad2,2, iPad2,3, iPad2,4 iPad iPad 2/iPad mini
iPhone 4 iPhone3,2, iPhone3,1, iPhone3,3 iPhone iPhone 4
iPad iPad1,1 iPad iPad
iPhone 3GS iPhone2,1 iPhone iPhone/iPhone 3G/iPhone 3GS
iPhone 3G iPhone1,2 iPhone iPhone/iPhone 3G/iPhone 3GS
iPhone iPhone1,1 iPhone iPhone/iPhone 3G/iPhone 3GS

Adding device properties

The capabilities of the Client-side component can be customized by adding or replacing functions to detect device properties.

Example:


<script type="text/javascript">

/**
* Adding property to see if it's a modern browser:
*
* For more details: https://www.w3.org/TR/html5/
*/
var DeviceAtlas = {
properties: {
isModernBrowser: function(isModernBrowserValueFromCache, asyncDoneCallback, detectedProperties) {
return detectedProperties.cookieSupport &&
detectedProperties.js.webWorkers &&
detectedProperties.js.webSockets &&
detectedProperties.css.animations &&
detectedProperties.html.video &&
detectedProperties.html.svg &&
detectedProperties.js.webGl &&
detectedProperties.js.localStorage;
}
}
}

</script>
<script type="text/javascript" src="https://cs.deviceatlas-cdn.com/dacs.js" async></script>

Client-side Component Variants

Standard Library

The standard version of the Client-side Component is distributed via CDN here https://cs.deviceatlas-cdn.com/dacs.js.

It provides the detection of the full property set.

Lite Variant

The Lite variant, a subset of the standard component for optimization purposes, is distributed in via https://cs.deviceatlas-cdn.com/dacs-lite.js.

It solely identifies those device properties that are required to distinguish the underlying hardware of iOS based devices.

Custom Build

From the DeviceAtlas site, a customized Client-side component with a subset of properties can be created tailored to specific needs.

The resulting JavaScript file will be optimized in terms of size and speed to improve end-user experience.