Retrieving Website Visitor Information Using Javascript

Elliot Forbes Elliot Forbes ⏰ 1 Minutes 📅 Apr 15, 2017

In this tutorial I'll be demonstrating how you can retrieve key information about all your website visitors using a very simple javascript snippet. This could in theory be placed on all your website's pages and then returned to a REST API which then stores this information for you to analyse in the future. I thought this would be an interesting little snippet for those of you thinking of rolling your own google analytics-like tracking.

The Web Page

<html>
  <head>
    <title>Analytics Engine Test Page</title>
  </head>
  <body>
    <h1>This is my test webpage</h1>

    <script src="analytics.js"></script>
  </body>
</html>

The JavaScript File

console.log("Cookies: " + navigator.cookieEnabled);
console.log("Browser Language: " + navigator.browserLanguage);
console.log("Language: " + navigator.language);
console.log("Platform: " + navigator.platform);
console.log("Connection Speed: " + navigator.connectionSpeed);
console.log("User Agent: " + navigator.userAgent);
console.log("Webdriver: " + navigator.webdriver);
console.log("Geolocation: " + navigator.geolocation);

Conclusion

If you visit this web page in your browser of choice and open up the console, you should see just about everything you can see about yourself displayed in the console.