Find the Visitor's Browser and OS with Google Apps Script

Published in: Google Apps Script

The HTML Service of Google Apps Script lets you create HTML and JavaScript based applications that can be served as standalone web apps or they can be used for building user interfaces (like a form) contained inside Google Sheets and Google Docs.

HTML service executes JavaScripts on the client side and communicates with server side Google Apps Script functions using, an asynchronous client-side JavaScript API.

The File Upload Forms for Google Drive are built entirely with HTML service. The user visits an online web form, uploads a file to Google Drive and the form response is saved to Google Sheet. In addition to capturing user-entered data, we can also use Html Service to capture information about the visitor’s browser, their OS (Mac, Windows, etc) and their device (whether they are accessing the page from a tablet, mobile or a TV).

Here’s a sample snippet that shows how to parse the User Agent string using the ua-parser-js library. This method, however, cannot be used to find the I.P. Address of the visitor.

The server side Google Script.

function doGet() {
return HtmlService.createTemplateFromFile("index")
.setTitle("User Agent - Google Apps Script");

And the index.html file served via HTML service.

<!DOCTYPE html>
    <base target="_top">
    <div id="browser"></div>
    <div id="os"></div>
    <script src=""></script>
      var parser = new UAParser();
      parser.setUA("<?= HtmlService.getUserAgent(); ?>");
      var result = parser.getResult();
      document.getElementById("browser").textContent = + " v" + result.browser.major;
      document.getElementById("os").textContent = + " v" + result.os.version;
Published in: Google Apps Script

Looking for something? Find here!

Meet the Author

Web Geek, Google Developer Expert
Amit Agarwal

Amit Agarwal is a Google Developer Expert in Google Workspace and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India. He is the developer of Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory

Get in touch