ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • adsbygoogle.push({});} 관련 error 해결해보기
    IT-Information/Blog-operation 2022. 5. 25. 12:21

    개요

    블로그를 운영하다보니 애드센스 승인을 받고 게재를 했으나 광고가 않나오는 경우가 생각보다 많은것같아 알아보게 되었음

     

    관련 코드를 열어보니 해당 에러를 찾음

    adsbygoogle.push() error : Only one AdSense head tag supported per page. The second tag is ignored.

    이런류의 에러는 태그를 넣었을때 나오지 않자 다른 위치에 태그를 옮기면서 잔류된 태그가 삭제되지 않아서 발생함

    기존 태그를 삭제하면 문제없이 광고가 나옴

     

    adsbygoogle.push() error : Only one 'enable_page_level_ads' allowed per page.

    head  태그 안의 태그를 하나로 줄였지만 계속 나오는 에러인 경우 수동과고를 넣을때 script 태그를 포함해서 넣고 있을 가능성이 있음

    수동광고를 넣을 때 <script...></script>태그 부분을 삭제해주면 콘솔의 에러가 사라짐

     

    애드센스를 적용할 때 head 태그에  처음 넣는 태그는

    <head>
    ....
    //광고 코드//
    <script async src="https://paged2.googlesyndication.com/paged/js/adsbygoogle.js?client=ca-pub-xxxxxxxxxxxxxx"
      crossrigin="anonymous"></script>
    ....
    </head>

    수동 단위 광고 복붙 할때 코드

    <ins class="adsbygoogle"
      style="display:block; text-align:center;"
      data-ad-layout="in-article"
      data-ad-format="fluid"
      data-ad-client="ca-pub-xxxxxxxxxxxxx"
      data-ad-slot="xxxxxxxxxxxxx"></ins>
      <script>
      (adsbygoogle = window.adsbygoolge || []).push({});
      </script>

    자바스크립트의 코드는 위부터 차례대로 읽어 내려 오면서 코드를 동작시키는데 같은 코드가 식별되면 한번만 인식을 하게 됨 중복 될 경우 불필요한 과정이 반복되어 로드에 영향을 미치기 때문에

     

     

    이런류의 에러는

    adsbygoogle.push() error: Fluid responsive ads must be at least 250px wide : availableWitdth=0", name: "TagError"...

    Adsense 코드를 표시하려는 부분의 폭이 부족하여 나타남

    <div class="adsense example">
     <script async src="https//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
     <ins class="adsbygoogle"
     style="display:block"
     data-ad-format="fluid"
     data-ad-layout-key="-xxxxxxxxxx"
     data-ad-client="ca-pub-xxxxxxxxxxxxxxxx"
     data-ad-slot="xxxxxxxxxxxxx"></ins>
     <script>
    (adsbygoogle = window.adsbygoogle || []).push({});
    </script>
    </div>

    이 경우 대처법은 단순히 에드센스 코드를 설치한 상위 태그의 width를 지정하여 처리할 수 있음

    .adsense {
      width: 400px;
      }

    그럼에도 해결되지 않을때는 html트리 구조의 더 상위 태그 문제를 확인해야함

     

    adsbygoogle.push() error: No slot size for availableWitdth=0", name: "TagError"...

    이런류의 에러는 광고를 표시하려할 때 상위 태그의 사이즈를 가지고 올 수 없는 에러로 사이드바에서 표시하도록 설정했는데 블로그 화면에는 사이드바가 표시 되지 않은 경우 나타남

     

    이런 경우에는

     <script>
    (adsbygoogle = window.adsbygoogle || []).push({});
    </script>

    이렇게 된 부분을

    <script>
     window.onload = function() {
      (adsbygoogle = window.adsbygoogle || []).push({});
     }
     </script>

    로 수정을 진행함

    window.onload를 사용해서 실행을 하면 DOM이 구축된 후 실행됨. 이 해결방법이 적용되는 경우 페이지 내에 다른 Ajax 처리가 많이 사용되고 있어서 애드센스 코드의 로드가 잘 실행되지 않는 경우에 해당함

     

     

Designed by Tistory.