Page-level ads are a new feature of Adsense that is available since today.
It's in Beta right now.
It allows to display transition ads or bottom attached ads for mobile displays.

This is a feature request to support those ads

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
  (adsbygoogle = window.adsbygoogle || []).push({
    google_ad_client: "ca-pub-0123456789abcdef",
    enable_page_level_ads: true
  });
</script>

This should be placed in <head> or after <body>

Comments

dalu created an issue. See original summary.

dalu’s picture

Issue summary: View changes
jcnventura’s picture

Status: Active » Postponed

Still not available to me.

vitchy’s picture

Available for me, it would be great to add support for them.
Implementation guide https://support.google.com/adsense/answer/6245305?hl=en&ref_topic=1307438

jcnventura’s picture

Still not available to me. Someone needs to provide a patch, and then other people need to test and review it, since I (the maintainer) can't.

fenstrat’s picture

Version: master » 7.x-1.x-dev
Status: Postponed » Needs review
StatusFileSize
new2.74 KB

The attached patch has Page-level ads working for me. Would be good to get some feedback from others (@vitchy / @dalu).

  1. Included as part of adsense_managed and defaulting to disabled. It needs to be enabled at admin/config/services/adsense/managed and also in your AdSense account.
  2. These page-level ads don't seem to have a non async option, so hence it's always included via async as per Google's recommendations.
  3. I considered modifying adsense_display() to output the ad (which should have enabled the reuse of the enabled/page matching checking) however adsense_display() is too focused on an ad format (which page-level ads do not have, rather they're a simple boolean option).
emilorol’s picture

Just to confirm patch #6 is working like a charm.

Thank you.

fenstrat’s picture

@emilorol Great. In that case could you mark this as RTBC?

jwintx’s picture

Status: Needs review » Reviewed & tested by the community

Patch #6 is working great for me, as well. Marking RTBC as requested.

jcnventura’s picture

Status: Reviewed & tested by the community » Needs work

I'm pretty sure this is not adding the async tag to the script.. And why call drupal_add_js on the script by itself? This would make better sense as part of the inline script.

The good news is that this seems to have come out of beta, and it's now available to me as well.

fenstrat’s picture

Status: Needs work » Needs review
StatusFileSize
new2.7 KB
new710 bytes

@jcnventura Well noticed, I'd missed the async tag. Seeing as #1664602: Allow attributes to be passed to drupal_add_[css|js] (SRI) is still not fixed for D7 then yes, putting it inline seems the only option.

jwintx’s picture

Patch #11 results in the following error in the browser console:
Firefox - SyntaxError: expected expression, got '<'
Chrome - Uncaught SyntaxError: Unexpected token <

for this line:
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

fenstrat’s picture

StatusFileSize
new3.04 KB
new1016 bytes

@JWinTX hmm sorry about that, helps if I properly test patches! #11 resulted in a nested <script> tag.

The attached fixes that issue. As I noted in #11 drupal_add_js() doesn't (yet) support async so I've used drupal_add_html_head() as a work around.

jwintx’s picture

Patch #13 is working just fine for me. Thanks @fenstrat!

fenstrat’s picture

Status: Needs review » Reviewed & tested by the community

Great, thanks @JWinTX, marking as RTBC based on your feedback as this seems to address @jcnventura concerns in #10.

jcnventura’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the work on this @fenstrat. Even though setting to RTBC on your own patches is not kosher.. But then again, I've done that also, so who am I to judge?

I only did a couple minor change, that simplify maintaining parity with the ad code, and avoids calling both drupal_add_js and drupal_add_html_head.. I bundled everything together exactly as provided by Google, and just called drupal_add_html_head once.

But you should still be able to recognize your code.

fenstrat’s picture

Great, thanks @jcnventura. Cheers for the commit credit as well.

As for self marking as RTBC, yeah sorry about that. In my defence @JWinTX had already RTBC'd in #9, and gave positive feedback again in #14.

Fair call bundling everything into one drupal_add_html_head() call. Good catch removing the "BETA" status of Async and Page-level ads.

  • jcnventura committed 764808b on 8.x-1.x
    Issue #2563101: Support page-level ads (8.x)
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Vic96’s picture

Using this patch, can one prevent the page level ads from being shown on specific nodes?

fenstrat’s picture

@Vic96 The patch from #13 has already been committed. And no, sorry, this issue didn't add the ability to control where page level ads are displayed, that'd be a new featured to be added in a new issue.