Today we have made a change to the Layouts Template language to improve Google Analytics coverage. We have added the following includable section.
<b:includable id='google-analytics' var='blog'> <b:if cond='data:blog.analyticsAccountNumber'> <script type='text/javascript'> var _gaq = _gaq || []; _gaq.push(['_setAccount', '<data:blog.analyticsAccountNumber/>']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = (document.location.protocol == 'https:' ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> </b:if> </b:includable>
This now allows you to include analytics tracking on your blog by adding the following include call to your template, preferably right before the close body tag so it doesn’t delay the visible page being rendered:
<b:include name='google-analytics' data='blog'/>
For more details on the benefits you get from using Google Analytics, see this post on Blogger Buzz. If you have any questions about this new functionality, please join in the discussion on the Blogger Developer Group.
<html> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> <script> // Request an API Key for the Blogger API from // https://code.google.com/apis/console/ var apikey = "YOUR API KEY HERE"; // You can find the blogId in the HTML source of a blog var blogId = "2399953"; // When the document is loaded $(document).ready(function() { // Make a JSONP request for the Posts on the Blogger Buzz blog $.ajax({ url:"https://www.googleapis.com/blogger/v2/blogs/”+ blogId+”/posts?key="+apikey, dataType: "jsonp", success: function(data, textStatus, jqXHR) { var items = []; // Construct a chunk of HTML for each post // containing the Post title, content, and a // link to the post author. $.each(data.items, function(index, value) { items.push("<h2>"+value.title+"</h2>"+value.content+ "<p>Posted by <em><a href='"+value.author.url+"'>"+ value.author.displayName+"</a></em></p>"); }); // And finally, append the generated content to the page body. $(items.join('')).appendTo('body'); } }); }); </script> </html>
It is important to understand that this release is the first step on a journey of discovery, as we work with all of you to build a better API for using Blogger. Please review the documentation, and join in the discussion on Blogger Developer Group and let us know what we can add to the API to make it more useful for you!