# DeviceAtlas Cloud Client API Usage # This section deals with usage of the DeviceAtlas Cloud API. ## Client Side Library - Apple Device Identification ## In addition to the server-side API, an optional client-side Javascript library is available. This library is important for two reasons: 1. It facilitates identification of Apple devices. Apple devices are _not_ identifiable using only HTTP User-Agent data. 2. It allows for the collection of dynamic or changing properties. When the client-side library is embedded in a web page it collects additional properties from the client's web browser. This data is then sent back to the server and must be passed to the DeviceAtlas API along with the HTTP headers. The combination of the client data and the server side data allow for accurate identification of Apple devices. The client-side library may be included on a webpage by adding the following snippet: ```Javascript <!-- Adding the DeviceAtlas client side component to get client side properties --> <script type="text/javascript" src="https://cs.deviceatlas-cdn.com/dacs.js" async></script> ``` By default, the client-side library returns the data via a cookie. If this is present in the `request` object it will be automatically used. The cookie name is configurable via the `Config` class. Alternatively, the client data may be returned via AJAX and passed to the server side API manually. For additional information, please see the [Client Side Library](https://docs.deviceatlas.com/apis/clientside/latest/README.ClientSide.html) documentation. ## Basic Usage ## The DeviceAtlas Cloud Client API can be used as follows: ### Instantiate the client ### First, we create an instance of the client with the licence key. ```javascript const Config = require('deviceatlas-cloud-nodejs').Config; const Client = require('deviceatlas-cloud-nodejs').Client; const config = new Config("LICENCE KEY"); const client = new Client(config); ``` ### Device Identification ### Now that we have the client instantiated, there are two device identification methods: #### Identification via headers #### The device can be identified by passing a set of HTTP headers: ```javascript const headers = { 'User-Agent': 'Mozilla/5.0 (Linux; U; Android 2.3.3; en-gb; GT-I9100 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1', 'Accept-Language': 'en-US' }; client.getProperties(headers).then((properties) => { console.log(properties) }) .catch((error) => { console.error('Error performing identification:', error); }); ``` #### Identification via a request object #### The device can be identified by passing a request object: ```javascript app.get('/', async (req, res) => { client.getPropertiesFromRequest(req).then((properties) => { console.log(properties); }) .catch((error) => { console.error('Error performing identification:', error); }); }); ``` See the list of all property names here: https://deviceatlas.com/resources/available-properties The availability of a property depends on the device and your licence, before accessing a property always check if it exists in the set or not. ### Additional Examples ### Please find more complete examples in the /Examples directory. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - _ Copyright (c) DeviceAtlas Limited 2024. All Rights Reserved. _ _ https://deviceatlas.com _ <!-- HTML+JS for document formatting when opened in browser --> <div class="btn-group" id="main-menu" style="float:right"><a class="btn dropdown-toggle" data-toggle="dropdown" href="#">Menu<span class="caret"></span></a><ul class="dropdown-menu"><li><a href="README.html">Cloud Client API Introduction</a></li><li><a href="README.Installation.html">Cloud Client API Installation</a></li><li class="disabled"><a href="README.CloudApi.html">Cloud Client API Usage</a></li><li><a href="README.Config.html">Cloud Client API Configuration</a></li><li class="divider"></li><li><a href="./ApiDocs/index.html">DeviceAtlas Cloud Client API NodeJS docs</a></li></ul></div>