schema.org 中的動作代表可對結構化資料執行的動詞或活動。系統支援多種動作,且都能以類似的結構化資料定義這些動作。
行動號召
如果你是透過 schema.org 實體在內容中加入標記,可以為這些實體新增「前往」動作。舉例來說,如要讓 EmailMessage
實體有 ViewAction
Go-To 連結,請填入電子郵件的 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>
延伸閱讀
如要進一步瞭解動作,請參閱: