宣告動作
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
schema.org 中的動作代表可對結構化資料執行的動詞或活動。系統支援多種動作,且這些動作都可以使用類似的結構化資料定義。
Go-To Actions
如果使用 schema.org 實體在內容中加入標記,可以為這些實體新增「前往」動作。舉例來說,如要讓 EmailMessage
實體具有「前往」ViewAction
連結,請填入電子郵件的 potentialAction
屬性,如下列範例所示:
JSON-LD
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://watch-movies.com/watch?movieId=abc123",
"name": "Watch movie"
},
"description": "Watch the 'Avengers' movie online"
}
</script>
微資料
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="potentialAction" itemscope itemtype="http://schema.org/ViewAction">
<link itemprop="target" href="https://watch-movies.com/watch?movieId=abc123"/>
<meta itemprop="name" content="Watch movie"/>
</div>
<meta itemprop="description" content="Watch the 'Avengers' movie online"/>
</div>
請注意,如果其他電子郵件用戶端不支援電子郵件中的結構定義,系統會自動忽略上述標記。
行動深層連結
「前往」動作也可以直接連結至 Android 和 iOS 原生行動應用程式中的內容。如要深層連結至應用程式,請加入以 android-app://
和 ios-app://
架構編碼的其他 target
網址,如下所示:
JSON-LD
"target": [
“<web url>”,
“android-app://<android package name>/<scheme>/<host>/<path+query>”,
“ios-app://<App store ID>/<scheme>/<host><path+query>"
]
微資料
<link itemprop="target" href="<web url>"/>
<link itemprop="target" href="android-app://<android package name>/<scheme>/<host>/<path+query>”/>
<link itemprop="target" href="ios-app://<App store ID>/<scheme>/<host>/<path+query>"/>
延續先前的 EmailMessage
範例:
JSON-LD
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"name": "Watch movie",
... information about the movie ...
"potentialAction": {
"@type": "ViewAction",
"target": [
"https://watch-movies.com/watch?movieId=abc123",
"android-app://com.watchmovies.app/http/watch-movies.com/watch?movieId=abc123",
"ios-app://12345/movieapp/watch-movies.com/watch?movieId=abc123"
]
}
}
</script>
微資料
<div itemscope itemtype="http://schema.org/EmailMessage">
<meta itemprop="name" content="Watch movie"/>
... information about the movie ...
<div itemprop="potentialAction" itemscope itemtype="http://schema.org/ViewAction">
<meta itemprop="target" content="https://watch-movies.com/watch?movieId=abc123"/>
<meta itemprop="target" content="android-app://com.watchmovies.android/http/watch-movies.com/watch?movieId=abc123"/>
<meta itemprop="target" content="ios://12345/movieapp/watch-movies.com/watch?movieId=abc123"/>
</div>
</div>
如果使用者沒有您的應用程式,系統會將他們帶往您提供的網頁網址。
應用程式內動作
應用程式內動作會在 Gmail 內處理,不會將使用者導向其他網站。應用程式內動作的宣告方式與前往動作類似,但包含額外資訊,方便使用者代理程式 (例如 Gmail) 處理內嵌動作。
您需要為動作宣告 HttpActionHandler
,並進行適當設定,而不是使用 target
宣告動作。
舉例來說,如果電子郵件要求使用者核准、確認或瞭解某件事,您可以在郵件中加入確認按鈕。使用者點選按鈕後,Google 會向您的服務發出 HTTP 要求,記錄確認資訊。ConfirmAction
只能互動一次。
以下範例會在費用報告電子郵件中新增 ConfirmAction
按鈕:
JSON-LD
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ConfirmAction",
"name": "Approve Expense",
"handler": {
"@type": "HttpActionHandler",
"url": "https://myexpenses.com/approve?expenseId=abc123"
}
},
"description": "Approval request for John's $10.13 expense for office supplies"
}
</script>
微資料
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="potentialAction" itemscope itemtype="http://schema.org/ConfirmAction">
<meta itemprop="name" content="Approve Expense"/>
<div itemprop="handler" itemscope itemtype="http://schema.org/HttpActionHandler">
<link itemprop="url" href="https://myexpenses.com/approve?expenseId=abc123"/>
</div>
</div>
<meta itemprop="description" content="Approval request for John's $10.13 expense for office supplies"/>
</div>
即將到期的動作
在許多情況下,動作只在一段時間內有效。與已知日期相關聯的實體 (例如旅遊預訂) 動作會自動過期。行程結束後,Gmail 就不會顯示這項動作。
您也可以明確為動作新增到期日。舉例來說,剪下優待券或儲存優惠代碼的動作可能僅在一段時間內有效。如要設定顯示動作的時間範圍,請設定動作的 startTime
和 endTime
屬性:
JSON-LD
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ConfirmAction",
"name": "Save coupon",
"handler": {
"@type": "HttpActionHandler",
"url": "https://my-coupons.com/approve?couponId=abc123"
},
"startTime": "2015-06-01T12:00:00Z",
"endTime": "2015-06-05T12:00:00Z"
}
}
</script>
微資料
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="potentialAction" itemscope itemtype="http://schema.org/ConfirmAction">
<meta itemprop="name" content="Save coupon"/>
<div itemprop="handler" itemscope itemtype="http://schema.org/HttpActionHandler">
<link itemprop="url" href="https://my-coupons.com/approve?couponId=abc123"/>
</div>
<meta itemprop="startTime" content="2015-06-01T12:00:00Z" />
<meta itemprop="endTime" content="2015-06-05T12:00:00Z" />
</div>
</div>
延伸閱讀
如要進一步瞭解動作,請參閱:
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-29 (世界標準時間)。
[null,null,["上次更新時間:2025-08-29 (世界標準時間)。"],[],[],null,["# Declare Actions\n\nAn Action in schema.org represents a verb or activity that can be performed on a piece of structured data. Multiple types of [actions](/workspace/gmail/markup/actions/actions-overview) are supported and they can all be defined with similar structured data.\n\nGo-To Actions\n-------------\n\nIf you add markup to your content with schema.org entities, you can add Go-To actions for them. For example, to make an `EmailMessage` entity have a `ViewAction` Go-To link, populate the email's `potentialAction` property, as in the following example: \n\n### JSON-LD\n\n \u003cscript type=\"application/ld+json\"\u003e\n {\n \"@context\": \"http://schema.org\",\n \"@type\": \"EmailMessage\",\n \"potentialAction\": {\n \"@type\": \"ViewAction\",\n \"target\": \"https://watch-movies.com/watch?movieId=abc123\",\n \"name\": \"Watch movie\"\n },\n \"description\": \"Watch the 'Avengers' movie online\"\n }\n \u003c/script\u003e\n\n### Microdata\n\n \u003cdiv itemscope itemtype=\"http://schema.org/EmailMessage\"\u003e\n \u003cdiv itemprop=\"potentialAction\" itemscope itemtype=\"http://schema.org/ViewAction\"\u003e\n \u003clink itemprop=\"target\" href=\"https://watch-movies.com/watch?movieId=abc123\"/\u003e\n \u003cmeta itemprop=\"name\" content=\"Watch movie\"/\u003e\n \u003c/div\u003e\n \u003cmeta itemprop=\"description\" content=\"Watch the 'Avengers' movie online\"/\u003e\n \u003c/div\u003e\n\nNote that the markup above is automatically ignored by other email clients that do not support schemas in emails.\n\nMobile Deep Linking\n-------------------\n\nGo-To actions can also link directly to content in native mobile apps on\n[Android](https://developer.android.com/training/app-indexing/deep-linking.html) and\n[iOS](https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Inter-AppCommunication/Inter-AppCommunication.html#//apple_ref/doc/uid/TP40007072-CH6-SW1). To deep link to\nan app, include additional `target` URLs encoded with the `android-app://` and `ios-app://` schemes as shown below: \n\n### JSON-LD\n\n \"target\": [\n \"\u003cweb url\u003e\",\n \"android-app://\u003candroid package name\u003e/\u003cscheme\u003e/\u003chost\u003e/\u003cpath+query\u003e\",\n \"ios-app://\u003cApp store ID\u003e/\u003cscheme\u003e/\u003chost\u003e\u003cpath+query\u003e\"\n ]\n\n### Microdata\n\n \u003clink itemprop=\"target\" href=\"\u003cweb url\u003e\"/\u003e\n \u003clink itemprop=\"target\" href=\"android-app://\u003candroid package name\u003e/\u003cscheme\u003e/\u003chost\u003e/\u003cpath+query\u003e\"/\u003e\n \u003clink itemprop=\"target\" href=\"ios-app://\u003cApp store ID\u003e/\u003cscheme\u003e/\u003chost\u003e/\u003cpath+query\u003e\"/\u003e\n\nExtending the previous `EmailMessage` example: \n\n### JSON-LD\n\n \u003cscript type=\"application/ld+json\"\u003e\n {\n \"@context\": \"http://schema.org\",\n \"@type\": \"EmailMessage\",\n \"name\": \"Watch movie\",\n ... information about the movie ...\n \"potentialAction\": {\n \"@type\": \"ViewAction\",\n \"target\": [\n \"https://watch-movies.com/watch?movieId=abc123\",\n \"android-app://com.watchmovies.app/http/watch-movies.com/watch?movieId=abc123\",\n \"ios-app://12345/movieapp/watch-movies.com/watch?movieId=abc123\"\n ]\n }\n }\n \u003c/script\u003e\n\n### Microdata\n\n \u003cdiv itemscope itemtype=\"http://schema.org/EmailMessage\"\u003e\n \u003cmeta itemprop=\"name\" content=\"Watch movie\"/\u003e\n ... information about the movie ...\n \u003cdiv itemprop=\"potentialAction\" itemscope itemtype=\"http://schema.org/ViewAction\"\u003e\n \u003cmeta itemprop=\"target\" content=\"https://watch-movies.com/watch?movieId=abc123\"/\u003e\n \u003cmeta itemprop=\"target\" content=\"android-app://com.watchmovies.android/http/watch-movies.com/watch?movieId=abc123\"/\u003e\n \u003cmeta itemprop=\"target\" content=\"ios://12345/movieapp/watch-movies.com/watch?movieId=abc123\"/\u003e\n \u003c/div\u003e\n \u003c/div\u003e\n\nIf the user doesn't have your app, the action takes the user to the web URL you provide.\n\nIn-App Actions\n--------------\n\nIn-App Actions are handled in-place, inside Gmail, without sending the user to another website. In-App Actions are declared like [Go-To Actions](#go-to_actions), but contain extra information that makes it easy for user-agents (such as Gmail) to handle the action inline.\n\nInstead of declaring an action with a `target`, you need to declare an `HttpActionHandler` for the action with the proper configuration.\n\nFor instance, you can add a confirm button to emails requiring users to approve, confirm, and acknowledge something. Once the user clicks on the button, an HTTP request will be issued from Google to your service, recording the confirmation. `ConfirmAction` can only be interacted with once.\n\nThe following example adds a `ConfirmAction` button to an email about an expense report: \n\n### JSON-LD\n\n \u003cscript type=\"application/ld+json\"\u003e\n {\n \"@context\": \"http://schema.org\",\n \"@type\": \"EmailMessage\",\n \"potentialAction\": {\n \"@type\": \"ConfirmAction\",\n \"name\": \"Approve Expense\",\n \"handler\": {\n \"@type\": \"HttpActionHandler\",\n \"url\": \"https://myexpenses.com/approve?expenseId=abc123\"\n }\n },\n \"description\": \"Approval request for John's $10.13 expense for office supplies\"\n }\n \u003c/script\u003e\n\n### Microdata\n\n \u003cdiv itemscope itemtype=\"http://schema.org/EmailMessage\"\u003e\n \u003cdiv itemprop=\"potentialAction\" itemscope itemtype=\"http://schema.org/ConfirmAction\"\u003e\n \u003cmeta itemprop=\"name\" content=\"Approve Expense\"/\u003e\n \u003cdiv itemprop=\"handler\" itemscope itemtype=\"http://schema.org/HttpActionHandler\"\u003e\n \u003clink itemprop=\"url\" href=\"https://myexpenses.com/approve?expenseId=abc123\"/\u003e\n \u003c/div\u003e\n \u003c/div\u003e\n \u003cmeta itemprop=\"description\" content=\"Approval request for John's $10.13 expense for office supplies\"/\u003e\n \u003c/div\u003e\n\nExpiring Actions\n----------------\n\nIn many cases, actions are only relevant for a limited period of time. Actions associated to entities with known dates, like travel reservations, will automatically expire. Gmail doesn't display the action after the trip has passed.\n\nExpirations can also be explicitly added to actions. For example, an action to clip a coupon or save an offer code might only be valid for a limited time. To set the time window for when an action is displayed, set the `startTime` and `endTime` properties of the action: \n\n### JSON-LD\n\n \u003cscript type=\"application/ld+json\"\u003e\n {\n \"@context\": \"http://schema.org\",\n \"@type\": \"EmailMessage\",\n \"potentialAction\": {\n \"@type\": \"ConfirmAction\",\n \"name\": \"Save coupon\",\n \"handler\": {\n \"@type\": \"HttpActionHandler\",\n \"url\": \"https://my-coupons.com/approve?couponId=abc123\"\n },\n \"startTime\": \"2015-06-01T12:00:00Z\",\n \"endTime\": \"2015-06-05T12:00:00Z\"\n }\n }\n \u003c/script\u003e\n\n### Microdata\n\n \u003cdiv itemscope itemtype=\"http://schema.org/EmailMessage\"\u003e\n \u003cdiv itemprop=\"potentialAction\" itemscope itemtype=\"http://schema.org/ConfirmAction\"\u003e\n \u003cmeta itemprop=\"name\" content=\"Save coupon\"/\u003e\n \u003cdiv itemprop=\"handler\" itemscope itemtype=\"http://schema.org/HttpActionHandler\"\u003e\n \u003clink itemprop=\"url\" href=\"https://my-coupons.com/approve?couponId=abc123\"/\u003e\n \u003c/div\u003e\n \u003cmeta itemprop=\"startTime\" content=\"2015-06-01T12:00:00Z\" /\u003e\n \u003cmeta itemprop=\"endTime\" content=\"2015-06-05T12:00:00Z\" /\u003e\n \u003c/div\u003e\n \u003c/div\u003e\n\nFurther Reading\n---------------\n\nFor more details about Actions, see:\n\n- [Handling Action Requests](/workspace/gmail/markup/actions/handling-action-requests)\n- [Securing Actions](/workspace/gmail/markup/actions/securing-actions)\n- [Android Deep Linking](https://developer.android.com/training/app-indexing/deep-linking.html)\n- [iOS Deep Linking](https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Inter-AppCommunication/Inter-AppCommunication.html#//apple_ref/doc/uid/TP40007072-CH6-SW1)\n\n| **Note:** Some of the schemas used by Google are still going through the standardization process of [schema.org](http://schema.org), and therefore, may change in the future. [Learn More](/workspace/gmail/markup/reference/schema-org-proposals)."]]