Willy Tarreau | 29b2531 | 2016-11-08 14:57:29 +0100 | [diff] [blame] | 1 | 51Degrees Device Detection |
| 2 | -------------------------- |
| 3 | |
| 4 | You can also include 51Degrees for inbuilt device detection enabling attributes |
| 5 | such as screen size (physical & pixels), supported input methods, release date, |
| 6 | hardware vendor and model, browser information, and device price among many |
| 7 | others. Such information can be used to improve the user experience of a web |
| 8 | site by tailoring the page content, layout and business processes to the |
| 9 | precise characteristics of the device. Such customisations improve profit by |
| 10 | making it easier for customers to get to the information or services they |
| 11 | need. Attributes of the device making a web request can be added to HTTP |
| 12 | headers as configurable parameters. |
| 13 | |
| 14 | In order to enable 51Degrees download the 51Degrees source code from the |
Dragan Dosen | 16586e6 | 2017-09-27 12:55:07 +0200 | [diff] [blame] | 15 | official 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 | |
Dragan Dosen | a9800a0 | 2022-02-14 13:05:45 +0100 | [diff] [blame] | 22 | - use newer 3.2.12.12 version which continues to receive database |
Dragan Dosen | 16586e6 | 2017-09-27 12:55:07 +0200 | [diff] [blame] | 23 | updates and supports a new Hash Trie algorithm, but which is not |
| 24 | compatible with older Trie databases : |
Willy Tarreau | 29b2531 | 2016-11-08 14:57:29 +0100 | [diff] [blame] | 25 | |
Ben51Degrees | 636e6af | 2017-10-05 19:54:18 +0100 | [diff] [blame] | 26 | git clone https://github.com/51Degrees/Device-Detection.git -b v3.2.12 |
Willy Tarreau | 29b2531 | 2016-11-08 14:57:29 +0100 | [diff] [blame] | 27 | |
Dragan Dosen | a9800a0 | 2022-02-14 13:05:45 +0100 | [diff] [blame] | 28 | - or use the latest 51Degrees version 4 with 51Degrees Hash algorithm, |
| 29 | not compatible with older databases : |
Willy Tarreau | 29b2531 | 2016-11-08 14:57:29 +0100 | [diff] [blame] | 30 | |
Dragan Dosen | a9800a0 | 2022-02-14 13:05:45 +0100 | [diff] [blame] | 31 | git clone --recurse-submodules https://github.com/51Degrees/device-detection-cxx.git |
| 32 | |
Willy Tarreau | 3f2803e | 2022-12-21 18:54:36 +0100 | [diff] [blame] | 33 | then run 'make' with USE_51DEGREES, optionally 51DEGREES_VER=4 (if using |
| 34 | 51Degrees version 4), and 51DEGREES_SRC set. Both 51DEGREES_INC and |
| 35 | 51DEGREES_LIB may additionally be used to force specific different paths for |
| 36 | .o and .h, but will default to 51DEGREES_SRC. Make sure to replace |
| 37 | '51D_REPO_PATH' with the path to the 51Degrees repository. |
Dragan Dosen | a9800a0 | 2022-02-14 13:05:45 +0100 | [diff] [blame] | 38 | |
| 39 | 51Degrees provide 4 different detection algorithms: |
Willy Tarreau | 29b2531 | 2016-11-08 14:57:29 +0100 | [diff] [blame] | 40 | |
| 41 | 1. Pattern - balances main memory usage and CPU. |
| 42 | 2. Trie - a very high performance detection solution which uses more main |
| 43 | memory than Pattern. |
Ben51Degrees | 636e6af | 2017-10-05 19:54:18 +0100 | [diff] [blame] | 44 | 3. Hash Trie - replaces Trie, 3x faster, 80% lower memory consumption and |
| 45 | tuning options. |
Dragan Dosen | a9800a0 | 2022-02-14 13:05:45 +0100 | [diff] [blame] | 46 | 4. 51Degrees V4 Hash - only with 51Degrees Device Detection V4. |
Willy Tarreau | 29b2531 | 2016-11-08 14:57:29 +0100 | [diff] [blame] | 47 | |
| 48 | To make with 51Degrees Pattern algorithm use the following command line. |
| 49 | |
| 50 | $ make TARGET=<target> USE_51DEGREES=1 51DEGREES_SRC='51D_REPO_PATH'/src/pattern |
| 51 | |
| 52 | To use the 51Degrees Trie algorithm use the following command line. |
| 53 | |
| 54 | $ make TARGET=<target> USE_51DEGREES=1 51DEGREES_SRC='51D_REPO_PATH'/src/trie |
| 55 | |
Dragan Dosen | a9800a0 | 2022-02-14 13:05:45 +0100 | [diff] [blame] | 56 | To build with the 51Degrees Device Detection V4 use the following command line. |
| 57 | |
Willy Tarreau | 3f2803e | 2022-12-21 18:54:36 +0100 | [diff] [blame] | 58 | $ make TARGET=<target> USE_51DEGREES=1 51DEGREES_VER=4 51DEGREES_SRC='51D_REPO_PATH'/src |
Dragan Dosen | a9800a0 | 2022-02-14 13:05:45 +0100 | [diff] [blame] | 59 | |
Willy Tarreau | 29b2531 | 2016-11-08 14:57:29 +0100 | [diff] [blame] | 60 | A data file containing information about devices, browsers, operating systems |
| 61 | and their associated signatures is then needed. 51Degrees provide a free |
| 62 | database with Github repo for this purpose. These free data files are located |
| 63 | in '51D_REPO_PATH'/data with the extensions .dat for Pattern data and .trie for |
Ben51Degrees | 636e6af | 2017-10-05 19:54:18 +0100 | [diff] [blame] | 64 | Trie data. Free Hash Trie data file can be obtained by signing up for a licence |
| 65 | key at https://51degrees.com/products/store/on-premise-device-detection. |
Dragan Dosen | a9800a0 | 2022-02-14 13:05:45 +0100 | [diff] [blame] | 66 | If using the 51degrees version 4, the free hash data file is located in |
| 67 | '51D_REPO_PATH'/device-detection-data with the .hash extension. |
Ben51Degrees | 636e6af | 2017-10-05 19:54:18 +0100 | [diff] [blame] | 68 | |
Ben51Degrees | 31c3d51 | 2019-06-12 15:42:53 +0100 | [diff] [blame] | 69 | For HAProxy developers who need to verify that their changes didn't affect the |
Willy Tarreau | 977209d | 2021-04-02 16:12:32 +0200 | [diff] [blame] | 70 | 51Degrees implementation, a dummy library is provided in the |
| 71 | "addons/51degrees/dummy" directory. This does not function, but implements the |
| 72 | API such that the 51Degrees module can be used (but not return any meaningful |
Dragan Dosen | a9800a0 | 2022-02-14 13:05:45 +0100 | [diff] [blame] | 73 | information). To test either Pattern or Hash Trie, or the 51Degrees version 4 |
| 74 | Hash algorithm, build with: |
Willy Tarreau | 5e4c500 | 2019-06-13 15:56:10 +0200 | [diff] [blame] | 75 | |
Willy Tarreau | 977209d | 2021-04-02 16:12:32 +0200 | [diff] [blame] | 76 | $ make TARGET=<target> USE_51DEGREES=1 51DEGREES_SRC=addons/51degrees/dummy/pattern |
Ben51Degrees | 31c3d51 | 2019-06-12 15:42:53 +0100 | [diff] [blame] | 77 | or |
Willy Tarreau | 977209d | 2021-04-02 16:12:32 +0200 | [diff] [blame] | 78 | $ make TARGET=<target> USE_51DEGREES=1 51DEGREES_SRC=addons/51degrees/dummy/trie |
Dragan Dosen | a9800a0 | 2022-02-14 13:05:45 +0100 | [diff] [blame] | 79 | or |
Willy Tarreau | 3f2803e | 2022-12-21 18:54:36 +0100 | [diff] [blame] | 80 | $ make TARGET=<target> USE_51DEGREES=1 51DEGREES_VER=4 51DEGREES_SRC=addons/51degrees/dummy/v4hash |
Willy Tarreau | 5e4c500 | 2019-06-13 15:56:10 +0200 | [diff] [blame] | 81 | |
Ben51Degrees | 31c3d51 | 2019-06-12 15:42:53 +0100 | [diff] [blame] | 82 | respectively. |
Willy Tarreau | 29b2531 | 2016-11-08 14:57:29 +0100 | [diff] [blame] | 83 | |
| 84 | The configuration file needs to set the following parameters: |
| 85 | |
| 86 | global |
Dragan Dosen | a9800a0 | 2022-02-14 13:05:45 +0100 | [diff] [blame] | 87 | 51degrees-data-file path to the Pattern, Trie or V4 Hash data file |
Willy Tarreau | 29b2531 | 2016-11-08 14:57:29 +0100 | [diff] [blame] | 88 | 51degrees-property-name-list list of 51Degrees properties to detect |
| 89 | 51degrees-property-separator separator to use between values |
| 90 | 51degrees-cache-size LRU-based cache size (disabled by default) |
| 91 | |
| 92 | The following is an example of the settings for Pattern. |
| 93 | |
| 94 | global |
| 95 | 51degrees-data-file '51D_REPO_PATH'/data/51Degrees-LiteV3.2.dat |
| 96 | 51degrees-property-name-list IsTablet DeviceType IsMobile |
| 97 | 51degrees-property-separator , |
| 98 | 51degrees-cache-size 10000 |
| 99 | |
| 100 | HAProxy needs a way to pass device information to the backend servers. This is |
| 101 | done by using the 51d converter or fetch method, which intercepts the HTTP |
| 102 | headers and creates some new headers. This is controlled in the frontend |
| 103 | http-in section. |
| 104 | |
| 105 | The following is an example which adds two new HTTP headers prefixed X-51D- |
| 106 | |
| 107 | frontend http-in |
| 108 | bind *:8081 |
| 109 | default_backend servers |
| 110 | http-request set-header X-51D-DeviceTypeMobileTablet %[51d.all(DeviceType,IsMobile,IsTablet)] |
| 111 | http-request set-header X-51D-Tablet %[51d.all(IsTablet)] |
| 112 | |
| 113 | Here, two headers are created with 51Degrees data, X-51D-DeviceTypeMobileTablet |
| 114 | and X-51D-Tablet. Any number of headers can be created this way and can be |
| 115 | named anything. 51d.all( ) invokes the 51degrees fetch. It can be passed up to |
| 116 | five property names of values to return. Values will be returned in the same |
Joseph Herlant | 71b4b15 | 2018-11-13 16:55:16 -0800 | [diff] [blame] | 117 | order, separated by the 51-degrees-property-separator configured earlier. If a |
Willy Tarreau | 29b2531 | 2016-11-08 14:57:29 +0100 | [diff] [blame] | 118 | property name can't be found the value 'NoData' is returned instead. |
| 119 | |
| 120 | In addition to the device properties three additional properties related to the |
| 121 | validity of the result can be returned when used with the Pattern method. The |
| 122 | following example shows how Method, Difference and Rank could be included as one |
| 123 | new HTTP header X-51D-Stats. |
| 124 | |
| 125 | frontend http-in |
| 126 | ... |
| 127 | http-request set-header X-51D-Stats %[51d.all(Method,Difference,Rank)] |
| 128 | |
| 129 | These values indicate how confident 51Degrees is in the result that that was |
| 130 | returned. More information is available on the 51Degrees web site at: |
| 131 | |
| 132 | https://51degrees.com/support/documentation/pattern |
| 133 | |
| 134 | The above 51d.all fetch method uses all available HTTP headers for detection. A |
| 135 | modest performance improvement can be obtained by only passing one HTTP header |
| 136 | to the detection method with the 51d.single converter. The following example |
| 137 | uses the User-Agent HTTP header only for detection. |
| 138 | |
| 139 | frontend http-in |
| 140 | ... |
| 141 | http-request set-header X-51D-DeviceTypeMobileTablet %[req.fhdr(User-Agent),51d.single(DeviceType,IsMobile,IsTablet)] |
| 142 | |
| 143 | Any HTTP header could be used inplace of User-Agent by changing the parameter |
| 144 | provided to req.fhdr. |
| 145 | |
| 146 | When compiled to use the Trie detection method the trie format data file needs |
| 147 | to be provided. Changing the extension of the data file from dat to trie will |
| 148 | use the correct data. |
| 149 | |
| 150 | global |
| 151 | 51degrees-data-file '51D_REPO_PATH'/data/51Degrees-LiteV3.2.trie |
| 152 | |
| 153 | When used with Trie the Method, Difference and Rank properties are not |
| 154 | available. |
| 155 | |
Dragan Dosen | a9800a0 | 2022-02-14 13:05:45 +0100 | [diff] [blame] | 156 | When using the 51Degrees V4 Hash algorithm, the hash format data file needs |
| 157 | to be provided as in the following example. |
| 158 | |
| 159 | global |
| 160 | 51degrees-data-file '51D_REPO_PATH'/device-detection-data/51Degrees-LiteV4.1.hash |
| 161 | |
Willy Tarreau | 29b2531 | 2016-11-08 14:57:29 +0100 | [diff] [blame] | 162 | The free Lite data file contains information about screen size in pixels and |
| 163 | whether the device is a mobile. A full list of available properties is located |
| 164 | on the 51Degrees web site at: |
| 165 | |
| 166 | https://51degrees.com/resources/property-dictionary |
| 167 | |
| 168 | Some properties are only available in the paid for Premium and Enterprise |
| 169 | versions of 51Degrees. These data sets not only contain more properties but |
| 170 | are updated weekly and daily and contain signatures for 100,000s of different |
| 171 | device combinations. For more information see the data options comparison web |
| 172 | page: |
| 173 | |
| 174 | https://51degrees.com/compare-data-options |