Showing posts with label adsense. Show all posts
Showing posts with label adsense. Show all posts

Tuesday, July 2, 2013

An async script for AdSense tagging

Author Photo
By Michael Kleber, Ads Latency Team

As part of our ongoing quest to make the Web faster, we're happy to share a new tag that publishers can use to request AdSense ads. This new tag is built around the modern <script async> mechanism, ensuring that even if a slow network connection makes our script slow to load, the surrounding web page can fully render. A few other benefits come along for the ride, like the ability for ad slot configuration and placement to live entirely in the DOM.

A decade ago, when AdSense was born, asking publishers to copy-and-paste a bit of HTML including <script src=".../show_ads.js"> was the natural way to get our ads to appear in that spot on a web page. But as web speed evangelist Steve Souders has explained, that kind of blocking script tag is a "Frontend Single Point of Failure": if a server or network problem makes that script unavailable, it could prevent the whole rest of the page from appearing. That's why modern best practices emphasize loading most resources asynchronously. These guidelines are even more important for sites loaded on mobile devices, where dropped HTTP connections are far too common.

Anatomy of the new tag:
  1. A script, which only needs to appear once on your page, even if you have multiple ads. It is loaded asynchronously, so it is safe and most efficient to put it near the top.

    <script async src="http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
  2. A particular DOM element, inside of which the ad will appear. We use attributes of this element to configure the properties of the ad slot.
  3. A call to adsbygoogle.push(), which instructs us to fill in the first unfilled slot.
    <ins class="adsbygoogle"
    style="display:inline-block;width:300px;height:250px"
    data-ad-client="ca-pub-xxxxxxxxxxxxxxxx"
    data-ad-slot="yyyyyyyyyy"></ins>
    <script>
    (adsbygoogle = window.adsbygoogle || []).push({});
    </script>
The ad block size is based on the width and height of the <ins>, which can be set inline, as shown here, or via CSS. Other configuration happens through its data-* properties, which take the place of the old (and manifestly not async-friendly!) google_* window-level variables. If your Google Analytics integration required setting google_analytics_uacct="UA-zzzzzz-zz" before, then you should now add the property data-analytics-uacct="UA-zzzzzz-zz" to the <ins> instead, for example.

The classic show_ads.js tag is a battle-tested warrior with years of experience, running on millions of sites around the web. The upstart adsbygoogle.js is in beta and may not be as robust yet. Give it a try and please let us know if you run into any problems. But if you were jumping through hoops before to keep ads from blocking your content, try this out straight away. We think you'll approve.


Michael Kleber is the Tech Lead of the Ads Latency Team at the Google office in Cambridge, MA. Before coming to Google to make the Internet faster, he spent time as a math professor working on representation theory and combinatorics, as a computational biologist working on genome assembly, and on machine learning for speech recognition.

Posted by Scott Knaster, Editor

Friday, December 16, 2011

Introducing AdSense Management Services in Google Apps Script

Author Photo
By Silvano Luciani, Developer Programs Engineer, AdSense API Team

Starting today, the AdSense Management API is available as part of AdSense Services in Google Apps Script. This means that you’ll be able to automate your AdSense reporting across Google products using a JavaScript cloud scripting language to do things like:
  • Create AdSense performance reports for your AdSense accounts in a Google spreadsheet.
  • Create a chart based on your AdSense reporting data and display it in a Google spreadsheet.
  • Embed your scripts in a Google Sites page, for instance to import a chart.
  • Use triggers to schedule the execution of your scripts, for instance to periodically update the chart imported in the Google Sites page.
spreadsheet with embedded chart

You can start using the service by checking out the reference documentation, which also contains some sample scripts, and by reading this tutorial, which implements the use cases mentioned above.


Based in London, Silvano Luciani joined Google in 2011 to make the AdSense API developers happier people. Before that, he has worked in Finland, Italy, Spain and the UK, writing web based configuration management tools for ISPs, social networks, web based training materials, e-commerce apps and more. He has recently discovered that he loves charts, and has finally started to play the drums in the London’s office music room. If you can call what he does "playing the drums".

Posted by Scott Knaster, Editor






Thursday, March 17, 2011

Your Web, Half a Second Sooner

At Google we’re constantly trying to make the web faster — not just our corner of it, but the whole thing. Over the past few days we’ve been rolling out a new and improved version of show_ads.js, the piece of JavaScript used by more than two million publishers to put AdSense advertisements on their web pages. The new show_ads is small and fast, built so that your browser can turn its attention back to its main task — working on the rest of the web page — as soon as possible. This change is now making billions of web pages every day load faster by half a second or more.

The old show_ads did lots of work: loading additional scripts, gathering information about the web page it was running on, and building the ad request to send back to Google. The new show_ads has a different job. It creates a friendly (same-origin) iframe on the web page, and starts the old script with a new name, show_ads_impl, running inside that iframe. The _impl does all the heavy lifting, and in the end the ads look exactly the same. But there’s a substantial speed advantage: many things happening inside an iframe don’t block the web browser’s other work.

How much of an effect this has depends on context: a page with nothing but ads on it isn’t going to get any faster. But on the real-world sites we tested, the latency overhead from our ads is basically gone. Page load times with the new asynchronous AdSense implementation are statistically indistinguishable from load times for the same pages with no ads at all.

