How to fix googletag.defineSlot was called without a matching googletag.display call.

I got this error “googletag.defineSlot was called without a matching googletag.display call.” when changing out my Google AdSense tags for DoubleClick for Publishers. I’m using the Google Publisher Tag (asynchronous) option which requires you to put a block of code in the header of each page and another block into the body.

The thing is, I’ve actually had to put multiple blocks of code into the header of my page since I have three ads per page and the second section of the header code is specific to each ad unit. This is where the problem emerges. Each time you click the “Generate Tags” button in DFP the div-gpt-ad-#############-0 number changes… and this has to match in the header and body blocks of code.

What happened to me that caused the issue was, I clicked “generate code” multiple times and was pasting in different div-gpt-ad-#############-0 numbers in the header js and the body js. These numbers need to match. So I just updated the header code to match what I had in my body and then used the Google Publisher Console to validate the ad placements.

To get the Google Publisher Console working all you have to do is append ?google_console=1 to the end of your URL and then click Ctrl+F10 and you’ll see a little diagnostic panel appear (screenshot below). Before I did the fix described above I was getting two errors (one for each number that was mismatched.

Pro tip, if you want to combine the second javascript call in the header of your page (if you run multiple DFP ads like I do) you can just bring up the ad ID for each as follows, this example shows three ad ID’s:

<script type='text/javascript'>
googletag.cmd.push(function() {
googletag.defineSlot('/########/ad1-name-300x250', [300, 250], 'div-gpt-ad-#############-0').addService(googletag.pubads());
googletag.defineSlot('/########/ad2-name-300x250', [300, 250], 'div-gpt-ad-#############-0').addService(googletag.pubads());
googletag.defineSlot('/########/ad3-name-300x250', [300, 250], 'div-gpt-ad-#############-0').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>