Monday, May 2, 2016

How to set up Page-level AdSense ads in your blog

This article describes Page-level ads, a new type of AdSense advertisement which Google has recently introduced.   It includes how to set up these ads if you use Blogger, and some troubleshooting information about them.  

It also describes how to fix an error in the code which is supplied, which causes a message like "Attribute name "async" associated with an element type "script" must be followed by the ' = ' character".

What are Page Level AdSense ads

Google has recently introduced a new type of Adsense ad-units, which may be shown to people who visit a website using a mobile device (eg smartphone of tablet),

There are two types of Page-level ads:
  • Vignette ads:   When a visitor on your site clicks on a link to another page on you site, a vignette ad may be loaded as a full-page overlay which the user needs to close before they see the page which they navigated to.
  • Overlay ads:   these are smaller ads which show at the top or bottom of your screen, and which "stick" to the edge, so they seem to stay in place as the user scrolls up and down your site.   The visit may click on them in the usual way.

For Blogger users, these ads are only currently available if you have a full AdSense account: if you only have a hosted AdSense account, then you cannot get the code to install them.   But if you do have a full AdSense account (either because you have a custom domain, or because you signed up for AdSense before the "host AdSense account" option was introduced), they are attractive because they don't count towards the count of advertisement-units which you are allowed to display on each page.

They also only work if you have a mobile theme switched on for your blog, so that visitors who use a mobile device see mobile-optimised screen.

How to install AdSense Page Level ads in Blogger

Log in to your AdSense account.

Go to the My Ads tab

Turn on one or both of  Overlay or Vignette ads options.
(By default, they are both turned Off.    Click on the empty box beside the "0" to turn an option to  on:  in these controls, 0 means "off" and 1 means "on".)

Click the < > Get Code button.

Copy the code that is generated.

Switch to Blogger, and edit your theme in the usual way.

Find the text   <head>    (including the brackets).

On the very next line after <head>, paste in your code.

Optional - but highly recommended - add comments to clearly show what this code is for.   I usually use
and then the code goes in here ...
Preview the theme, and make sure it's working.
(See Troubleshooting section below if you get a message about   Attribute name "async" associated with an element type "script"    or similar.

Save the theme.

Job done!   This is all you need to do to enable page-levels ads for your blog:   you do not need to install gadgets to say where these ads go, because Google handles this for you.

How to see what page-level ads look like in your blog

Visit your blog using a smartphone or tablet.

Add the text   #googleads   at the end of the website address, so it changes from something like:
to something like:

After this, when you click on a link to move a different page in your blog,  a Vignette style ad will display - these are whole-page ads, which include a "close ad" button, like this:


Extra "src" text in the ad-code

Right now, there is a problem with the code that AdSense are providing.   I don't know if this is because Blogger doesn't understand a feature that AdSense is using, or if it's a genuine bug.    But if you see a message like this when you try to preview the theme:
Could not load theme preview: Error parsing XML, line 21, column 15: Attribute name "async" associated with an element type "script" must be followed by the ' = ' character.
then there's a very simple change that you have to make.

All you have to do is delete the "src" immediately after the word async.

So your code changes from like this:
<script async src="//"></script>
  (adsbygoogle = window.adsbygoogle || []).push({
    google_ad_client: "ca-pub-DONT-USE-MY-NUMBER-GET-YOUR-OWN-PUBLISHER-ID",
    enable_page_level_ads: true

to like this:
<script async ="//"></script>
  (adsbygoogle = window.adsbygoogle || []).push({
    google_ad_client: "ca-pub-DONT-USE-MY-NUMBER-GET-YOUR-OWN-PUBLISHER-ID",
    enable_page_level_ads: true

Different Page Level settings for different websites

If you are using Adsense across several different websites, then you may want to enable one of vignette or overlay ads on some sites, and a different option on others.

Currently, there is no way to do this:  you must choose one combination of:
  • No Page Level ads
  • Overlay ads only, no Vignette ads
  • No Overlay ads, but do show Vignette ads
  • Allowing Google to choose Overlay and/or Vignette ads

Stop Vignette ads being attached to some links

By default, any link to another page in your blog may have a Vignette ad attached to it.    However there may be some links which you specifically don't want this to happen to - for example if the user really needs to remember what was on the current page once the get to the next one.

You can prevent any Vignette ads being displayed when a user clicks a link by adding a tag to the link.

The tag to add is:

and you need to switch to Edit HTML (top left of the post-editor window) to add it.

This is an example link to another page on this blog which is prevented from having a Vignette ad, and this is the HTML code I've used to achieve this.
<a data-google-vignette=”false” href="">an example link</a> 

More help

Google have provided more information about Page level ads here.

Related Articles

Setting up a mobile theme for your blog

Editing your Blogger theme

Hosted AdSesne accounts for Blogger users

Share this Article


HTML link code:

BB (forum) link code:

Subscribe to Blogger-hints-and-tips

FeedBurner will send a confirmation message. Click the verify link in it to start your subscription.

Follow Me on Pinterest Subscribe to Blogger-HAT on Google + RSS subscription icon Follow BloggerHAT on Twitter

1 comment:

  1. This ad not show in blogger Default mobile template. How to show it?