Archived topic
Adding Google Publisher Tag to my website
1 reply · Started by Grant on November 30, 2021
Hello,
I am trying to run ads on my website with a company. They have provided the following code:
Header
<!-- Start GPT Tag -->
<script async src='https://securepubads.g.doubleclick.net/tag/js/gpt.js'></script>
<script>
window.googletag = window.googletag || {cmd: []};
googletag.cmd.push(function() {
var mapping1 = googletag.sizeMapping()
.addSize([1024, 0], [[728, 90]])
.addSize([640, 0], [[320, 50]])
.addSize([0, 0], [[320, 50]])
.build();
googletag.defineSlot('/22491887924/iafrika.org/generic', [[728,90],[320,50]], 'div-gpt-ad-8601431-1')
.setTargeting('pos', ['L_Top'])
.defineSizeMapping(mapping1)
.addService(googletag.pubads());
googletag.defineSlot('/22491887924/iafrika.org/generic', [[300,250]], 'div-gpt-ad-8601431-2')
.setTargeting('pos', ['MPU_Mid'])
.addService(googletag.pubads());
googletag.defineSlot('/22491887924/iafrika.org/generic', [[728,90],[320,50]], 'div-gpt-ad-8601431-3')
.setTargeting('pos', ['L_Bot'])
.defineSizeMapping(mapping1)
.addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.pubads().collapseEmptyDivs();
googletag.enableServices();
});
</script>
<!-- End GPT Tag -->
Body
<!-- GPT AdSlot 1 for Ad unit 'iafrika.org/generic' ### Size: [[728,90],[320,50]] -->
<div id='div-gpt-ad-8601431-1'>
<script>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-8601431-1'); });
</script>
</div>
<!-- End AdSlot 1 -->
<!-- GPT AdSlot 2 for Ad unit 'iafrika.org/generic' ### Size: [[300,250]] -->
<div id='div-gpt-ad-8601431-2'>
<script>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-8601431-2'); });
</script>
</div>
<!-- End AdSlot 2 -->
<!-- GPT AdSlot 3 for Ad unit 'iafrika.org/generic' ### Size: [[728,90],[320,50]] -->
<div id='div-gpt-ad-8601431-2'>
<script>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-8601431-2'); });
</script>
</div>
<!-- End AdSlot 3 -->
for me to add but I'm not sure:
- What the best what to do it is with Generate Press Premium
- If there is anything else I need to consider
I have looked in the forum but couldn't see anything similar. Please let me know.
Thanks,
Grant
Hi there,
you can use the Hook Element:
https://docs.generatepress.com/article/hooks-element-overview/
For adding code to the header you would select the Hook: wp_head
For the codes going into the body - that really depends on where you want them to be displayed. If you want them auto inserted into posts or other areas of the site then its best to use the Ad Inserter plugin: