首頁
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
首頁是 Google Workspace 外掛程式的新功能,可定義一或多個非情境卡片。非情境卡片會在使用者處於特定情境之外時顯示使用者介面,例如使用者查看 Gmail 收件匣,但尚未開啟郵件或草稿時。
首頁可讓您顯示非情境內容,就像快速存取側邊面板 中的 Google 應用程式 (Keep、日曆和 Tasks) 一樣。首頁也可以為使用者初次開啟外掛程式時提供初始起點,並可用於教導新使用者如何與外掛程式互動。
您可以透過在專案資訊清單中指定,並實作一或多個 homepageTrigger
函式,為外掛程式定義首頁 (請參閱「首頁設定」)。
您可以擁有多個首頁,每個首頁對應至擴充外掛程式所延伸的每個主機應用程式。您也可以選擇定義單一常見的預設首頁,用於未指定自訂首頁的主機。
系統會在符合下列任一條件時,顯示你的擴充功能首頁:
設計首頁並非必要,但強烈建議您這麼做;如果您未定義任何首頁,使用者在前往首頁時,系統會使用含有外掛程式名稱的一般資訊卡。
首頁設定
Google Workspace 外掛程式會使用 addOns.common.homepageTrigger
欄位,為外掛程式 manifest 中的所有主機應用程式設定預設的首頁 (非情境相關) 外掛程式內容:
{
// ...
"addOns": {
// ...
"common": {
// ...
"homepageTrigger": {
"runFunction": "myFunction",
"enabled": true
}
}
}
}
runFunction
:Google Workspace 外掛程式架構叫用以顯示首頁外掛程式資訊卡的 Apps Script 函式名稱。這個函式是首頁觸發函式。這個函式必須建立並傳回 Card
物件陣列,這些物件組成首頁 UI。如果傳回多張資訊卡,主機應用程式會在清單中顯示資訊卡標題,供使用者選取 (請參閱「傳回多張資訊卡」)。
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
區段都不是必填。不過,在任何特定主機產品中,顯示的擴充功能 UI 取決於是否有對應的資訊清單欄位,以及是否有相關的 homepageTrigger
。以下範例顯示執行哪些外掛程式觸發函式 (如有),以便為不同的資訊清單設定建立首頁 UI:

首頁事件物件
呼叫時,上述的首頁觸發事件函式 (runFunction
) 會傳遞包含呼叫內容的資料的事件物件。
首頁事件物件不包含小工具或內容相關資訊;傳遞的資訊僅限於下列常見事件物件欄位:
commonEventObject.clientPlatform
commonEventObject.hostApp
commonEventObject.userLocale
和 commonEventObject.userTimezone
(但請參閱「存取使用者語言代碼和時區」一文,瞭解限制資訊)。
詳情請參閱「事件物件」。
其他非情境卡片
外掛程式 UI 可包含非首頁的其他非情境資訊卡。舉例來說,首頁可能會提供一個按鈕,讓使用者開啟「設定」資訊卡,以便調整外掛程式設定 (在多數情況下,這類設定會與內容無關,因此屬於非情境設定)。
非情境資訊卡的建構方式與其他資訊卡相同,唯一的差異在於產生及顯示資訊卡的動作或事件。如要進一步瞭解如何在資訊卡之間建立轉場效果,請參閱「導覽方法」。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-01 (世界標準時間)。
[null,null,["上次更新時間: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."]]