Search code examples
c#asp.net-coregoogle-ads-apigoogle-ad-manager

Google Ads APM shows null


Recently I try to add google ads to my personal website. Base on google documentation I can Use Auto ad or Unit ad and I decided to go with Unit ad, I created 3 different type of ads called

  1. SquareAds
  2. VerticalAds
  3. HorizontalAds

Each ad has two different type of codes. First one called HTML and second one called AMP.

First of all when I checked the code for each type of ad that I created I could not find any difference between them. Second of all I tried to show ads in my partial views in C# using HTML section. In my page I added 3 different section to shows ad but only one of them works and sometimes no one.

I decided to change the HTML code to AMP

I added following code to head

<script async custom-element="amp-ad" src="https://cdn.ampproject.org/v0/amp-ad-0.1.js"></script>

And this code to each section in my body:

<div class="col-md-3">
<div class="panel-body">
    <amp-ad width="100vw" height=320
            type="adsense"
            data-ad-client="ca-pub-xxxxx"
            data-ad-slot="5555555555"
            data-auto-format="rspv"
            data-full-width>
        <div overflow></div>
    </amp-ad>
</div>

But when I publish my website and upload it to the server that shows nothing.

checked google documentation and google this issue but I could not find anything.


Solution

  • I just found the answer to my question

    If you have more than one ads in your page you have to change your scripts to a loop to convert your amp to iframe like this

    //Google Ads
    [].forEach.call(document.querySelectorAll('.adsbygoogle'), function () {
        (adsbygoogle = window.adsbygoogle || []).push({});
    });