# DeviceAtlas Connectivity Analyser # The DeviceAtlas Connectivity Analyser is used to measure the round trip time when sending a payload of a fixed size to a client. This measures a combination of latency and bandwidth. The measured time is then used to categorize the client's current connection into low, medium or high. ### Usage ### In order to use the Connectivity Analyser into your Ruby on Rails web application, follow these steps: 1) Install the deviceatlas_connectivity_analyser gem (add a reference from Gemfile if needed). 2) (OPTIONAL) Set the checker's options through an initializer config file associated to your app. If you do not use a config file, the options will be set with the default values: - The amount of data to send to the client as part of the bandwidth measurement. Defaults to 1KB. payloadSizeBytes = 1024 - The thresholds to define the low and mid tiers. The threshold is defined in ms. Everything faster than the mid threshold is classified as high quality. lowThresholdMs = 900 mediumThresholdMs = 400 - Frequency of measurement for a given user. If the frequency is not every request then the previous results are forwarded to the destination instead of re-measuring the bandwidth for the times when measurement should not be performed. frequency = 1 3) Include the Connectivity Analyser controller helper. This will let you get an instance of ConnectivityAnalyser and use the methods to decide what actions to apply after checking the user's bandwidth. 4) Get the duration in ms and quality from your controller's methods. ### Step By Step ### #### Steps (1), (3) and (4). #### ```ruby # Your app's controller script. require 'deviceatlas_connectivity_analyser' class YourAppController < ActionController::Base # Controller helper to have access to ConnectivityAnalyser objects include Mobi::Mtld::Da::ConnectivityAnalyser::ControllerHelper def index # Get an instance of ConnectivityAnalyser connectivity_analyser = get_deviceatlas_connectivity_analyser_instance @duration_ms = connectivity_analyser.get_duration_ms @quality = connectivity_analyser.get_quality # Put your code here to use the above variables. # For example, you could generate an optimized webpage if the # quality is low. end end ``` #### Step (2). #### ```ruby # Your initializer config file. # For example: /path/to/your/project/config/initializers/deviceatlas_connectivity_analyser.rb YourApp::Application.configure do config.payloadSizeBytes = 1024 config.lowThresholdMs = 900 config.mediumThresholdMs = 400 config.frequency = 3 end ``` ```ruby # Additionally, you can also display the duration and quality from your app with # a simple .html.erb file as follows. <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>DeviceAtlas Connectivity Analyser</title> </head> <body> <h2>DeviceAtlas Connectivity Analyser</h2> <p> <strong>Duration:</strong> <%= @durationMs %>ms<br/> <strong>Quality:</strong> <%= @quality %><br/> </p> </body> </html> ``` ### Example ### The DeviceAtlas Connectivity Analyser comes with an example application, with the default values set, which you can find inside example directory. This example uses DeviceAtlas Connectivity Analyser to find out the quality of user's network, then based on the quality an appropriate photo is selected and shown to the user. There are three photos with different size and jpeg compression ratio, therefore different file size. The given example contains the basic files you would need to use this application from a Ruby on Rails project. Once the gem is installed and controllers, viewers and assets are placed in the respective folders from your Rails server, the example app will be ready to be checked from your browser. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - _ Copyright (c) DeviceAtlas Limited 2021. All Rights Reserved. _ https://deviceatlas.com <!-- HTML+JS for document formatting when opened in browser --> <div class="btn-group" id="main-menu" style="float:right"><a class="btn dropdown-toggle" data-toggle="dropdown" href="#">Menu<span class="caret"></span></a><ul class="dropdown-menu"><li><a href="README.html">Main</a></li><li><a href="README.DeviceApi-Web.html">Device Detection for Web</a></li><li><a href="README.DeviceApi-Apps.html">Device Detection for Apps</a></li><li><a href="README.DeviceApi-Config.html">Device Detection API Config</a></li><li><a href="README.Upgrade.html">Device Detection API Upgrade</a></li><li><a href="./ApiDocs/DeviceAtlas/Device/DeviceApi.html">Device API Docs</a></li><li class="divider"></li><li><a href="README.CarrierApi.html">Carrier Identification API</a></li><li><a href="./ApiDocs/DeviceAtlas/Carrier/CarrierApi.html">Carrier API Docs</a></li><li class="divider"></li><li><a href="https://docs.deviceatlas.com/apis/clientside/latest/README.ClientSide.html" target="_blank">Client-side Component</a></li><li class="disabled"><a href="README.ConnectivityAnalyser.html">Connectivity Analyser</a></li></ul></div>