This example shows how to return Javascript to obtain further evidence for 51Degrees' on-premise device detection in Nginx. This example is available in full on GitHub.
This example requires a local data file. The free 'Lite' data file can be acquired by pulling the git submodules under this repository (run `git submodule update --recursive`) or from the device-detection-data GitHub repository.
The Lite data file is only used for illustration, and has limited accuracy and capabilities. Find out about the more capable data files that are available on our pricing page
Properties required for this example are not included in the free Lite file, so a data file that includes ScreenPixelsWidth and ScreenPixelsWidthJavascript need to be obtained from configurator.
Before using the example, update the followings:
- Remove this 'how to' guide block.
- Update the file path specifed in
51D_file_path
with the actual file path. - Replace the nginx.conf with this file or run Nginx with
-c
option pointing to this file. - Create a static file
overrides
in the Nginxdocument_root
.
In a Linux environment, once Nginx has started, open the index.html in a browser.
The index.html
send a request to the /51D.js
endpoint to obtain the javascript and execute it as below:
Then use the obtained screen pixels width to send back to the /overrides
endpoint. The full details can be seen in the index.html
.
The Javascript can be seen by running the below command.
Expected display after open the index.html
in the browser is:
The number should be the screen pixels width of your machine.
NOTE
: All the lines above, this line and the end of comment block line after this line should be removed before using this example.