1

I am using adsesne code in my angularjs application. On the first load of application ads are working fine when I switch content dynamically I get this error.

Exception in queued GPT command TypeError: Cannot read property 'addService' of null site:stackoverflow.com.

This is the script which I load inside my div.

<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('/28379801/MWBanner320x50', [320, 50], 'div-adlocation').addService(googletag.pubads());
    googletag.enableServices();
  });
</script>
<!-- /28379801/MWBanner320x50 -->
<div id='div-adlocation' style='width: 320px; height: 50px; margin:auto'>
  <script>
    googletag.cmd.push(function() { googletag.display('div-adlocation'); });
  </script>
</div>

Any possible work around using angularjs?

Ali Wahab
  • 482
  • 6
  • 13

1 Answers1

3

I had the same issue and saw your post. Only after two weeks I found out by accident that you get the same error if you define the slot twice with the same adUnitPath. Maybe you have the same issue.

Solution

Make sure that the adUnitPath is define only once. The easiest way to check this for me was to console.log(<the adUnitPath>) with every googletag.defineSlot(...) call. In the screenshot you can see that two attempts are made to definer the same slot. However, this is not possible because the adUnitPath must be unique.

Example of the error and the double define action