網站連結搜尋框 (WebSite) 結構化資料

「網站連結搜尋框」可讓使用者在搜尋結果網頁上立即搜尋您的網站或應用程式,快速找出需要的內容。搜尋框會提供即時建議和其他功能。

當您的網站顯示在搜尋結果中時,Google 搜尋就可能會自動顯示以您的網站為搜尋範圍的搜尋框,完全不需要您另外採取任何行動。此搜尋框採用 Google 搜尋技術,不過您也可以新增 WebSite 結構化資料以明確提供資訊,讓 Google 進一步瞭解您的網站。

如果 Google 搜尋已經為您的網站顯示網站連結搜尋框,您就可以透過新增 WebSite 結構化資料,控管網站連結搜尋框的某些部分。

如何導入網站連結搜尋框

如果想讓您的網站符合在 Google 搜尋結果中顯示搜尋框的條件,請按照下列步驟進行:

  1. 在您的網站或 Android 應用程式上安裝有效的搜尋引擎

    網站連結搜尋查詢會將使用者導向網站或應用程式的搜尋結果頁面,因此您必須具備運作中的搜尋引擎才能啟動此功能。

    • 網站:在網站上設定搜尋引擎。此功能會使用結構化資料中指定的語法,將使用者的查詢轉送至您的目標。您的搜尋引擎必須支援 UTF-8 編碼查詢。
    • 應用程式:請參閱 Android 開發人員網站上的搜尋總覽,瞭解如何為應用程式實作搜尋引擎。您的 Android 應用程式必須支援來自搜尋結果的 ACTION_VIEW 意圖,並在標記的 potentialAction.target 屬性中指定對應的資料 URI。
  2. 在網站的首頁實作 WebSite 結構化資料元素。應用程式必須具備相關聯網站才能啟用此功能,即使網站只有一個網頁也可以。下面列出幾項額外的規範:
    • 這個標記只能在首頁新增,不能在其他頁面新增。
    • 如果您已經實作 WebSite 結構化資料來提供網站名稱功能,請務必在同一個節點中建立網站名稱屬性的巢狀結構。也就是說,如果可以,請避免在首頁上建立額外的 WebSite 結構化資料區塊。
    • 一定要為網站指定 SearchAction,如果也支援應用程式搜尋,可以再指定另一個,但後者屬於選用性質。即便應用程式是您比較偏好的搜尋目標,也還是必須為網站指定 SearchAction;因為這樣一來,如果使用者不是從 Android 手機進行搜尋,或是並未安裝您的 Android 應用程式,這項做法能確保搜尋結果仍然會導向您的網站。
    • 根據您使用的格式,瞭解要在網頁中的什麼位置插入結構化資料
  3. 遵循指南的規定。
  4. 使用複合式搜尋結果測試驗證程式碼
  5. 驗證您的搜尋引擎實作程序,做法是從結構化資料複製 WebSite.potentialAction.target 網址,並使用測試查詢取代 {search_term_string},然後在網路瀏覽器中前往該網址。 舉例來說,如果您的網站為 example.com,而您想要測試的查詢為「kittens」(小貓),則可前往 https://www.example.com/search/?q=kittens
  6. 在首頁的所有變化版本上使用 rel="canonical" link 元素,藉此為網域首頁設定偏好的標準網址。這種做法有助於 Google 搜尋選擇正確的標記網址。您的伺服器必須支援 UTF-8 字元編碼。
  7. 如果是應用程式,請啟用適當的意圖篩選器來支援您在標記的應用程式目標中指定的網址。如要進一步瞭解如何為 Google 搜尋網址建立意圖篩選器,請參閱適用於 Android 的 Firebase 應用程式索引
  8. 部署幾個包含結構化資料的網頁,並使用網址檢查工具測試 Google 轉譯網頁的情形。請確認 Google 可以存取您的網頁,且網頁並未遭到 robots.txt 檔案或 noindex 標記封鎖,也未設有登入規定。如果網頁看起來沒問題,您可以要求 Google 重新檢索您的網址
  9. 為了讓 Google 掌握日後的異動內容,建議您提交 Sitemap。您可以使用 Search Console Sitemap API 自動執行這項操作。

範例

