GPT googletag.content().setContent 不适用于设置 html 内容

GPT googletag.content().setContent does not work for setting html content

提问人:Ozge Cokyasar 提问时间:1/14/2021 更新时间:3/2/2022 访问量:1790

问:

我正在尝试设置新元素的 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>')

我使用此链接中的代码片段来查看新定义的插槽:https://gist.github.com/rdillmanCN/a70ec955d9a982127fefadabe8b898b5

javascript google-ads-api google-publisher-tag

评论


答:

1赞 rabsom 1/15/2021 #1

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

如此所述,用于手动设置插槽的内容。它将 html 内容添加到目标插槽 div 中,然后生成 adcall iframe :googletag.content()

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 结果:

enter image description here

slot.getHtml()将提取生成的 iframe 中的 HTML。如果它返回一个空字符串,则表示您的插槽广告为空。它不会提取 ,而是提取 google ad iframe innerHTML。这就是为什么它返回一个空字符串。googletag.content()

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

enter image description here

据我了解,用于将 html 设置为在您的广告调用完成之前显示,或者如果您的广告调用不返回任何内容可显示。googletag.content().setContent()

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