Improve your users' overall experience by following these guides for add-on design.
General best practices
You are encouraged to follow the following best practices for all add-ons you develop.
Determine add-on ownership before starting
Add-ons are defined by Apps Script projects, which must be owned by a specific account or else placed in a shared drive. Before coding an add-on, determine what account should own the project, and what account acts as its publisher. Also determine what accounts are to act as collaborators, and make sure those accounts have access to the script project and its associated Cloud platform project.
Extend G Suite, don't replicate it
Add-ons are meant to provide new capabilities to the G Suite applications they extend, or else automate complex tasks. Add-ons that merely replicate functionality already within the application or ones that don't make significant improvements to a workflow aren't likely to pass add-on review for publication.
Avoid relying too much on libraries
Using Apps Script libraries can cause your add-on to run more slowly than it would if all the Apps Script code were contained within a single script project. Although Apps Script libraries work in add-ons, you may run into performance reductions if you use them. Avoid including unnecessary libraries in your project, and consider ways to reduce your add-on's reliance on them.
G Suite add-on best practices
The following best practices only apply to G Suite add-ons and the use of the Card service.
Use just a few cards
If the add-on uses too many cards the navigation configuration becomes complex and difficult to manage.
Avoid the impulse to create more cards than necessary.
Use widget creation functions
When writing code that creates
or other complex UI objects, consider putting that code in its own function.
This creation function should just build the object and return it. This lets
you quickly regenerate that object whenever the UI must be refreshed. Remember
build() after using the builder classes in the
Keep cards simple
If a given card has too many widgets, it can fill too much of the screen and become less useful. While large card sections render as collapsible UI elements, this hides information from the user. Aim to streamline your add-on and provide exactly what the user needs and no more.
Use error cards
Create cards for error conditions. If your add-on produces an error, it should display a card with the error information and instructions on how to correct it if possible. For example, if your add-on could not connect to a non-Google service because the authorization failed, display a card stating this and ask the user to verify the account information being used.
Write tests and test messages
You should thoroughly test all the add-ons you create. Build test functions that create cards and widgets using test data, and then verify that the objects are created as expected.
When using action callback functions, you usually must construct a response object. You can use statements like the following to verify that the responses are being constructed correctly:
Run test functions you create directly from the Apps Script editor using the Run menu. When you have a viable add-on working, be sure to install the unpublished version so you can test it in the Gmail UI.
Use test data appropriate for each host application the add-on extends. For example, if the add-on extends Gmail you are likely to need a few test emails and their message IDs so that you can ensure that the add-on functions as expected when given different message content. You can get the message ID for a given message by listing messages using the Gmail API Users.messages.list method, or by making use of Apps Script's Gmail service.
Interim development practices
G Suite add-ons can only extend Gmail, Calendar, and Drive currently, but you may want to start building cards for other host applications. If you’d like to eventually make your add-on available elsewhere (for example, in Google Sheets), you can build the add-on's cards and preview them in Gmail. The common add-on homepage will have the same appearance and behavior in future G Suite hosts.
Contextual triggering for Calendar events and Drive files aren't yet supported.
You also can't yet read the active document in Docs, Sheets, Forms, and Slides
(for example, using
in a G Suite add-on isn't supported yet). While these features are being
developed for G Suite Add-ons, you can hardcode any required document ID, event
ID, or spreadsheet range selection.