Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,18 @@ The report object has the following keys and value types.
"version": (string)
},
"ip": (string),
"country": {
"name": (string),
"code": (string),
"city": (string),
"latitude" : (string),
"longitude": (string),
"timezone": (string)
},
"java": {
"version": (string)
},
"lang": (array || string),
"lang": (array),
"os": {
"name": (string),
"version": (string)
Expand All @@ -75,6 +83,14 @@ The report object has the following keys and value types.
"websockets": (boolean)
}

## TypeScript Usage

import 'browser-report';

window.browserReport((error, result) => {
console.log(result.ip + ' ' + result.browser.name);
});

# Coverage

The goal is to correctly identify all browsers included on caniuse.com according to their [browser usage table][3]. As of January 18, 2017, their browser usage table accounts for 98.19% of global usage based on data from [StatCounter GlobalStats][4].
Expand Down Expand Up @@ -105,6 +121,10 @@ In chronological order (oldest first); not in order of priority.

#Change Log

*2.2.9 – June 27, 2017*
* added extended country info from freegeoip
* added typescript definition

*2.2.8 – January 18, 2017*

* added test cases for detecting Opera Mobile
Expand Down Expand Up @@ -183,7 +203,7 @@ In chronological order (oldest first); not in order of priority.
* the previous synchronous function can still be found in `browserReportSync()`
* the remote client IP address is now reported from ipify.org
* a random UUID is now generated for cookie test instead of using the same UUID every time
* report now includes the client's preferred language(s) for displaying pages
* report now includes the client's preferred languages for displaying pages
* report now includes a timestamp with the client's locale date, time and time zone

*1.0.0 — September 11, 2015*
Expand Down
56 changes: 56 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Type definitions for browser-report v2.2.9
// Project: https://github.com/JTOne123/browser-report
// Definitions by: Paul Datsiuk <https://github.com/JTOne123>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

interface Window {
browserReport(result: (error: ErrorEvent, report: ReportResult) => any): void;
browserReportSync(): ReportResult;
}

interface ReportResult {
"browser": {
"name": string,
"version": string
},
"cookies": boolean,
"flash": {
"version": string
},
"ip": string,
"country": {
"name": string,
"code": string,
"city": string,
"latitude" : string,
"longitude": string,
"timezone": string
},
"java": {
"version": string
},
"lang": Array<string>,
"os": {
"name": string,
"version": string
},
"screen": {
"colors": number,
"dppx": number,
"height": number,
"width": number
},
"scripts": boolean,
"timestamp": string,
"userAgent": string,
"viewport": {
"height": number,
"layout": {
"height": number,
"width": number
}
"width": number,
"zoom": number
}
"websockets": boolean
}
30 changes: 22 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
"version": null
},
"ip": null,
"country": {
"name": null,
"code": null,
"city": null,
"latitude" : null,
"longitude": null,
"timezone": null
},
"java": {
"version": null
},
Expand Down Expand Up @@ -459,8 +467,8 @@
report.websockets = !!window.WebSocket;


// preferred language(s) for displaying pages
report.lang = navigator.languages || navigator.language;
// preferred languages for displaying pages
report.lang = navigator.languages || [navigator.language];


// local date, time, and time zone
Expand All @@ -473,23 +481,29 @@

/*
* asynchronous version includes the remote client IP address
* uses ipify.org API
* uses freegeoip.net API
*/
window.browserReport = window.browserReport || function (callback) {
var report, newScriptTag, existingScriptTag;

report = extractDataFromClient();

// use ipify.org to get the remote client ip address
// define function to handle data from ipify.org
window.getip = window.getip || function (data) {
report.ip = data.ip;
// define function to handle data from freegeoip.net
window.geoip = window.geoip || function (geoip) {
report.ip = geoip.ip;
report.country.name = geoip.country_name;
report.country.code = geoip.country_code;
report.country.city = geoip.city;
report.country.latitude = geoip.latitude;
report.country.longitude = geoip.longitude;
report.country.timezone = geoip.time_zone;
callback(null, report);
};

// inject script tag get JSONP response from ipify.org
// inject script tag get JSONP response from freegeoip.net
newScriptTag = document.createElement("script");
newScriptTag.src = "https://api.ipify.org?format=jsonp&callback=getip";
newScriptTag.src = "https://freegeoip.net/json/?callback=geoip";
existingScriptTag = document.getElementsByTagName("script")[0];
existingScriptTag.parentNode.insertBefore(newScriptTag, existingScriptTag);

Expand Down
8 changes: 8 additions & 0 deletions sample.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ <h3>
{{screen.colors}}
</td>
</tr>
<tr>
<td>
Country info
</td>
<td>
{{country.name}} {{country.city}}
</td>
</tr>
</table>
<p class="user-agent">
Your full user agent string is:<br>
Expand Down