Use PERL code like...
use FiftyOneDegrees::PatternV3; my $provider = new FiftyOneDegrees::PatternV3::Provider($filename); my $match = $provider->getMatch($httpHeaders); print "IsMobile: " . $match->getValue("IsMobile") . "\r\n"; print "DeviceType: " . $match->getValue("DeviceType") . "\r\n";
... to turn User-Agent HTTP headers into useful information about physical screen size, device price and type of device.
[Review All Properties](https://51degrees.com/resources/property-dictionary?utm_source=github&utm_medium=repository&utm_content=home-cta&utm_campaign=perl-open-source" View all available properties and values")
Use this project to detect device properties using HTTP browser User-Agents as input. It can be used to process server web log files, or for real time device detection to support web optimisation.
Two detection methods are supported.
Pattern: Searches for device signatures in a useragent returning metrics about the validity of the results. Does NOT use regular expressions.
Trie: A large binary Trie (pronounced Try) populated with User-Agent signatures. Very fast.
All methods use an external data file which can easilly be updated.
For Ubuntu based distributions these can be found on apt, use
$ sudo apt-get update $ sudo apt-get install make perl g++ swig
To use the examples the JSON and a simple web server need to be available. Use
$ sudo apt-get install libjson-perl $ sudo perl -MCPAN -e shell > install HTTP::Server::Simple::CGI > install String::Buffer
To install, go to the directory for your chosen detection method (i.e. Pattern or Trie) with
$ cd Device-Detection/perl/[package name]
Then install with
$ perl Makefile.PL $ sudo make install
To check everything is set up correctly, try running the following PERL script.
use FiftyOneDegrees::PatternV3; my $filename = "path/to/51Degrees-Lite.dat" my $userAgent = "Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9B176" my $provider = new FiftyOneDegrees::PatternV3::Provider($filename); my $match = $provider->getMatch($userAgent); print "IsMobile: " . $match->getValue("IsMobile") . "\r\n"; print "DeviceType: " . $match->getValue("DeviceType") . "\r\n";
In the examples folder, you can find examples of various functionalities that the 51Degrees detector has such as:
- Matching with a User-Agent
- Matching with a device id
- Evaluating match metrics
- Offline processing
- Strongly typed variables
- Finding profiles
A full explanation of these can be found within the files or at Perl Tutorials.
Both Pattern and Trie also contain the following examples
console.pl which takes no input and returns matches from predefined User-Agent and HTTP headers seperately. Is run with
$ perl console.pl
server.pl which runs a server at localhost:8080 by default and returns matches from the web browsers User-Agent and all relevant HTTP headers seperately. Is run with
$ perl server.pl