声明 Action

schema.org 中的 Action 表示可以对一段结构化数据执行的动词或活动。系统支持多种类型的操作,所有这些操作都可以使用类似的结构化数据进行定义。

前往操作

如果您使用 schema.org 实体向内容添加标记,则可以为其添加 Go-To 操作。例如,如需使 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>

请注意,不支持在电子邮件中使用架构的其他电子邮件客户端会自动忽略上面的标记。

移动深层链接

此外,Go-To 操作还可以直接链接到 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>

如果用户未安装您的应用,则相应操作会将用户转到您提供的网址。

应用内操作次数

与应用有关的 Action 会在 Gmail 内就地处理,无需将用户转到其他网站。与应用有关的 Action 的声明类似于 Go-To Actions,但包含一些额外信息,以便用户代理(如 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>

延伸阅读

如需详细了解 Action,请参阅: