
This add-on is operated by Expedited Security
Boost User Agent identification with our always up to date UA parsing
User Agent Identifier
Last updated July 28, 2023
This article is a work in progress, or documents a feature that is not yet released to all users. This article is unlisted. Only those with the link can access it.
The User Agent Identifier add-on is currently in beta.
Table of Contents
User Agent Identifier is an add-on to simplify User Agent Identification with our continuously updated user agent parsing library.
As automated bots, mobile devices and desktop browsers have exploded into a thousand different forms, it is really difficult to accurately determine just what a given user-agent represents and even more difficult to aggregate that raw information.
We do the heavy lifting for you by maintaining an always up to date database containing the latest user-agents and bot signatures. Additionally, the service collates that into easily accessible high level categories:
- is_mobile
- is_ios
- is_android
- os_family
Know instantly if a particular user is mobile, iOS, Android and what family of operating system they are using.
User Agent Identifier exposes an API and has supported examples for Ruby, PHP, Python, Node and Java.
Provisioning the add-on
User Agent Identifier can be attached to a Heroku application via the CLI:
A list of all plans available can be found here.
$ heroku addons:create useragentidentifier
-----> Adding useragentidentifier to sharp-mountain-4005... done, v18 (free)
Once User Agent Identifier has been added a USERAGENTIDENTIFIER_API_KEY
config variable will contain your specific API key granting access to the newly provisioned User Agent Identifier instance. This can be confirmed using the heroku config:get
command.
$ heroku config:get USERAGENTIDENTIFIER_API_KEY
Bl4XHVbdsf5GIXQbqTfXR5IrpuuXER2kaVc2zNnA
After installing User Agent Identifier your application should be modified to fully integrate with the add-on.
Local setup
Environment setup
After provisioning the add-on it’s necessary to locally replicate the config vars so your development environment can operate against the service.
Use the Heroku Local command-line tool to configure, run and manage process types specified in your app’s Procfile. Heroku Local reads configuration variables from a .env
file. To view all of your app’s config vars, type heroku config
. Use the following command for each value that you want to add to your .env
file.
$ heroku config:get USERAGENTIDENTIFIER_API_KEY -s >> .env
Credentials and other sensitive configuration values should not be committed to source-control. In Git exclude the .env
file with: echo .env >> .gitignore
.
For more information, see the Heroku Local article.
Input Parameter Descriptions
All languages will follow this call structure for inputs.
Index | Name | Example | Description |
---|---|---|---|
0 | user_agent |
string | A user-agent string |
Using with Ruby
Install the User-Agent-Identifier gem.
# In your Gemfile
gem 'useragentidentifier', git: 'https://github.com/mbuckbee/User-Agent-Identifier-Gem.git'
Making a Request
> require 'user_agent_identifier'
# Note: the 'Controller' here is not a reference to Rails controllers
# but an internal structure, won't interfere with your Rails app and will
# work fine in a standalone ruby app or another framework
> uae = UserAgentIdentifier::APIController.new
> result = uae.lookup("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36")
Using Results
> result.type
=> "desktop-browser"
> result.is_mobile
=> false
> result.is_android
=> false
> result.is_ios
=> false
> result.mobile_brand
=> ""
> result.mobile_browser
=> ""
> result.mobile_model
=> ""
> result.mobile_screen_width
=> 0
> result.mobile_screen_height
=> 0
> result.browser_name
=> "Chrome"
> result.operating_system
=> "OS X"
> result.operating_system_family
=> "OS X"
> result.producer
=> "Google Inc."
> result.version
=> "50.0.2661.102"
Using with PHP
<?php
$ch = curl_init('https://useragentidentifier.expeditedaddons.com/?api_key=' . getenv('USERAGENTIDENTIFIER_API_KEY') . '&user_agent=Mozilla');
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
Using with Python
import os
from urllib2 import Request, urlopen
request = Request('https://useragentidentifier.expeditedaddons.com/?api_key=' + os.environ['USERAGENTIDENTIFIER_API_KEY'] + '&user_agent=Mozilla')
response_body = urlopen(request).read()
print response_body
Using with Node
var request = require('request');
request('https://useragentidentifier.expeditedaddons.com/?api_key=' + process.env.USERAGENTIDENTIFIER_API_KEY + '&user_agent=Mozilla', function (error, response, body) {
console.log('Status:', response.statusCode);
console.log('Headers:', JSON.stringify(response.headers));
console.log('Response:', body);
});
Using with Java
// Maven : Add these dependencies to your pom.xml (java6+)
// <dependency>
// <groupId>org.glassfish.jersey.core</groupId>
// <artifactId>jersey-client</artifactId>
// <version>2.8</version>
// </dependency>
// <dependency>
// <groupId>org.glassfish.jersey.media</groupId>
// <artifactId>jersey-media-json-jackson</artifactId>
// <version>2.8</version>
// </dependency>
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.MediaType;
Client client = ClientBuilder.newClient();
Response response = client.target('https://useragentidentifier.expeditedaddons.com/?api_key=' + System.getenv('USERAGENTIDENTIFIER_API_KEY') + '&user_agent=Mozilla}')
.request(MediaType.TEXT_PLAIN_TYPE)
.get();
System.out.println("status: " + response.getStatus());
System.out.println("headers: " + response.getHeaders());
System.out.println("body:" + response.readEntity(String.class));
Result Field Descriptions
Attribute | Type | Description |
---|---|---|
type |
string | The user-agent type, possible values are: desktop-browser, email-client, feed-reader, software-library, media-player, mobile-browser, robot, unknown |
is_mobile |
boolean | True if this is a mobile user-agent |
is_android |
boolean | True if this is an Android based mobile user-agent |
is_ios |
boolean | True if this is an iOS based mobile user-agent |
mobile_brand |
string | Mobile device brand |
mobile_browser |
string | Mobile device browser name (this is usually the same as the browser name) |
mobile_model |
string | Mobile device model |
mobile_screen_width |
integer | Mobile device screen width (in px) |
mobile_screen_height |
integer | Mobile device screen height (in px) |
browser_name |
string | Browser software name |
operating_system |
string | The full operating system name which may include the major version number and code name |
operating_system_family |
string | The operating system family name, that is the OS name without any version or code names appended |
operating_system_version |
string | The operating system version number (if detectable) |
producer |
string | Producer or manufacturer |
version |
string | User-agent software version |
Dashboard
The User Agent Identifier dashboard allows you to monitor your API usage limits.
The dashboard can be accessed via the CLI:
$ heroku addons:open useragentidentifier
Opening useragentidentifier for sharp-mountain-4005
or by visiting the Heroku Dashboard and selecting the application in question. Select User Agent Identifier from the Add-ons menu.
Troubleshooting
As a sanity check it is sometimes useful to bypass your app stack and check the endpoint, your API Key and parameters directly.
Test with your browser
# Modify the following to use your actual API Key
https://useragentidentifier.expeditedaddons.com/?api_key=REPLACE_WITH_YOUR_USERAGENTIDENTIFIER_API_KEY&user_agent=Mozilla
A successful call will return your requested data with a HTTP result code of 200
along with your data. We recommend the JSON Formatter extension as a useful tool.
Your API key can be found on your User Agent Identifier dashboard.
Migrating between plans
No downtime or disruption of service will occur as you modify your plans.
Use the heroku addons:upgrade
command to migrate to a new plan.
$ heroku addons:upgrade useragentidentifier:newplan
-----> Upgrading useragentidentifier:newplan to sharp-mountain-4005... done, v18 ($49/mo)
Your plan has been updated to: useragentidentifier:newplan
Removing the add-on
User Agent Identifier can be removed via the CLI.
This will destroy all associated data, cannot be undone and will immediately block access to the API
$ heroku addons:destroy useragentidentifier
-----> Removing useragentidentifier from sharp-mountain-4005... done, v20 (free)
Support
All User Agent Identifier support and runtime issues should be submitted via one of the Heroku Support channels. Any non-support related issues or product feedback is welcome at support@expeditedaddons.com