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 中的廣告只會在完全呈現後才會顯示。
遠端廣告設定
除了將 JSON 設定檔新增到 script 標記內 (如「內嵌廣告設定」章節所示),您也可以使用下列方式託管遠端網址
{ "ad-attributes": { "type": "doubleclick", "data-slot": "/30497360/a4a/amp_story_dfp_example" } }
設定好 JSON 設定檔後,只需使用
在 <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>
。在嘗試插入廣告時,插入演算法就會略過這個頁面之後的版位。
<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
觸發器傳送的要求則可取得所有先前事件的值 (requestTime
、loadTime
、insertTime
等)。
名稱 | 定義 |
---|---|
adIndex |
產生觸發器的廣告索引 (適用於所有觸發器) |
adUniqueId |
每個廣告都應具備的專屬 ID (適用於所有觸發器) |
requestTime |
廣告要求時間戳記 |
loadTime |
廣告發出 INI_LOAD 訊號的時間戳記 |
insertTime |
廣告插入 story 的時間戳記 |
viewTime |
廣告頁面變成有效頁面的時間戳記 |
clickTime |
廣告點擊時間戳記 |
exitTime |
廣告頁面從有效變為無效的時間戳記 |
discardTime |
廣告因中繼資料錯誤等原因而捨棄的時間戳記 |
position |
在父層 story 中的位置。廣告前的頁面數量 + 1。不計算先前插入的廣告頁面。(在插入時提供) |
ctaType |
已插入廣告的指定 cta 類型 (在插入時提供) |
您已讀過這份文件好幾次,但內容還是無法解答您的所有疑問嗎?或許其他人也有相同的感受:請在 Stack Overflow 上與他們交流。
前往 Stack Overflow 發現錯誤或缺少功能?AMP 專案大力鼓勵您的參與和貢獻!我們希望您能長期參與我們的開放原始碼社群,但我們也歡迎您針對特別感興趣的問題提供一次性的貢獻。
前往 GitHub