The new show_ads is a drop-in replacement for the old one: web site owners don’t need to do anything to get this speed-up. But these dynamically-populated friendly iframes are finicky beasts. For now, we’re only using this technique on Chrome, Firefox, and Internet Explorer 8, with more to come once we’re sure that it plays well with other browsers.

And what if you’ve built a page that loads AdSense ads and then manipulates them in exotic ways not compatible with friendly iframes? (This is the web, after all, land of “What do you mean that’s ‘not supported’? I tried it, and it worked!”) You can set “google_enable_async = false” for any individual ad slot to revert to the old blocking behavior. But if your site loads ads in some tortuous way because you were looking for latency benefits, consider giving the straightforward invocation of show_ads.js a whirl. Because now, we’re fast.

Wednesday, May 19, 2010

Even more ways for developers to optimize with AdSense

Last year, we announced that developers can earn revenue by showing ads in two of our products, the GoogleBar for Local Searches on a Google Map and the Custom Search element for site-restricted and other curated searches. Today, we're happy to announce two new AdSense product updates to help monetize your website.

AdSense for search ads only
AdSense for search allows publishers to add Google search functionality to their site and monetize from search ads. The Custom Search element is a prime example. However, despite the power and flexibility of the element, you may want to show ads next to your own non-Google search results. With AdSense for search ads only, developers can now include AdSense for search ads on their pages, paired with their own homegrown search results.

AdSense for Ajax
The other side of AdSense is ads targeted to content on your site. In this case, developers turn to AdSense for content. But what if your content isn't crawlable by search engines or uses Ajax to dynamically update without a page refresh? Now you can deliver AdSense for content ads via AdSense for Ajax, which allows you to give hints about your uncrawlable content. Even better, it allows you to refresh the ads dynamically when there is a context change.

If your site is a good fit for either, or both, of these offerings, sign-up for AdSense for Ajax or AdSense for search ads only today! Learn more about them from the AdSense Blog post.

Monday, February 22, 2010

Introducing Google's DoubleClick For Publishers API

Today, we announced the next generation of our ad serving technology for online publishers, the new DoubleClick for Publishers (DFP) from Google. We are pleased to announce that the new version of DFP comes with a modern API that enables publishers and third-parties to customize and extend the product.

The new API is available to publishers who use DFP, as well as to third-parties and vendors who would like to build applications on top of DFP. A growing community of developers are already working on sales, order management, workflow and data visualization tools. We've incorporated feedback on the existing DART for Publishers API and believe the new API is a significant step forward. It uses SOAP, a standard and widely-adopted messaging technology that uses HTTP requests to transmit and receive XML data between your client and our servers. This means you can use it with virtually any programming language of your choice. We have a wealth of public documentation available online and there are numerous code samples and client libraries ready for you to download.

To learn more about the new API, there are a few places to get started:

We are looking forward to working with you and seeing what you build!

Wednesday, June 24, 2009

AdSense for Mobile Applications Beta

Are you developing free iPhone or Android applications? With our new beta product - AdSense for Mobile Applications, you can monetize your mobile applications by showing contextually targeted ads and/or placement targeted ads alongside your application content. We provide you with iPhone and Android SDKs and example applications that request and display AdSense ads. Our SDKs also support DoubleClick ads.

You can show 320x50 text and image ads linked to HTML webpages in your application. These ads are targeted to the keywords that you send us in the AdSense (or DoubleClick) ad request. The keywords must be relevant to your application content. If your application content is loaded from a webpage that is customized for iPhones and Android handsets, then you can also send us the webpage URL for us to target ads. The ads may also be placement targeted which means an advertiser can specifically target to your application.

Our iPhone SDK is compatible with iPhone OS 3.0, and our Android SDK is compatible with Android 1.5 SDK. The SDKs include a library that can be linked in to your application which exposes methods to fetch and show ads. You must place a maximum of one ad per screen at the top or bottom (see the screenshot from the Backgrounds iPhone application). When a user clicks on the ad in your application, you can choose whether the user should view the advertiser's website in iPhone Safari or a full-screen UIWebView on the iPhone. For Android applications, our API defaults to opening the advertiser's website in the native browser.

To get started with monetizing your iPhone or Android application, sign up today on the AdSense for Mobile Applications website. We can't wait to have you join our beta network!


Wednesday, March 18, 2009

Updated GoogleBar features new UI and targeted sponsored results



The GoogleBar, a control in the Maps API to allow users to search the map for local businesses, landmarks and points of interest, has just launched a new version. In addition to a greatly improved UI, the new GoogleBar includes advertising targeted to the user's searches. This new feature will improve the user experience by providing targeted and relevant sponsored results, and you can benefit by sharing in the revenue of including these results on your site. You can see the new GoogleBar, together with ads, below:


As shown above, the new version of the GoogleBar contains advertising. Profiting from the advertising personally is as easy as signing up for an AdSense account and including your AdSense publisher ID when you create the GoogleBar. See the recent Maps API Blog post for details. Whether you already have a map on your webpage or not, it only takes a few lines of code to embed a fully searchable map into your site - the GoogleBar documentation will tell you everything you need to know.

The GoogleBar is built upon our low-level Local Search Control. For those interested in peeking under the covers, check out the Local Search Control documentation and Code Playground examples.

Questions or comments? Please visit the AJAX API and Maps API discussion groups.