When you build a script with a user interface, either via Ui Service or Html Service, you can deploy it as a web app and then embed that web app in a Google Site as a Google Apps Script gadget. For example, if you build a script that allows users to schedule appointments with members of a support team, you can deploy that script as a web app and embed it in your Google Site as a Google Apps Script gadget.
- Requirements for Google Apps Script Gadgets
- Deploying your Script as a Web App
- Embedding Your Web App in Google Sites
- Permissions and Google Apps Script Gadgets
Requirements for Google Apps Script Gadgets
In order to embed a script in Google Sites as a Google Apps Script Gadget, you must first deploy the script as a web app. Scripts that are deployed as web apps must contain the
doGet(e) function. User interfaces for web apps can be built using either the Html Service or the Ui Service (including the use of the GUI Builder). Additionally, it's easiest to use a script which is bound to your Google Site. To create a script from Google Sites, go to More > Manage site > Google Apps Scripts and then click the button to Add new script.
Before you can deploy a web app, you must save a version of your script. To do so, choose File > Manage Versions in the Script Editor, provide a description for the version, and then click Save New Version.
Deploying your Script as a Web App
Once you have created your web app and saved a version, you can deploy it from the Script Editor. Choose Publish > Deploy as web app from the menu. A dialog will appear where you will need to make three decisions about how to publish your web app:
- Project version: Which saved version do you want to publish?
- Execute the app as: Do you want the web app to execute as you (the owner of the script) or as the active user who is accessing the web app?
- Who has access to the app: The options for this select box will differ depending on the type of account you have, but they can include only yourself, any member of your domain, anyone, or anyone including allowing anonymous access.
Once you've selected the options you want to use for your web app, click the Deploy button. You'll see a new dialog with a message indicating that your project has been successfully deployed as a web app. Below that message you'll find the URL of your web app. Copy that URL and use it to access your web app in a browser or to embed it as a Google Apps Script Gadget in Google Sites.
Embedding Your Web App in Google Sites
To embed your web app in Google Sites as a Google Apps Script Gadget, follow the steps below:
- Open an existing Site for which you have edit access or create a new Site.
- Navigate to the page in your Site where you want to embed the Google Apps Script Gadget.
- Click the edit icon, and then Insert > Google Apps Script Gadget.
- Choose the script from the list that represents your web app. If your web app was created in a standalone script or is associated with another Site or a Spreadsheet, then you can paste in the web app URL instead.
- Click the Select button, choose the desired options from the next dialog, and click Save.
- Save your changes to the page and then you should see your web app embedded in your Sites page.
Permissions and Google Apps Script Gadgets
The permissions for a web app differ depending on whether you chose to execute the app as you (the owner of the script) or as the active user who is accessing the web app.
If you chose for the script to execute as you, then the script will always execute under your identity, that is, the identity of the owner of the script. This will be the case regardless of which user is accessing the web app.
If you chose for the script to execute as the active user who is accessing the web app, then the script will execute under the identity of the active user who is accessing your script.