הצהרה על פעולות

פעולה ב-schema.org מייצגת פועל או פעילות שאפשר לבצע על נתונים מובְנים. המערכת תומכת בכמה סוגים של פעולות, וכולן יכולות להיות מוגדרות באמצעות נתונים מובְנים דומים.

פעולות מעבר

אם מוסיפים סימון לתוכן עם ישויות של schema.org, אפשר להוסיף להן פעולות מעבר. לדוגמה, כדי ליצור קישור 'מעבר אל' לישות EmailMessage, צריך לאכלס את המאפיין potentialAction של האימייל, כמו בדוגמה הבאה:ViewAction

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>

חשוב לציין שסימון ה-markup שלמעלה מתעלם באופן אוטומטי מלקוחות אימייל אחרים שלא תומכים בסכימות באימיילים.

קישורי עומק לנייד

פעולות 'מעבר אל' יכולות גם לקשר ישירות לתוכן באפליקציות נייטיב לנייד ב-Android וב-iOS. כדי להוסיף קישור עומק לאפליקציה, צריך לכלול כתובות URL נוספות שמקודדות באמצעות הסכמות 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>

אם האפליקציה לא מותקנת אצל המשתמש, הפעולה מפנה אותו לכתובת ה-URL באינטרנט שציינתם.

פעולות בתוך האפליקציה

הפעולות בתוך האפליקציה מתבצעות במקום, בתוך Gmail, בלי להעביר את המשתמש לאתר אחר. ההצהרה על פעולות באפליקציה דומה להצהרה על פעולות מעבר, אבל היא מכילה מידע נוסף שמקל על סוכני משתמש (כמו Gmail) לטפל בפעולה בתוך השורה.

במקום להצהיר על פעולה עם target, צריך להצהיר על HttpActionHandler לפעולה עם ההגדרה המתאימה.

לדוגמה, אפשר להוסיף לאימיילים לחצן אישור שדורש מהמשתמשים לאשר, לאמת או לאשר קבלה של משהו. כשהמשתמש לוחץ על הלחצן, 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>

קריאה נוספת

פרטים נוספים על פעולות זמינים במאמרים הבאים: