AMPに対応してアドセンスを表示するようにしたら、β機能の連絡が来ていました。せっかくなので試してみたいと思います。
AMP対応したAdsense表示
まず、プラグイン「Ad inserter」で作った通常のAMP対応広告コードはこんな感じです。
ヘッダ部分
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <script> (adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-1234567890123456", enable_page_level_ads: true }); </script> [ADINSERTER AMP] <script async custom-element="amp-ad" src="https://cdn.ampproject.org/v0/amp-ad-0.1.js"></script>
冒頭部分
<!-- inarticle after title --> <ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-format="fluid" data-ad-layout="in-article" data-ad-client="ca-pub-1234567890123456" data-ad-slot="1234567890"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> [ADINSERTER AMP] <amp-ad layout="fixed-height" height=100 type="adsense" data-ad-client="ca-pub-1234567890123456" data-ad-slot="1234567890"> </amp-ad>
途中と記事下
<!-- Boxed Ad --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-1234567890123456" data-ad-slot="1234567890" data-ad-format="auto"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> [ADINSERTER AMP] <amp-ad layout="fixed-height" height=100 type="adsense" data-ad-client="ca-pub-1234567890123456" data-ad-slot="1234567890"> </amp-ad>
<!-- matched content area --> <ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-format="fluid" data-ad-layout="in-article" data-ad-client="ca-pub-1234567890123456" data-ad-slot="1234567890"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> <ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-1234567890123456" data-ad-slot="1234567890"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> [ADINSERTER AMP] <amp-ad layout="responsive" width=300 height=250 type="adsense" data-ad-client="ca-pub-1234567890123456" data-ad-slot="1234567890"> </amp-ad>
auto-adsコード
ヘッダー内に
<script async custom-element="amp-auto-ads" src="https://cdn.ampproject.org/v0/amp-auto-ads-0.1.js"></script>
を入れ、HTMLボディ内の最初に
<amp-auto-ads type="adsense" data-ad-client="ca-pub-1234567890123456"></amp-auto-ads>
を入れるだけという簡単仕様です。
auto-adsが働かない・・
設定してみたものの、うまく動作してくれません。数分待ってくださいとあるので、待ってみましたが全く表示してくれません。
通常バージョンのAdsenseと共有できないのかと思い、削除してみましたがやはり働いてくれません。
検索してみたところ、JSONのエラーがブラウザ上で検出されるという記述が結構出てきます。
amp-auto-ads config xhr failed: SyntaxError: Unexpected end of JSON input

deltimeのエラーと同じくAMP for WPを停止してみましたが、AutomatticのAMPプラグインだけだとアドセンスの挿入スクリプト自体が削除されるため、追加のプラグイン(もしくはAMPプラグインの改変)なしでは無理のようです。
Ad Inserterは働いているのが確認できるため(スクリプトではなくHTMLコメントなら挿入されたままになるため)少なくともWordpressのAMP for WPプラグインを使用している限り逃れられないのかもしれません。
上記フォーラムでも、エラーなく表示されているし通常のAdsenseコードとも共存できているという報告もあるので、Google側のエラーではないのかもしれません。
アドセンスのAuto-Adsはモバイル端末以外では無効になるはずなので、PCのブラウザではエラーになるのかもしれませんが、モバイル端末でも表示できていないので、今のところ使えないようです。一度、JoomlaのAMPページでも試してみたいですね。
コメント