Trong schema.org, hành động đại diện cho một hoạt động có thể được thực hiện trên một phần dữ liệu có cấu trúc. Gmail hỗ trợ nhiều loại hành động và bạn có thể xác định từng loại bằng dữ liệu có cấu trúc tương tự.
Thao tác chuyển đến
Nếu thêm mã đánh dấu vào nội dung bằng các thực thể schema.org, bạn có thể thêm hành động truy cập cho các thực thể đó. Ví dụ: để cung cấp cho một thực thể EmailMessage một đường liên kết ViewAction, hãy điền sẵn thuộc tính potentialAction của email, như trong ví dụ sau:
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>
Vi dữ liệu
<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>
Các ứng dụng email khác không hỗ trợ giản đồ trong email sẽ tự động bỏ qua mã đánh dấu này.
Liên kết sâu trên thiết bị di động
Hành động chuyển đến cũng có thể liên kết trực tiếp đến nội dung trong ứng dụng di động trên Android và iOS.
Để liên kết sâu đến một ứng dụng, hãy thêm các URL target bổ sung được mã hoá bằng các giản đồ android-app:// và ios-app://, như trong các ví dụ sau:
JSON-LD
"target": [
"<web url>",
"android-app://<android package name>/<scheme>/<host>/<path+query>",
"ios-app://<App store ID>/<scheme>/<host><path+query>"
]
Vi dữ liệu
<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>"/>
Mở rộng ví dụ EmailMessage trước đó:
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>
Vi dữ liệu
<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>
Nếu người dùng chưa cài đặt ứng dụng của bạn, hành động này sẽ đưa người dùng đến URL trên web mà bạn cung cấp.
Hành động trong ứng dụng
Gmail xử lý các hành động trong ứng dụng ngay tại chỗ mà không chuyển người dùng đến một trang web khác. Bạn khai báo các thao tác trong ứng dụng như thao tác chuyển đến, nhưng hãy thêm thông tin bổ sung giúp các ứng dụng email (chẳng hạn như Gmail) xử lý thao tác nội tuyến.
Thay vì khai báo một thao tác bằng target, hãy khai báo một HttpActionHandler cho thao tác đó bằng cấu hình phù hợp.
Ví dụ: bạn có thể thêm một nút xác nhận vào những email yêu cầu người dùng phê duyệt, xác nhận hoặc xác nhận đã nhận được thông tin nào đó. Khi người dùng nhấp vào nút này, Google sẽ gửi một yêu cầu HTTP đến dịch vụ của bạn để ghi lại thông tin xác nhận. Người dùng chỉ có thể tương tác với một ConfirmAction một lần.
Ví dụ sau đây thêm một nút ConfirmAction vào email về báo cáo chi phí:
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>
Vi dữ liệu
<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>
Hành động sắp hết hạn
Trong nhiều trường hợp, các thao tác chỉ phù hợp trong một khoảng thời gian có hạn. Những hành động liên kết với các thực thể có ngày đã biết, chẳng hạn như thông tin đặt chỗ du lịch, sẽ tự động hết hạn. Gmail sẽ không hiển thị thao tác này sau khi chuyến đi kết thúc.
Bạn cũng có thể thêm thời gian hết hạn một cách rõ ràng cho các thao tác. Ví dụ: hành động cắt phiếu giảm giá hoặc lưu mã ưu đãi có thể chỉ có hiệu lực trong một khoảng thời gian giới hạn. Để đặt khung thời gian hiển thị một thao tác, hãy đặt các thuộc tính startTime và endTime của thao tác:
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>
Vi dữ liệu
<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>
Tài liệu đọc thêm
Để biết thêm thông tin chi tiết về các thao tác, hãy xem: