Knowledge base

JavaScript

How does it work?

To make use of Netbiscuits’ JavaScript Device Detection, you have to add a JavaScript code block to any pages on which you want to use it. The earlier in your HTML you add this code block, the sooner you can use it, but it can be placed anywhere.

A typical JavaScript Device Detection code block will look something like this, but customized for your account:

<script src="//dcs.netbiscuits.net/ds/detect/js/account/[account_name]/profile/default/jsprofile/mytoken/token/[token]"></script>
<script>
    // DD init
    var dd = dd || undefined;
    if (dd !== undefined) {
        dd.dynamic.init({
            callback: customCallback
        });
    }
    // DD custom callback (optional)
    function customCallback() {
        // create a custom callback function here, if you need it
    }
</script>

With the script block added, the following events will happen when a user’s browser requests a page from your website:

  • The browser encounters the Device Detection script block and requests the Device Detection JavaScript file from a Netbiscuits Device Detection server.
  • The Device Detection server runs a series of tests to identify the user’s device.
  • A collection of parameters and values is created and returned to the user’s device in JSON format.
  • The Device Detection JavaScript can also (optionally) gather dynamic data within the user’s browser, like current Bandwidth and Geolocation. (Learn more about using using Dynamic Parameters.)
  • Once complete, the Device Detection object can be used to customize the user’s experience for the exact device they are using.

How can I use JavaScript Device Detection?

  1. First of all, make sure you’ve created a Netbiscuits account and have logged in.
  2. If you’re all set there, then you need the JavaScript code block. The Device Detection code generator allows you to configure your code block before copying it to your clipboard.
  3. Once copied, paste that code block into any pages on which you want to use Device Detection. The earlier in your HTML you add this code block, the sooner you can use it, but it can be placed anywhere.
  4. Load any page into which you’ve included the Device Detection JavaScript code block.
  5. Copy and paste the following into your favorite browser developer console:
    console.log(dd.devicetype);
    console.log(dd.vendor);
    console.log(dd.model);
    console.log(dd.touch);
    console.log(dd.svg);
    console.log(dd.positionfixed);
    
  6. Similar code can now be used anywhere in your website’s code, as long as it is after the Device Detection code block.

Demos

To help you further with getting started, we have created a series of demos that you can download and run on your own server (including your localhost).

We hope this has helped you get up and running with the Netbiscuits JavaScript Device Detection. If you have any questions or need help with your setup, please contact us.

Or if you’re ready for the next step, find out about all the Device Detection Parameters you can build into your website!

Learn more about Device Detection Parameters

YouTube aktivieren?

Auf dieser Seite gibt es mind. ein YouTube Video. Cookies für diese Website wurden abgelehnt. Dadurch können keine YouTube Videos mehr angezeigt werden, weil YouTube ohne Cookies und Tracking Mechanismen nicht funktioniert. Willst du YouTube dennoch freischalten?