Google AdSense JavaScript – Introduction

The Google AdSense Sandbox uses standard JavaScript code to display Google AdSense ads in various formats. The various parameters are passed through google_* variables and the ads are rendered through the google_ad_request_done function.

The following snippet explains the working of the Google AdSense code:

<script type="text/javascript">

// The unique ID of the AdSense publisher
  google_ad_client='ca-digitalinspiration';
   
// Return ads in JS or XML format?
   google_ad_output='js';

// When the Ad Test parameter is ON, advertisers aren't charged
   google_adtest = 'on';

// Request ads in different formats separated by commas
// If Flash or HTML (Rich Media) is unavailable, Image Ads may be returned
   google_ad_type='text,image,flash,html';

// The URL where users can report offensive Google Ads
   google_feedback='on';

// Specify the language and encoding of Google Ads
   google_language='en';
   google_encoding='utf8';

// How may ads should be returned (max value is 20)
   google_max_num_ads='10';

// The country of the visitor (Google Ads are geo-targeted)
// google_gl may also be replaced with google_country
   google_gl = 'US';

// See Google ads targeted at a particular website, enter the page_url
   google_page_url='http://www.labnol.org';

// For contextual ads, use the google_kw parameter with matching set to broad.
   google_kw='computer';
   google_kw_type='broad';
   
// JavaScript function to display Google Ads 
  function google_ad_request_done(google_ads) {
     
// If no ads were found, return;    
    if (google_ads.length==0) {      
      return;        
    } else {
      for(i=0;i<google_ads.length;++i) {     

// Code to display the Google Ads
// google_ads[i].url = URL of the advertiser's landing page
// google_ads[i].line1 = Line 1 (for Google Text Ads - CPC)
// google_ads[i].line2 = Line 2 (for Google Text Ads - CPC)
// google_ads[i].line2 = Line 3 (for Google Text Ads - CPC)
// google_ads[i].visible_url = The domain of the advertiser
     }
   }
   
   return;
  }   
&lt;/script>

&lt;script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
&lt;/script>