以下是「Pinterest」的 Google 搜尋結果範例,這個範例能夠傳回 Pinterest 網站的網站連結搜尋框:

使用中的網站連結搜尋框

下列提供幾個標記範例,示範如何使用網站自訂搜尋引擎實作網站連結搜尋框:

JSON-LD

以下是採用 JSON-LD 格式的範例:


<html>
  <head>
    <title>The title of the page</title>
    <script type="application/ld+json">
    {
      "@context": "https://schema.org",
      "@type": "WebSite",
      "url": "https://www.example.com/",
      "potentialAction": {
        "@type": "SearchAction",
        "target": {
          "@type": "EntryPoint",
          "urlTemplate": "https://query.example.com/search?q={search_term_string}"
        },
        "query-input": "required name=search_term_string"
      }
    }
    </script>
  </head>
  <body>
  </body>
</html>
微資料

以下是採用微資料格式的範例:


<div itemscope itemtype="https://schema.org/WebSite">
  <meta itemprop="url" content="https://www.example.com/"/>
  <form itemprop="potentialAction" itemscope itemtype="https://schema.org/SearchAction">
    <meta itemprop="target" content="https://query.example.com/search?q={search_term_string}"/>
    <input itemprop="query-input" type="text" name="search_term_string" required/>
    <input type="submit"/>
  </form>
</div>
  

以下是採用 JSON-LD 格式的網站和應用程式範例:

<html>
  <head>
    <title>The title of the page</title>
    <script type="application/ld+json">
    {
      "@context": "https://schema.org",
      "@type": "WebSite",
      "url": "https://www.example.com/",
      "potentialAction": [{
        "@type": "SearchAction",
        "target": {
          "@type": "EntryPoint",
          "urlTemplate": "https://query.example.com/search?q={search_term_string}"
        },
        "query-input": "required name=search_term_string"
      },{
        "@type": "SearchAction",
        "target": {
          "@type": "EntryPoint",
          "urlTemplate": "android-app://com.example/https/query.example.com/search/?q={search_term_string}"
        },
        "query-input": "required name=search_term_string"
      }]
    }
    </script>
  </head>
  <body>
  </body>
</html>

指南規範

您必須遵守下列規範,才能以複合式搜尋結果的形式顯示您的網站。

即使網站並未包含此處說明的結構化資料,Google 搜尋仍可自行在網站的搜尋結果中加入網站連結搜尋框。不過,您可以在首頁新增下列 meta 標記,避免這個現象發生:

<meta name="google" content="nositelinkssearchbox">

結構化資料類型定義

如要讓您的內容符合網站連結搜尋框的顯示資格,請加入必要屬性。

經過修改的 WebSite 類型

Google 搜尋會同時針對網站和應用程式搜尋框使用修改後的 WebSite 結構化資料類型。雖然 Google 搜尋的標準與 schema.org 略有不同,您仍可前往該網站查看 WebSite 的完整定義。Google 支援的屬性如下:

必要屬性
potentialAction

一或兩個 SearchAction 物件的陣列

此物件會說明傳送查詢的目的地 URI,以及所傳送要求的語法。您必須實作可接收要求的網頁或意圖處理常式,並且對提交的字串執行適當的搜尋。如果使用者並非位於 Android 應用程式 (或是在 Android 應用程式,但並未指定 Android 意圖目標),搜尋框就會將查詢的網站版本傳送至指定的位置;如果使用者位於 Android 裝置且已指定 Android 意圖 URI,則搜尋框會傳送該意圖。

您必須建立網站 SearchAction 以啟用桌面搜尋案例。如果同時支援應用程式搜尋,您便可另外為應用程式指定 SearchAction 物件。每個 SearchAction 都必須含有下列巢狀屬性:

網站範例

下列範例會將 GET 要求傳送至 https://query.example.com/search?q=user%20search%20string

"potentialAction": [{
  "@type": "SearchAction",
  "target": {
    "@type": "EntryPoint",
    "urlTemplate": "https://query.example.com/search?q={search_term_string}"
  },
  "query-input": "required name=search_term_string"
}]

應用程式範例

下列範例會將 Android 意圖傳送至 android-app://com.example/https/query.example.com/search/?q=user_search_string

