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 |
| 15 | official github repository : |
| 16 | |
| 17 | git clone https://github.com/51Degrees/Device-Detection |
| 18 | |
| 19 | then run 'make' with USE_51DEGREES and 51DEGREES_SRC set. Both 51DEGREES_INC |
| 20 | and 51DEGREES_LIB may additionally be used to force specific different paths |
| 21 | for .o and .h, but will default to 51DEGREES_SRC. Make sure to replace |
| 22 | '51D_REPO_PATH' with the path to the 51Degrees repository. |
| 23 | |
| 24 | 51Degrees provide 2 different detection algorithms: |
| 25 | |
| 26 | 1. Pattern - balances main memory usage and CPU. |
| 27 | 2. Trie - a very high performance detection solution which uses more main |
| 28 | memory than Pattern. |
| 29 | |
| 30 | To make with 51Degrees Pattern algorithm use the following command line. |
| 31 | |
| 32 | $ make TARGET=<target> USE_51DEGREES=1 51DEGREES_SRC='51D_REPO_PATH'/src/pattern |
| 33 | |
| 34 | To use the 51Degrees Trie algorithm use the following command line. |
| 35 | |
| 36 | $ make TARGET=<target> USE_51DEGREES=1 51DEGREES_SRC='51D_REPO_PATH'/src/trie |
| 37 | |
| 38 | A data file containing information about devices, browsers, operating systems |
| 39 | and their associated signatures is then needed. 51Degrees provide a free |
| 40 | database with Github repo for this purpose. These free data files are located |
| 41 | in '51D_REPO_PATH'/data with the extensions .dat for Pattern data and .trie for |
| 42 | Trie data. |
| 43 | |
| 44 | The configuration file needs to set the following parameters: |
| 45 | |
| 46 | global |
| 47 | 51degrees-data-file path to the Pattern or Trie data file |
| 48 | 51degrees-property-name-list list of 51Degrees properties to detect |
| 49 | 51degrees-property-separator separator to use between values |
| 50 | 51degrees-cache-size LRU-based cache size (disabled by default) |
| 51 | |
| 52 | The following is an example of the settings for Pattern. |
| 53 | |
| 54 | global |
| 55 | 51degrees-data-file '51D_REPO_PATH'/data/51Degrees-LiteV3.2.dat |
| 56 | 51degrees-property-name-list IsTablet DeviceType IsMobile |
| 57 | 51degrees-property-separator , |
| 58 | 51degrees-cache-size 10000 |
| 59 | |
| 60 | HAProxy needs a way to pass device information to the backend servers. This is |
| 61 | done by using the 51d converter or fetch method, which intercepts the HTTP |
| 62 | headers and creates some new headers. This is controlled in the frontend |
| 63 | http-in section. |
| 64 | |
| 65 | The following is an example which adds two new HTTP headers prefixed X-51D- |
| 66 | |
| 67 | frontend http-in |
| 68 | bind *:8081 |
| 69 | default_backend servers |
| 70 | http-request set-header X-51D-DeviceTypeMobileTablet %[51d.all(DeviceType,IsMobile,IsTablet)] |
| 71 | http-request set-header X-51D-Tablet %[51d.all(IsTablet)] |
| 72 | |
| 73 | Here, two headers are created with 51Degrees data, X-51D-DeviceTypeMobileTablet |
| 74 | and X-51D-Tablet. Any number of headers can be created this way and can be |
| 75 | named anything. 51d.all( ) invokes the 51degrees fetch. It can be passed up to |
| 76 | five property names of values to return. Values will be returned in the same |
| 77 | order, seperated by the 51-degrees-property-separator configured earlier. If a |
| 78 | property name can't be found the value 'NoData' is returned instead. |
| 79 | |
| 80 | In addition to the device properties three additional properties related to the |
| 81 | validity of the result can be returned when used with the Pattern method. The |
| 82 | following example shows how Method, Difference and Rank could be included as one |
| 83 | new HTTP header X-51D-Stats. |
| 84 | |
| 85 | frontend http-in |
| 86 | ... |
| 87 | http-request set-header X-51D-Stats %[51d.all(Method,Difference,Rank)] |
| 88 | |
| 89 | These values indicate how confident 51Degrees is in the result that that was |
| 90 | returned. More information is available on the 51Degrees web site at: |
| 91 | |
| 92 | https://51degrees.com/support/documentation/pattern |
| 93 | |
| 94 | The above 51d.all fetch method uses all available HTTP headers for detection. A |
| 95 | modest performance improvement can be obtained by only passing one HTTP header |
| 96 | to the detection method with the 51d.single converter. The following example |
| 97 | uses the User-Agent HTTP header only for detection. |
| 98 | |
| 99 | frontend http-in |
| 100 | ... |
| 101 | http-request set-header X-51D-DeviceTypeMobileTablet %[req.fhdr(User-Agent),51d.single(DeviceType,IsMobile,IsTablet)] |
| 102 | |
| 103 | Any HTTP header could be used inplace of User-Agent by changing the parameter |
| 104 | provided to req.fhdr. |
| 105 | |
| 106 | When compiled to use the Trie detection method the trie format data file needs |
| 107 | to be provided. Changing the extension of the data file from dat to trie will |
| 108 | use the correct data. |
| 109 | |
| 110 | global |
| 111 | 51degrees-data-file '51D_REPO_PATH'/data/51Degrees-LiteV3.2.trie |
| 112 | |
| 113 | When used with Trie the Method, Difference and Rank properties are not |
| 114 | available. |
| 115 | |
| 116 | The free Lite data file contains information about screen size in pixels and |
| 117 | whether the device is a mobile. A full list of available properties is located |
| 118 | on the 51Degrees web site at: |
| 119 | |
| 120 | https://51degrees.com/resources/property-dictionary |
| 121 | |
| 122 | Some properties are only available in the paid for Premium and Enterprise |
| 123 | versions of 51Degrees. These data sets not only contain more properties but |
| 124 | are updated weekly and daily and contain signatures for 100,000s of different |
| 125 | device combinations. For more information see the data options comparison web |
| 126 | page: |
| 127 | |
| 128 | https://51degrees.com/compare-data-options |