在 schema.org 中,操作表示可以对结构化数据执行的活动。Gmail 支持多种类型的操作,您可以使用类似的结构化数据来定义每种操作。
前往操作
如果您使用 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-app://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>
深入阅读
如需详细了解操作,请参阅: