首页
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
首页是 Google Workspace 插件的一项新功能,可让您定义一个或多个非情境卡片。非情境卡片用于在用户不在特定情境中时显示界面,例如当用户查看 Gmail 收件箱但尚未打开邮件或草稿时。
您可以在首页上显示非情境内容,就像在快捷访问侧边栏 中显示 Google 应用(Keep、日历和 Tasks)一样。首页还可以为用户首次打开您的插件提供初始起点,并有助于向新用户介绍如何与您的插件互动。
您可以通过在项目清单中指定该网页并实现一个或多个 homepageTrigger
函数来为您的插件定义首页(请参阅首页配置)。
您可以有多个首页,每个首页对应您的插件扩展的每个托管应用。您还可以选择定义一个常用的默认首页,用于未指定自定义首页的主机。
当满足以下条件之一时,系统会显示您的插件首页:
设计主页并非强制性要求,但强烈建议您这样做;如果您未定义任何主页,那么每当用户导航到主页时,系统都会使用包含您的插件名称的通用卡片。
首页配置
Google Workspace 插件使用 addOns.common.homepageTrigger
字段为插件清单中的所有托管应用配置默认首页(非情境)插件内容:
{
// ...
"addOns": {
// ...
"common": {
// ...
"homepageTrigger": {
"runFunction": "myFunction",
"enabled": true
}
}
}
}
runFunction
:Google Workspace 插件框架调用以呈现首页插件卡片的 Apps 脚本函数的名称。此函数是首页触发器函数。此函数必须构建并返回一个 Card
对象数组,该数组构成了首页界面。如果返回多个卡片,托管应用会在列表中显示卡片标题,供用户选择(请参阅返回多张卡片)。
enabled
:是否应为此范围启用首页卡片。此字段是可选字段,默认值为 true
。将此属性设置为 false
会导致为所有主机停用首页卡片(除非为该主机覆盖此设置;请参阅下文)。
除了常规配置之外,每个主机应用的配置中还提供了结构相同的每个主机替换项,位于 addOns.gmail.homepageTrigger
、addOns.calendar.homepageTrigger
等位置:
{
...
"addOns": {
...
"common": {
// By default, call 'buildHomePage' to render homepage content
// in all hosts. Since calendar.homepageTrigger below overrides
// this in Calendar and Drive and the homepageTrigger is disabled
// for Gmail, this homepage function never executes.
"homepageTrigger": { "runFunction": "buildHomePage" }
},
"calendar": {
// Show customized homepage content for Calendar only.
"homepageTrigger": { "runFunction": "buildCalendarHomepage" }
},
"drive": {
// Show customized homepage content for Drive only.
"homepageTrigger": { "runFunction": "buildDriveHomepage" }
}
"gmail": {
// Disable homepage add-on content in Gmail.
"homepageTrigger": { "enabled": false }
},
...
}
}
请注意,这与以下清单摘要等效:
{
...
"addOns": {
...
"common": { /* ... */ }, // Omitted a default homepageTrigger specification.
"calendar": {
// Show customized homepage content for Calendar only.
"homepageTrigger": { "runFunction": "myCalendarFunction" }
},
"drive": {
// Show customized homepage content for Drive only.
"homepageTrigger": { "runFunction": "myDriveFunction" }
}
"gmail": { /* ... */ },
...
}
}
所有 homepageTrigger
部分都不是必填字段。不过,在任何给定托管产品中为插件显示的界面取决于相应清单字段是否存在,以及是否存在关联的 homepageTrigger
。以下示例展示了系统会执行哪些插件触发器函数(如果有)来为不同的清单配置创建首页界面:

首页事件对象
调用时,系统会向上述首页触发器函数 (runFunction
) 传递一个包含调用上下文中数据的事件对象。
首页事件对象不包含微件或情境信息;传递的信息仅限于以下常见事件对象字段:
commonEventObject.clientPlatform
commonEventObject.hostApp
commonEventObject.userLocale
和 commonEventObject.userTimezone
(但如需了解限制信息,请参阅访问用户语言区域和时区)。
如需了解详情,请参阅事件对象。
其他非情境卡片
您的插件界面可以包含其他非情境卡片,这些卡片不是首页。例如,您的首页可能有一个按钮,用于打开“设置”卡片,用户可以在其中调整插件设置(在大多数情况下,此类设置与上下文无关,因此属于非情境设置)。
非情境卡片的构建方式与任何其他卡片一样;唯一的区别在于生成和显示卡片的操作或事件。如需详细了解如何在卡片之间创建转场效果,请参阅导航方法。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-01。
[null,null,["最后更新时间 (UTC):2025-08-01。"],[[["\u003cp\u003eHomepages in Google Workspace add-ons display non-contextual content, similar to built-in apps like Keep and Calendar, offering a starting point for users.\u003c/p\u003e\n"],["\u003cp\u003eYou can customize the homepage content by specifying a homepage trigger function in your add-on's manifest, potentially creating different homepages for each supported host application.\u003c/p\u003e\n"],["\u003cp\u003eAdd-ons can have multiple non-contextual cards, with the homepage acting as the primary entry point and other cards serving specific functions, such as settings or help.\u003c/p\u003e\n"],["\u003cp\u003eAlthough not mandatory, designing a homepage is recommended to improve the user experience, as a generic card is used otherwise.\u003c/p\u003e\n"],["\u003cp\u003eHomepage triggers are invoked without contextual information, relying on limited event object fields like client platform, host application, user locale, and timezone.\u003c/p\u003e\n"]]],["Google Workspace add-ons can utilize \"homepages,\" which are non-contextual cards displayed when users are outside a specific context or first open an add-on. Developers define homepages in the project manifest using `homepageTrigger` functions, which generate the UI. Multiple homepages can be specified for different host applications, or a default one can be used. Homepages are triggered when the add-on opens, transitions out of context, or navigates to the root. It's highly recommended to create a homepage, else a basic card is used.\n"],null,["# Homepages\n\n*Homepages* are a new Google Workspace add-ons feature\nthat provides the ability to define one or more *non-contextual cards*.\nNon-contextual cards are used to display a user interface when the user is\noutside a specific context, such as when the user is viewing their Gmail inbox\nbut hasn't opened a message or draft.\n\nHomepages let you show non-contextual content, just like the\nGoogle apps in the\n[quick-access side panel](https://workspaceupdates.googleblog.com/2018/08/use-quick-access-side-panel-to-do-more.html)\n(Keep, Calendar, and Tasks). Homepages can also provide an initial starting\nplace for when a user first opens your add-on, and are useful for teaching\nnew users how to interact with your add-on.\n\nYou can define a homepage for your add-on by specifying it in your project\nmanifest and implementing one or more `homepageTrigger` functions (see\n[Homepage configuration](#homepage_configuration)).\n\nYou can have multiple homepages, one for each host application that your add-on\nextends. You can also decide to define a single common default homepage that is\nused in hosts where you haven't specified a custom homepage.\n\nYour add-on homepage is displayed when one of the following conditions are met:\n\n- When the add-on is first opened in the host (after authorization).\n- When the user switches from a contextual context to a non-contextual context while the add-on is open. For example, from editing a Calendar event to the main Calendar.\n- When the user clicks the back button enough times to [pop every other card off of the internal stacks](/workspace/add-ons/how-tos/navigation).\n- When a UI interaction in a non-contextual card results in a [`Navigation.popToRoot()`](/apps-script/reference/card-service/navigation#popToRoot()) call.\n\nDesigning a homepage isn't mandatory but highly recommended; if you do not define any, a generic card\ncontaining your add-on name is used whenever a user would otherwise navigate\nto the homepage.\n\nHomepage configuration\n----------------------\n\nGoogle Workspace add-ons use the\n[`addOns.common.homepageTrigger`](/apps-script/manifest/addons#Common.FIELDS.homepageTrigger)\nfield to configure the default homepage (non-contextual) add-on content for\nall host applications in the add-on\n[manifest](/workspace/add-ons/concepts/workspace-manifests): \n\n {\n // ...\n \"addOns\": {\n // ...\n \"common\": {\n // ...\n \"homepageTrigger\": {\n \"runFunction\": \"myFunction\",\n \"enabled\": true\n }\n }\n }\n }\n\n- `runFunction`: The name of the Apps Script function that the\n Google Workspace add-ons framework invokes to render homepage add-on cards.\n This function is the *homepage trigger function* . This function must build\n and return an array of [`Card`](/apps-script/reference/card-service/card)\n objects that make up the homepage UI. If more than one card is returned, the\n host application shows the card headers in a list that the user can select\n from (see\n [Returning multiple cards](/workspace/add-ons/how-tos/navigation#returning_multiple_cards)).\n\n- `enabled`: Whether homepage cards should be enabled for this scope. This\n field is optional, and defaults to `true`. Setting this to `false` causes\n homepage cards to be disabled for all hosts (unless overridden for that\n host; see below).\n\n| **Note:** In order for a host to use the common homepage, both [`addOns.common.homepageTrigger`](/apps-script/manifest/addons#Common.FIELDS.homepageTrigger) and the host's top-level resource must be present in the add-on [manifest](/workspace/add-ons/concepts/workspace-manifests). For example, if [`addOns.gmail`](/apps-script/manifest/addons#AddOns.FIELDS.gmail) isn't present in the manifest, then the add-on is disabled for Gmail and will not show a homepage (or any other functionality in that host).\n\nIn addition to the common configuration, there are also\nidentically-structured per-host overrides available in each host application's\nconfig, at `addOns.gmail.homepageTrigger`, `addOns.calendar.homepageTrigger`,\nand so forth: \n\n {\n ...\n \"addOns\": {\n ...\n \"common\": {\n // By default, call 'buildHomePage' to render homepage content\n // in all hosts. Since calendar.homepageTrigger below overrides\n // this in Calendar and Drive and the homepageTrigger is disabled\n // for Gmail, this homepage function never executes.\n \"homepageTrigger\": { \"runFunction\": \"buildHomePage\" }\n },\n \"calendar\": {\n // Show customized homepage content for Calendar only.\n \"homepageTrigger\": { \"runFunction\": \"buildCalendarHomepage\" }\n },\n \"drive\": {\n // Show customized homepage content for Drive only.\n \"homepageTrigger\": { \"runFunction\": \"buildDriveHomepage\" }\n }\n \"gmail\": {\n // Disable homepage add-on content in Gmail.\n \"homepageTrigger\": { \"enabled\": false }\n },\n ...\n }\n }\n\nNote that this is equivalent to the following manifest excerpt: \n\n {\n ...\n \"addOns\": {\n ...\n \"common\": { /* ... */ }, // Omitted a default homepageTrigger specification.\n \"calendar\": {\n // Show customized homepage content for Calendar only.\n \"homepageTrigger\": { \"runFunction\": \"myCalendarFunction\" }\n },\n \"drive\": {\n // Show customized homepage content for Drive only.\n \"homepageTrigger\": { \"runFunction\": \"myDriveFunction\" }\n }\n \"gmail\": { /* ... */ },\n ...\n }\n }\n\nNone of the `homepageTrigger` sections are required. However, the UI shown for\nan add-on in any given host product depends on the presence of the\ncorresponding manifest field, and whether there's an associated\n`homepageTrigger`. The following example shows which add-on trigger functions\nare executed (if any) to create a homepage UI for different manifest\nconfigurations:\n\n### Homepage event objects\n\nWhen called, the homepage trigger function (`runFunction`) described above is\npassed an [event object](/workspace/add-ons/concepts/event-objects)\ncontaining data from the invocation context.\n\nHomepage event objects don't include widget or contextual information; the\ninformation passed is limited to the following\n[common event object](/workspace/add-ons/concepts/event-objects#common_event_object)\nfields:\n\n- `commonEventObject.clientPlatform`\n- `commonEventObject.hostApp`\n- `commonEventObject.userLocale` and `commonEventObject.userTimezone` (but see [Accessing user locale and timezone](/workspace/add-ons/how-tos/access-user-locale) for restriction information).\n\nSee [Event object](/workspace/add-ons/concepts/event-objects) for more details.\n\nOther non-contextual cards\n--------------------------\n\nYour add-on UI can contain additional non-contextual cards that aren't\nhomepages. For example, your homepage might have a button that opens a\n\"Settings\" card where the user can adjust the add-on settings (such settings\nwould, in most cases, be independent of context and therefore non-contextual).\n\nNon-contextual cards are built like any other card; the only difference is\nwhat action or event generates and displays the card. See\n[Navigation methods](/workspace/add-ons/how-tos/navigation#navigation_methods)\nfor details on how to create transitions between cards."]]