AMP

重要事項:本文件不適用於您目前選取的格式 電子郵件

amp-story-auto-ads

描述

動態地將廣告插入 Story 中。

 

必要指令碼

<script async custom-element="amp-story-auto-ads" src="https://cdn.ampproject.org/v0/amp-story-auto-ads-0.1.js"></script>

動態地將廣告插入 Story 中。

開始使用

如需如何在 AMP Story 中加入廣告的相關資訊,請參閱我們的指南

建立 AMP Story 廣告的最佳實務

如果您有興趣為 AMP Story 平台建立廣告,請參閱我們的最佳實務指南

行為

amp-story-auto-ads 擴充功能會在使用者瀏覽內容時,動態地將廣告 (以 amp-ad 實作) 插入 story 中。目前的演算法預期 story 至少包含 7 頁。

每個 amp-ad 都會以全螢幕 story 頁面插入。為了避免顯示空白/未載入的廣告,廣告會在背景中完整預先呈現,然後才對使用者顯示。擴充功能會根據使用者互動,決定何時以及何處插入廣告。

廣告在 story 中可以像一般 story 頁面一樣略過,方法是點擊螢幕的右側部分。

設定

設定廣告的方式有兩種:內嵌遠端

內嵌廣告設定

<amp-story-auto-ads> 元素中,您要指定一個 JSON 設定物件,其中包含廣告應如何擷取和顯示的詳細資訊,看起來如下所示

<amp-story>
  <amp-story-auto-ads>
    <script type="application/json">
      {
        "ad-attributes": {
          "type": "doubleclick",
          "data-slot": "/30497360/a4a/amp_story_dfp_example"
        }
      }
    </script>
  </amp-story-auto-ads>
  ...
</amp-story>

ad-attributes 是鍵值組的對應,這些鍵值組是要插入的 amp-ad 元素的屬性。

以上範例會插入以下 amp-ad 元素,代表由 doubleclick 提供的廣告

<amp-ad type="doubleclick" data-slot="/30497360/a4a/amp_story_dfp_example">
</amp-ad>

與一般的 amp-ad 不同,這裡不需要指定 <fallback><placeholder>,因為 story 中的廣告只會在完整呈現後才會顯示。

遠端廣告設定

除了在 script 標記內加入 JSON 設定檔 (如內嵌廣告設定章節所示) 之外,您也可以使用下列方式託管遠端 URL

遠端 JSON 廣告設定檔

{
  "ad-attributes": {
    "type": "doubleclick",
    "data-slot": "/30497360/a4a/amp_story_dfp_example"
  }
}

設定好 JSON 設定檔後,只需使用

html 廣告設定程式碼來擷取遠端 URL

<amp-story-auto-ads> 元素中,如下所示

<amp-story standalone supports-landscape>
    <!--
      This is an example of JSON retrieved from a source file.
    -->
    <amp-story-auto-ads src="/examples/amp-story/ads/remote.json" ></amp-story-auto-ads>
    <amp-story-page id="page-1">
    .
    .
    .
</amp-story>

傳遞其他屬性 (RTC、目標設定等)

如果您希望將任何其他資料 (例如目標設定資訊) 作為屬性傳遞至建立的 <amp-ad> 標記,只需將其他鍵值組新增至 ad-attributes JSON 物件即可。

常見的使用案例是將目標設定資料或 RTC 設定傳遞至底層的 amp-ad 元素。更複雜的設定可能如下所示

<amp-story-auto-ads>
  <script type="application/json">
    {
      "ad-attributes": {
        "type": "doubleclick",
        "data-slot": "/30497360/a4a/amp_story_dfp_example",
        "rtc-config": {
          "urls": ["https://rtcEndpoint.biz/"]
        },
        "json": {
          "targeting": {
            "loc": "usa",
            "animal": "cat"
          },
          "categoryExclusions": ["sports", "food", "fun"]
        }
      }
    }
  </script>
</amp-story-auto-ads>

這會產生以下 amp-ad 元素的建立結果。

<amp-ad
  type="doubleclick"
  data-slot="/30497360/a4a/amp_story_dfp_example"
  rtc-config='{"urls": ["https://rtcEndpoint.biz/"}'
  json='{"targeting":{"loc": "usa", "animal": "cat"}, "categoryExclusions":["sports", "food", "fun"]}'
>
</amp-ad>

驗證

amp-story-auto-ads 必須是 amp-story 元素的直接子元素。

插入控制

如果 story 中有特定位置是您絕不想顯示廣告的,您可以將 next-page-no-ad 屬性新增至 <amp-story-page>。插入演算法接著會在嘗試插入廣告時,略過此頁面之後的 slot。

<amp-story-page next-page-no-ad id="page-7">
  ...
</amp-story-page>

<!-- No ad will ever be inserted here. -->

<amp-story-page next-page-no-ad id="page-8">
  ...
</amp-story-page>

分析

當使用 amp-story-auto-ads 時,將會有幾個新的 分析觸發器和 [變數] 可用於您的分析設定。

觸發器

名稱 事件
story-ad-request 廣告已請求。
story-ad-load 廣告已載入。
story-ad-insert 廣告已插入。
story-ad-view 廣告已檢視。
story-ad-click 廣告的 CTA 按鈕已被點擊。
story-ad-exit 使用者停止觀看廣告。
story-ad-discard 廣告因設定無效而被捨棄。

變數

以下變數將大致依序提供。這些變數接著可用於任何後續的 ping。例如,使用 story-ad-load 觸發器的請求將無法存取 viewTime 變數,因為該變數尚未發生 (這會解析為空字串)。然而,使用 story-ad-exit 觸發器傳送的請求將能夠取得所有先前事件的值 (requestTimeloadTimeinsertTime 等)。

名稱 定義
adIndex 產生觸發器的廣告索引 (適用於所有觸發器)
adUniqueId 每個廣告都應是唯一的 ID (適用於所有觸發器)
requestTime 廣告請求的時間戳記
loadTime 廣告發出 INI_LOAD 訊號的時間戳記
insertTime 廣告插入 story 的時間戳記
viewTime 廣告頁面變成活動頁面的時間戳記
clickTime 廣告被點擊的時間戳記
exitTime 廣告頁面從活動 => 非活動狀態移動的時間戳記
discardTime 廣告因中繼資料錯誤等原因而被捨棄的時間戳記
position 在父層 story 中的位置。廣告之前的頁面數量 + 1。不計算先前插入的廣告頁面。(在插入時提供)
ctaType 已插入廣告的指定 cta-type (在插入時提供)
需要更多協助嗎?

您已閱讀本文件十幾次,但它仍然沒有真正涵蓋您的所有問題?也許其他人也有同感:在 Stack Overflow 上與他們聯繫。

前往 Stack Overflow
發現錯誤或缺少功能?

AMP 專案強烈鼓勵您的參與和貢獻!我們希望您能成為我們開放原始碼社群的長期參與者,但我們也歡迎您針對您特別熱衷的問題做出一次性的貢獻。

前往 GitHub