HTML code added in 1*1 pixel creative ad on Google Tag Manager not displaying on the page

让人想犯罪 __ 提交于 2021-01-29 18:45:28

问题


I have created 1*1 pixel creative on Google Ad Manager and added following code.

Hello world

So after this we get the following script tag and div tags which i have added in my sample HTML code.

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Hello GPT</title>
    <script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
<script>
  window.googletag = window.googletag || {cmd: []};
  googletag.cmd.push(function() {
    googletag.defineSlot('/21795367156/Hindsight_ThesSource_Poc', [1, 1], 'div-gpt-ad-1585827491123-0').addService(googletag.pubads());
    googletag.pubads().enableSingleRequest();
    googletag.enableServices();
  });
</script>
  </head>
  <body>
    <!-- /21795367156/Hindsight_ThesSource_Poc -->
<div id='div-gpt-ad-1585827491123-0' style='width: 1px; height: 1px;'>
  <script>
    googletag.cmd.push(function() { googletag.display('div-gpt-ad-1585827491123-0'); });
  </script>
</div>
  </body>
</html>

So it is supposed to render the Hello World, but it is not rendering on page.


回答1:


The declared dimension of the adslot is 1x1. It means GPT is generating a 1x1 iframe. So even if your html ad "Hello World" is called, is stays encapsulated in a 1x1 google ad iframe. Here are few workarounds you could apply to succeed in visualizing your html ad on the page.

Please note these workarounds are only compatible with a setup without safeframe enabled (see here).

1) Use javascript to built your html ad in the parent DOM : From your ad iframe, you can interact with the main page DOM (parent page), so you could inject your html code ad in the parent page DOM. Example :

<script>
//built your html creative
var myCreative = document.createElement('h1');
    myCreative.innerHTML = 'Hello World';

//target where to inject
var parentTarget = top.document.body;

//append your html creative to your targeted element
parentTarget.appendChild(myCreative);
</script>

2) Use javascript to resize your google ad iframe : If you need to keep your creative within its iframe, you could then choose to resize the generated google ad iframe with javascript. Example :

<!--my html creative (rendered for 728x90 display) -->
<h1>Hello World</h1>

<script>
//get the google ad iframe id
var frameId = window.frameElement.id;

//resize iframe from parent DOM
top.document.getElementById(frameId).width = 728;
top.document.getElementById(frameId).height = 90;
</script>

3) Declare other dimensions to your adslot : One adslot can accept multiple sizes (see here). Then you could declare 1x1 and 728x90 sizes to this adslot so it can display one or the other. It really depends on what you want to do with the 1x1 (usually used for page takeovers / skins or third party scripts that could interact with the page to render external adnetwork ads).

4) Use an image : Most of the time, your creative will not be an HTML code but an image. If you upload an image creative that doesn't match the used size (1x1), you can force the adslot to get the uploaded image real size and resize the iframe.

Hope this helps.



来源:https://stackoverflow.com/questions/60991463/html-code-added-in-11-pixel-creative-ad-on-google-tag-manager-not-displaying-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!