Khai báo thao tác

Một Hành động trong schema.org biểu thị một động từ hoặc hoạt động có thể được thực hiện trên một phần dữ liệu có cấu trúc. Google hỗ trợ nhiều loại hành động và có thể xác định các hành động đó bằng dữ liệu có cấu trúc tương tự.

Chuyển đến hành động

Nếu thêm thẻ đánh dấu vào nội dung bằng các thực thể schema.org, bạn có thể thêm các thao tác Chuyển đến cho các thực thể đó. Ví dụ: để tạo một thực thể EmailMessage có đường liên kết Truy cập ViewAction, hãy điền sẵn tài sản 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>

Lưu ý rằng mã đánh dấu nêu trên sẽ tự động bị các ứng dụng email khác không hỗ trợ giản đồ trong email.

Đường liên kết sâu trên thiết bị di động

Thao tác Chuyển đến cũng có thể liên kết trực tiếp đến nội dung trong ứng dụng gốc dành cho thiết bị di động trên AndroidiOS. Đến đường liên kết sâu đến một ứng dụng, hãy thêm các URL target khác được mã hoá bằng giao thức android-app://ios-app:// như trình bày dưới đây:

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ụ trước về 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>

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://12345/movieapp/watch-movies.com/watch?movieId=abc123"/>
 </div>
</div>

Nếu người dùng không có ứng dụng của bạn, thao tác này sẽ đưa người dùng đến URL web mà bạn cung cấp.

Hành động trong ứng dụng

Hành động trong ứng dụng được xử lý tại chỗ, bên trong Gmail mà không cần chuyển người dùng đến trang web khác. Hành động trong ứng dụng được khai báo giống như Hành động chuyển đến, nhưng chứa thêm thông tin giúp tác nhân người dùng (chẳng hạn như Gmail) dễ dàng xử lý hành động cùng dòng.

Thay vì khai báo một thao tác bằng target, bạn cần khai báo HttpActionHandler cho thao tác đó có cấu hình phù hợp.

Ví dụ: bạn có thể thêm nút xác nhận vào email yêu cầu người dùng phê duyệt, xác nhận và xác nhận một nội dung nào đó. Khi người dùng nhấp vào nút, Google sẽ gửi một yêu cầu HTTP đến dịch vụ của bạn, trong đó ghi lại nội dung xác nhận. Bạn chỉ có thể tương tác với ConfirmAction một lần.

Ví dụ sau đây sẽ thêm nút ConfirmAction vào một 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, hành động chỉ liên quan đến một khoảng thời gian giới hạn. Các hành động liên kết với các mục mà chúng tôi đã xác định được, chẳng hạn như thông tin đặt chỗ du lịch, sẽ tự động hết hạn. Gmail không hiển thị hành động sau khi chuyến đi đã qua.

Bạn cũng có thể thêm rõ ràng thời gian hết hạn vào các thao tác. Ví dụ: một hành động để cắt phiếu giảm giá hoặc lưu mã ưu đãi có thể chỉ hợp lệ trong thời gian có hạn. Để đặt khoảng thời gian hiển thị một hành động, hãy đặt các thuộc tính startTimeendTime của hành động đó:

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ề Thao tác, hãy xem: