【问题标题】:GPT googletag.content().setContent does not work for setting html contentGPT googletag.content().setContent 不适用于设置 html 内容
【发布时间】:2021-01-14 07:43:21
【问题描述】:

我正在尝试设置新元素的 html 内容,但是当我检查 slot.getHtml() 是否为我提供了 html 元素(设置如下)时,它显示一个空字符串。知道为什么会发生这种情况吗?

var slot = googletag.defineSlot('/1234567/sports', [160, 600], 'ozge')
  .addService(googletag.companionAds())
  .addService(googletag.pubads())
  .addService(googletag.content());

googletag.content().setContent(slot, '<h2>Custom content in ad slot.</h2>')

我用这个链接里的代码sn-p查看新定义的slot:https://gist.github.com/rdillmanCN/a70ec955d9a982127fefadabe8b898b5

【问题讨论】:

    标签: javascript google-ads-api gpt google-publisher-tag


    【解决方案1】:

    编辑: 根据详细的here,contentService 将很快被弃用(2022 年 3 月 29 日)。

    详细heregoogletag.content()用于手动设置插槽的内容。它在生成的 adcall iframe 之前将 html 内容添加到目标插槽 div :

    var slot = googletag.defineSlot('adpath', [728, 90], 'div-1')
    .addService(googletag.content())
    .addService(googletag.pubads());
    
    var content = '<a href="www.mydestinationsite.com"><img src="www.mysite.com/img.png"></img></a>';
    googletag.content().setContent(slot, content);
    

    HTML 结果:

    slot.getHtml() 将在生成的 iframe 中提取 html。如果它返回一个空字符串,则意味着您的广告位广告调用是空的。它不提取googletag.content(),而是提取google ad iframe innerHTML。这就是它返回空字符串的原因。

    警告:根据我的经验,googletag.content().setContent() 仅在 adcall 不返回任何内容(空 adcall)时才会设置所需的 html。只要显示横幅,您的 googletag.content() 就会被清除:

    据我了解,googletag.content().setContent() 用于设置 html 在您的 adcall 完成之前或您的 adcall 没有返回任何内容时显示。

    总结:slot.getHtml() 无法获取生成的广告 iframe 之外的任何内容。当广告调用返回空展示时,它会返回一个空字符串。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-25
      • 2015-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-06
      • 1970-01-01
      • 2023-02-21
      相关资源
      最近更新 更多