Set up the code to track your AdSense sites in Analytics

To see AdSense reporting in Analytics for a webpage, that webpage must contain:

In addition, if a webpage is not on your primary property, you must add a third piece of code:

Please note that the order of the code snippets is very important. The AdSense-Analytics code must be placed above the AdSense ad code.

We recommend that you place the snippets in your webpage's HTML in the following order:

  1. The Analytics tracking code, placed just before the closing </head> tag
  2. The AdSense-Analytics code snippet just after the <body> tag (for non-primary properties only)
  3. The AdSense ad code, between the <body> and </body> tags
Example code implementation

<!DOCTYPE html>

<html>

<head>

<title>Webmaster quality guidelines - AdSense Help</title>

<script type="text/javascript">

  var _gaq = _gaq || [];

  _gaq.push(['_setAccount', 'UA-XXXXX-Y']);

  _gaq.push(['_trackPageview']);

  (function() {

    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;

    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';

    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

  })();

</script>

</head>

<body>

<script>

 window.google_analytics_uacct = "UA-accountnumber-propertyindex";

</script>

<h1>Webmaster quality guidelines</h1>

<p>In order to ensure a good experience for users and advertisers, publishers participating in the AdSense program are required to adhere to the webmaster quality guidelines. These guidelines provide many tips for creating sites that help Google find, index, and rank your site. In general, following these tips will help you to provide a positive experience for your users. The guidelines are quite extensive so we’ve highlighted some important information below:</p>

<script type="text/javascript"><!--

google_ad_client = "ca-pub-xxxxxxxxxxxxxxxx";

/* Homepage - 728x90 */

google_ad_slot = "2644871640";

google_ad_width = 728;

google_ad_height = 90;

//-->

</script>

<script type="text/javascript"

src="http://pagead2.googlesyndication.com/pagead/show_ads.js">

</script>

</body>

</html>