logo

Adding a Custom Domain to Google Apps Script

O

Ohidur Rahman Bappy

MAR 22, 2025

Introduction

When deploying a Google Apps Script web app, the URL can be long and cumbersome:

https://script.google.com/macros/s/***random-id***/exec

Wouldn't it be nicer to have a clean, personalized URL like:

https://mysite.com/thing

Solution Overview

Fortunately, there’s a way to host Google Apps Script web apps on custom domains. The key is using the setXFrameOptionsMode method in the HtmlService class. By setting it to ALLOWALL, you can embed your app into any page with an iframe.

Implementation Guide

Here's how you can achieve this:

return HtmlService  
     .createTemplateFromFile('login')  
     .evaluate()  
     .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);

Implementation Steps

  1. Create Your Google Apps Script App:

    • Develop the functionality you need within your Google Apps Script project.
  2. Set setXFrameOptionsMode to ALLOWALL:

    • This allows the web app to be embedded using an iframe.
  3. Use an Iframe for Embedding:

    • You can now embed your app in any HTML page:

      <iframe src="https://script.google.com/macros/s/***random-id***/exec"></iframe>
      

Additional Benefits

  • SSL Support: Your custom domain integration will support SSL, ensuring secure data transmission.

Conclusion

With these simple steps, you can host Google Apps Script web apps under your own custom domain, enhancing accessibility and branding. The result is both functional and aesthetically pleasing.