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

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

פעולות יעד

אם אתם מוסיפים לתוכן תגי עיצוב באמצעות ישויות של schema.org, תוכלו להוסיף פעולות Go-To עבורן. לדוגמה, כדי ליצור לישות EmailMessage קישור Go-To 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. לקישור עומק אל אפליקציה, לכלול כתובות URL נוספות מסוג target שמקודדות באמצעות הסכימות android-app:// ו-ios-app://, כפי שמוצג בהמשך:

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 עבור הפעולה עם ההגדרות המתאימות.

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

קריאה נוספת

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