广告最佳做法

将 Google 发布商代码 (GPT) 库集成到 熟悉了 最佳做法,您就可以 开始发出广告请求下面,我们将介绍一些 在配置和使用广告位时应注意这些事项, 尽可能降低对广告效果的影响。

优先考虑“重要”广告位

并非所有广告位都具有相同的价值。例如, 通常更“重要”比那些 用户滚动到用户视野范围内(非首屏)后才会看到这类广告 可见度和创收情况因此,请务必 仔细考虑您网页上每个广告位的相对重要性 优先加载最重要的广告位。

尽早加载首屏广告

应以最高级别:在网页加载后立即可见的广告 优先级。建议您在自己应用的 <head> 中定义这些槽 并在网页加载过程中尽早请求这些注释。这个 有助于确保这些广告尽早加载(最大限度地提高可见度) 它们不会不必要地降低初始网页加载速度。

延迟加载非首屏广告

对于需要滚动到用户视野范围内的广告,抓取和呈现应 被推迟,直到广告位即将进入视口为止。这是一个过程 称为延迟加载单独延迟加载 会优先请求和呈现位于 更有可能被观看这有助于优化网页加载性能 以节省浏览器有限的资源,这在 带宽和 CPU 通常都受到严格限制的移动环境。

刷新广告而不刷新网页

在很多情况下,最好甚至需要替换 广告位的当前广告内容。在这些情况下,最好使用 GPT 库的 刷新功能以动态方式执行此操作。 这可避免整页刷新,并可让您精确控制条件 一个或一组槽会在其下更新。

刷新广告位时,请务必熟悉并遵守 refresh() 最佳实践。 不当刷新广告可能会导致效果问题和负面影响 影响可见率

有效定位广告

配置键值对定位时,请务必小心 请考虑使用广告位级定位还是网页级定位。对于共享的键值对 网页级定位(通过 PubAdsService setTargeting() 方法。广告位级 定位应仅用于注册那些 包含在所有广告位中。

请注意,广告位级和网页级定位可同时使用,如 设置定位示例。强烈建议 请先在网页级配置定位条件,然后再应用广告位级 并仅在必要时进行替换。这种方法不仅能有效利用 还可以简化代码并帮助维护 针对网页上配置的所有定位条件提供一个明确的思维模式。

正确使用单一请求架构

单一请求架构 (SRA) 是一种 GPT 请求模式, 将对多个广告位的请求打包到一个广告请求中。这样可以确保 为网页配置的竞争性排除规则和包版 非常荣幸因此,如果您的网页使用了这些技术,建议您: 启用 SRA 并了解如何正确使用。

在其默认配置中,SRA 会请求 display()(或 refresh(),如果 初始加载已停用)。因此 建议您在网页的 <head> 中指定网页的所有广告位 文档,然后再首次调用 display()延迟加载可与上述方法结合使用 确保位于非首屏的广告位 不会立即加载

使用 SRA 时,请务必全面配置所有广告位(例如, 设置定位条件、类别排除等),然后再对 display()。只有在此时间点之前配置的值才会包含在 初始 SRA 请求

不正确 - SRA 请求中未包含广告位配置

<html>
  <head>
    <meta charset="utf-8">
    <title>Single Request Architecture Example</title>
    <script src="https://securepubads.g.doubleclick.net/tag/js/gpt.js" crossorigin="anonymous" async></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 src="https://securepubads.g.doubleclick.net/tag/js/gpt.js" crossorigin="anonymous" async></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>

优化广告尺寸

在定义广告位时,您不仅要考虑 但也可以尺寸较小,以适应同一空间。在 一般而言,您在定义广告位时指定的尺寸越多, 才能投放到该广告单元这就意味着更高的填充率 收入增加。