blob: 381008ae946c2f080c1dacc53846712cf9c2048e [file] [log] [blame]
Willy Tarreau29b25312016-11-08 14:57:29 +0100151Degrees Device Detection
2--------------------------
3
4You can also include 51Degrees for inbuilt device detection enabling attributes
5such as screen size (physical & pixels), supported input methods, release date,
6hardware vendor and model, browser information, and device price among many
7others. Such information can be used to improve the user experience of a web
8site by tailoring the page content, layout and business processes to the
9precise characteristics of the device. Such customisations improve profit by
10making it easier for customers to get to the information or services they
11need. Attributes of the device making a web request can be added to HTTP
12headers as configurable parameters.
13
14In order to enable 51Degrees download the 51Degrees source code from the
Dragan Dosen16586e62017-09-27 12:55:07 +020015official git repository :
16
17 - either use the proven stable but frozen 3.2.10 version which
18 supports the Trie algorithm :
19
20 git clone https://git.51Degrees.com/Device-Detection.git -b v3.2.10
21
22 - or use the new 3.2.12.12 version which continues to receive database
23 updates and supports a new Hash Trie algorithm, but which is not
24 compatible with older Trie databases :
Willy Tarreau29b25312016-11-08 14:57:29 +010025
Ben51Degrees636e6af2017-10-05 19:54:18 +010026 git clone https://github.com/51Degrees/Device-Detection.git -b v3.2.12
Willy Tarreau29b25312016-11-08 14:57:29 +010027
28then run 'make' with USE_51DEGREES and 51DEGREES_SRC set. Both 51DEGREES_INC
29and 51DEGREES_LIB may additionally be used to force specific different paths
30for .o and .h, but will default to 51DEGREES_SRC. Make sure to replace
31'51D_REPO_PATH' with the path to the 51Degrees repository.
32
Ben51Degrees636e6af2017-10-05 19:54:18 +01003351Degrees provide 3 different detection algorithms:
Willy Tarreau29b25312016-11-08 14:57:29 +010034
35 1. Pattern - balances main memory usage and CPU.
36 2. Trie - a very high performance detection solution which uses more main
37 memory than Pattern.
Ben51Degrees636e6af2017-10-05 19:54:18 +010038 3. Hash Trie - replaces Trie, 3x faster, 80% lower memory consumption and
39 tuning options.
Willy Tarreau29b25312016-11-08 14:57:29 +010040
41To make with 51Degrees Pattern algorithm use the following command line.
42
43 $ make TARGET=<target> USE_51DEGREES=1 51DEGREES_SRC='51D_REPO_PATH'/src/pattern
44
45To use the 51Degrees Trie algorithm use the following command line.
46
47 $ make TARGET=<target> USE_51DEGREES=1 51DEGREES_SRC='51D_REPO_PATH'/src/trie
48
49A data file containing information about devices, browsers, operating systems
50and their associated signatures is then needed. 51Degrees provide a free
51database with Github repo for this purpose. These free data files are located
52in '51D_REPO_PATH'/data with the extensions .dat for Pattern data and .trie for
Ben51Degrees636e6af2017-10-05 19:54:18 +010053Trie data. Free Hash Trie data file can be obtained by signing up for a licence
54key at https://51degrees.com/products/store/on-premise-device-detection.
55
Willy Tarreau29b25312016-11-08 14:57:29 +010056
57The configuration file needs to set the following parameters:
58
59 global
60 51degrees-data-file path to the Pattern or Trie data file
61 51degrees-property-name-list list of 51Degrees properties to detect
62 51degrees-property-separator separator to use between values
63 51degrees-cache-size LRU-based cache size (disabled by default)
64
65The following is an example of the settings for Pattern.
66
67 global
68 51degrees-data-file '51D_REPO_PATH'/data/51Degrees-LiteV3.2.dat
69 51degrees-property-name-list IsTablet DeviceType IsMobile
70 51degrees-property-separator ,
71 51degrees-cache-size 10000
72
73HAProxy needs a way to pass device information to the backend servers. This is
74done by using the 51d converter or fetch method, which intercepts the HTTP
75headers and creates some new headers. This is controlled in the frontend
76http-in section.
77
78The following is an example which adds two new HTTP headers prefixed X-51D-
79
80 frontend http-in
81 bind *:8081
82 default_backend servers
83 http-request set-header X-51D-DeviceTypeMobileTablet %[51d.all(DeviceType,IsMobile,IsTablet)]
84 http-request set-header X-51D-Tablet %[51d.all(IsTablet)]
85
86Here, two headers are created with 51Degrees data, X-51D-DeviceTypeMobileTablet
87and X-51D-Tablet. Any number of headers can be created this way and can be
88named anything. 51d.all( ) invokes the 51degrees fetch. It can be passed up to
89five property names of values to return. Values will be returned in the same
Joseph Herlant71b4b152018-11-13 16:55:16 -080090order, separated by the 51-degrees-property-separator configured earlier. If a
Willy Tarreau29b25312016-11-08 14:57:29 +010091property name can't be found the value 'NoData' is returned instead.
92
93In addition to the device properties three additional properties related to the
94validity of the result can be returned when used with the Pattern method. The
95following example shows how Method, Difference and Rank could be included as one
96new HTTP header X-51D-Stats.
97
98 frontend http-in
99 ...
100 http-request set-header X-51D-Stats %[51d.all(Method,Difference,Rank)]
101
102These values indicate how confident 51Degrees is in the result that that was
103returned. More information is available on the 51Degrees web site at:
104
105 https://51degrees.com/support/documentation/pattern
106
107The above 51d.all fetch method uses all available HTTP headers for detection. A
108modest performance improvement can be obtained by only passing one HTTP header
109to the detection method with the 51d.single converter. The following example
110uses the User-Agent HTTP header only for detection.
111
112 frontend http-in
113 ...
114 http-request set-header X-51D-DeviceTypeMobileTablet %[req.fhdr(User-Agent),51d.single(DeviceType,IsMobile,IsTablet)]
115
116Any HTTP header could be used inplace of User-Agent by changing the parameter
117provided to req.fhdr.
118
119When compiled to use the Trie detection method the trie format data file needs
120to be provided. Changing the extension of the data file from dat to trie will
121use the correct data.
122
123 global
124 51degrees-data-file '51D_REPO_PATH'/data/51Degrees-LiteV3.2.trie
125
126When used with Trie the Method, Difference and Rank properties are not
127available.
128
129The free Lite data file contains information about screen size in pixels and
130whether the device is a mobile. A full list of available properties is located
131on the 51Degrees web site at:
132
133 https://51degrees.com/resources/property-dictionary
134
135Some properties are only available in the paid for Premium and Enterprise
136versions of 51Degrees. These data sets not only contain more properties but
137are updated weekly and daily and contain signatures for 100,000s of different
138device combinations. For more information see the data options comparison web
139page:
140
141 https://51degrees.com/compare-data-options