What's Covered
51Degrees device detector returns all detection results as a string. This tutorial demonstrates how to return results for the IsMobile property value as a boolean.
Code and Explanation
Getting started example of using 51Degrees device detection. The example
shows how to:
-
Set the configuration using a json object
var config = {"dataFile" : require("fiftyonedegreeslitepattern"), "properties" : "IsMobile", "stronglyTyped" : true };
Note: stronglyTyped does not need to be set explicitly as true is the default
-
Instantiate the 51Degrees device detection provider with this
connfiguration
var provider = new fiftyonedegrees.provider(config);
-
Produce a match for a single HTTP User-Agent header
var match = provider.getMatch(userAgent);
-
Extract the value of the IsMobile property as boolean
match.IsMobile;
Summary
In this tutorial you have seen how to use the detector to retrieve the IsMobile property for a pre-defined User-Agent string. It sets a boolean value to true or false from the original string value of "True" or "False", making if statements simpler to test.