宣告動作

schema.org 中的動作代表可對結構化資料執行的特定動作或活動。Google 支援多種類型的動作,所有動作都能使用類似的結構化資料定義。

前往動作

如果您是透過 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>

請注意,其他不支援電子郵件架構的電子郵件用戶端會自動忽略上述標記。

行動深層連結

前往動作也可直接連結至 AndroidiOS:深層連結至 應用程式,加入其他以 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 不會顯示動作。

您也可以明確地為動作加入到期時間。舉例來說,剪輯優待券或儲存優惠代碼的動作可能只會在限定時間內有效。如要設定顯示動作的時間範圍,請設定動作的 startTimeendTime 屬性:

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>

其他資訊

如要進一步瞭解動作,請參閱: