廣告最佳做法

將 Google 發布商廣告代碼 (GPT) 整合到您的網站並熟悉一般最佳做法後,您就可以開始發出廣告請求。以下將介紹設定及使用廣告版位時,應謹記的幾個最佳做法,以發揮廣告空間的最大效益,並將影響降到最低。

優先顯示「重要」廣告版位

並非所有廣告版位的建立方式都一致。舉例來說,網頁載入時如有可見的版位 (不需捲動位置),通常比捲動畫面顯示 (不需捲動位置) 要看的時段要來得「重要」;有鑑於此,請務必仔細考量網頁中每個廣告版位的相對重要性,並盡快優先載入最重要的廣告版位。

提前載入不需捲動位置廣告

一旦系統載入網頁時,應該顯示優先順序最高的廣告。建議您在文件的 <head> 中定義這些運算單元,並盡早在網頁載入過程中盡早請求這些運算單元。以確保及早載入廣告 (盡可能提高可視度),而且不會拖慢初始網頁載入的速度。

延遲載入位於需捲動位置的廣告

對於需要捲動至視圖的廣告,您應該延遲擷取和顯示,直到廣告版位接近可視區域為止。這個過程稱為延遲載入。延遲載入功能,會優先針對最有可能瀏覽的版位請求和顯示廣告素材內容。這有助於節省瀏覽器受限的資源,這對於在頻寬和 CPU 經常受到嚴格限制的行動環境中尤其重要。

重新整理廣告而不重新整理網頁

在許多情況下,最好將版位的現有廣告內容換成最佳,甚至是必要的。在這類情況下,最好使用 GPT 程式庫的重新整理功能來進行動態更新。如此可避免重新整理整個網頁,並讓您精確控制在哪個條件下,更新運算單元或一組運算單元。

重新整理廣告版位時,請務必熟悉並遵循 refresh() 最佳做法。不當重新整理廣告可能會導致成效問題,並對可視度造成負面影響。

有效指定廣告目標

設定鍵/值指定目標時,請謹慎考慮要使用版位或網頁層級指定目標。針對多個版位之間共用的鍵/值,透過 PubAdsService setTargeting() 方法使用網頁層級指定最為有效。運算單元層級指定目標只應用於註冊不同或不包含所有運算單元的鍵/值。

請注意,您可以同時使用版位和網頁層級指定目標,如設定指定目標範例中所述。強烈建議您先在網頁層級設定指定目標,再視情況套用版位層級覆寫。這種方法不僅可有效運用 GPT API,還能簡化程式碼,並能維持網頁上所有設定的指定目標的明確心理模型。

正確使用單一請求架構

單一請求架構 (SRA) 是一種 GPT 請求模式,可將多個廣告版位的要求併入單一廣告請求中。這能確保網頁採用的競爭排除項目和路障型廣告能正常放送。因此,如果您的頁面運用了這些技術,建議您啟用 SRA 並瞭解如何正確使用 SRA。

在預設設定中,SRA 會在您第一次呼叫 display() 時要求網頁中定義的所有廣告版位 (如果已停用初始載入功能,則會呼叫 refresh())。因此,建議您在第一次呼叫 display() 之前,先在文件的 <head> 中定義所有網頁的廣告版位。延遲載入可以與這個方法搭配使用,以確保不需捲動位置下方的版位不會立即載入

使用 SRA 之前,請務必先設定所有廣告版位 (例如,設定指定目標、排除類別等),然後再呼叫 display()。只有在這個時間點之前設定的值才會包含在初始 SRA 要求中。

錯誤 - SRA 請求不包含廣告版位設定

<html>
  <head>
    <meta charset="utf-8">
    <title>Single Request Architecture Example</title>
    <script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
    <script>
      window.googletag = window.googletag || {cmd: []};
      var adSlot1, adSlot2;

      googletag.cmd.push(function() {
        // Define ad slot 1.
        adSlot1 = googletag
            .defineSlot('/6355419/Travel/Europe/France',[728, 90], 'banner-ad-1')
            .addService(googletag.pubads());
        // Define ad slot 2.
        adSlot2 = googletag
            .defineSlot('/6355419/Travel/Europe/France',[728, 90], 'banner-ad-2')
            .addService(googletag.pubads());
        // Enable SRA and services.
        googletag.pubads().enableSingleRequest();
        googletag.enableServices();
      });
    </script>
  </head>
  <body>
    <div id="banner-ad-1" style="width: 728px; height: 90px;">
      <script>
        googletag.cmd.push(function() {
          // This call to display requests both ad slots.
          googletag.display(adSlot1);
        });
      </script>
    </div>
    <div id="banner-ad-2" style="width: 728px; height: 90px;">
      <script>
        googletag.cmd.push(function() {
          // This call to display has no effect, since both ad slots have already
          // been fetched by the previous call to display.
          // Targeting configuration for ad slot 2 is ignored.
          adSlot2.setTargeting('test', 'privacy');
          googletag.display(adSlot2);
        });
      </script>
    </div>
  </body>
</html>

正確:廣告版位設定已納入 SRA 請求

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Single Request Architecture Example</title>
    <script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
    <script>
      window.googletag = window.googletag || {cmd: []};
      var adSlot1, adSlot2;

      googletag.cmd.push(function() {
        // Define ad slot 1.
        adSlot1 = googletag
            .defineSlot('/6355419/Travel/Europe/France',[728, 90], 'banner-ad-1')
            .addService(googletag.pubads());
        // Define and configure ad slot 2.
        adSlot2 = googletag
            .defineSlot('/6355419/Travel/Europe/France',[728, 90], 'banner-ad-2')
            .setTargeting('test', 'privacy')
            .addService(googletag.pubads());
        // Enable SRA and services.
        googletag.pubads().enableSingleRequest();
        googletag.enableServices();
      });
    </script>
  </head>
  <body>
    <div id="banner-ad-1" style="width: 728px; height: 90px;"></div>
    <div id="banner-ad-2" style="width: 728px; height: 90px;"></div>
    <script>
        googletag.cmd.push(function() {
          // This call to display requests both ad slots with all
          // configured targeting.
          googletag.display(adSlot1);
        });
      </script>
  </body>
</html>

調整廣告大小

定義廣告版位時,不建議您考慮可放送的最大廣告大小,也可以考慮能容納相同空間的較小尺寸。一般來說,您在定義廣告版位時所指定的大小就越多,可放送到更多廣告。這有助於提高供應率和收益。