"potentialAction": [{
  "@type": "SearchAction",
  "target": {
    "@type": "EntryPoint",
    "urlTemplate": "android-app://com.example/https/query.example.com/search/?q={search_term_string}"
  },
  "query-input": "required name=search_term_string"
}]

potentialAction.query-input

Text

使用 required name = search-term 文字字串,或是您在 target 中使用的任何預留位置。請確認這兩個預留位置值相符,例如 targetquery-input 屬性中的預留位置值都使用 search-term 字串:

"potentialAction": [{
  "@type": "SearchAction",
  "target": {
    "@type": "EntryPoint",
    "urlTemplate": "https://query.example.com/search?q={search-term}"
  },
  "query-input": "required name=search-term"
}]
potentialAction.target

EntryPoint

含有 urlTemplate 屬性的 EntryPoint 物件。

urlTemplate 必須為下列格式的字串:search_handler_uri{search_term_string}

例如:

https://query.example.com/search?q={search_term_string}
search_handler_uri 如果是網站,即為接收和處理搜尋查詢的處理常式網址;如果是應用程式,即為處理查詢的搜尋引擎意圖處理常式 URI。
search_term_string

這是預留位置字串,只要使用者在搜尋框中點選「搜尋」按鈕,本身發出的搜尋查詢就會取代這個字串。請確認在此使用的預留位置字串符合 query-input 屬性的 name 元素值。

url

URL

把提供外界搜尋的網站網址設定為您網站的標準首頁。例如:https://www.example.org

透過 Search Console 監控複合式搜尋結果

Search Console 這項工具能協助您監控網頁在 Google 搜尋中的成效。 Google 會主動將您的網頁納入搜尋結果,您無需為此申請使用 Search Console,但是您可以藉由這項服務瞭解並改善 Google 檢索您網站的方式。建議在下列情況查看 Search Console:

  1. 首次部署結構化資料後
  2. 發布新範本或更新程式碼後
  3. 定期分析流量

首次部署結構化資料後

在 Google 為網頁建立索引後,請透過相關的複合式搜尋結果狀態報告查看是否存在任何問題。理想情況下,有效項目會增加,但無效項目不會變多。如果您在結構化資料中發現問題,請依下列步驟操作:

  1. 修正無效項目
  2. 檢查線上網址,查看問題是否仍繼續發生。
  3. 透過狀態報告要求驗證

發布新範本或更新程式碼後

當您對網站進行大幅變更時,請留意結構化資料中無效項目是否增加。
  • 如果無效項目增加,代表您推出的新範本可能無法正常運作,或者您的網站採用新方式與現有範本互動,但效果不佳。
  • 如果有效項目減少,但錯誤並未隨之增加,代表您的網頁可能已不再內嵌結構化資料。請使用網址檢查工具找出問題的成因。

定期分析流量

透過成效報表分析您的 Google 搜尋流量。 這些資料會顯示您的網頁在 Google 搜尋中呈現為複合式搜尋結果的頻率、使用者點擊的頻率,以及您的搜尋結果平均排名。您也可以使用 Search Console API 自動提取這些結果。

Troubleshooting

If you're having trouble implementing or debugging structured data, here are some resources that may help you.

  • If you're using a content management system (CMS) or someone else is taking care of your site, ask them to help you. Make sure to forward any Search Console message that details the issue to them.
  • Google does not guarantee that features that consume structured data will show up in search results. For a list of common reasons why Google may not show your content in a rich result, see the General Structured Data Guidelines.
  • You might have an error in your structured data. Check the list of structured data errors.
  • If you received a structured data manual action against your page, the structured data on the page will be ignored (although the page can still appear in Google Search results). To fix structured data issues, use the Manual Actions report.
  • Review the guidelines again to identify if your content isn't compliant with the guidelines. The problem can be caused by either spammy content or spammy markup usage. However, the issue may not be a syntax issue, and so the Rich Results Test won't be able to identify these issues.
  • Troubleshoot missing rich results / drop in total rich results.
  • Allow time for re-crawling and re-indexing. Remember that it may take several days after publishing a page for Google to find and crawl it. For general questions about crawling and indexing, check the Google Search crawling and indexing FAQ.
  • Post a question in the Google Search Central forum.