Integrating google analytics with your web application

Google analytics is one of the best APIs of google in recent days. Google analytics gives the analytical reports related to page visit which is very much important for the site owner. This article explains how to incorporate this API with your application.

In this article we will see how to use google analytics for the web application. Before we begin lets know a bit about 'Google Analytics'.

Google Analytics
According to Wikipedia Google Analytics is a free service offered by Google that generates detailed statistics about the visitors to a website.

Now to avail the service and integrate it to your application you have to be the owner of your site as you have to access the files stored in the server.This service is available for all sort of web applications(i.e; ASP.Net, Java, PHP etc).

Now lets integrate it with an application. For this article i am using a web portal developed by myself. The site address is which is a govt. site for the National Board of Revenue, Bangladesh.

Step 1
Go to the following address

Step 2
Click on 'Create an account'. If you already have a google account then enter your email and password. If not then create an account by clicking on 'SIGN UP'.

Step 3
After logging in you can see 'Sign Up' button at the right side; Click on that. This is a free service so no need to pay anything or enter credit card information.

Step 4
Fill up the sign up form with proper information. use a short profile name and enter your website address in the 'Website's URL' box and fill all the rest info and create the account.

Step 5
Now you can see a code with the title 'Paste this code on your site'. Paste the code on each page of your site. if you use a master page then paste the code on your master page. Just as an info the code looks like this

<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-34761313-1']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);


Step 6
once you paste the code on your webpage then the 'Tracking Status' will be 'Installed' or else it will be 'Tracking Not Installed'

Step 7
Now your analytics is ready for your application to show the statistics reports of the visitors.
One thing to remember: This service needs around 24 hours to capture your site information. You can export report in pdf format anytime.

Now here are few points that can help you to understand the report.
Visits by Traffic Type

  • Direct : When user directly clicks the link (

  • Organic: When user gets the link via search engines (Google, Yahoo, Bing etc)

  • Referral: When user gets the link from any other web site as reference.

Visits and Page views by Mobile

This counts the visit using mobile phones. Now a single visit may have multiple page views. Getting into is considered as a visit and browsing the pages of the site will be counted as page views.

Avg Visit Duration

This is the average visit duration for the website. The inactive duration time limit is 30 minutes. That means if a user stays idol for 30 minutes on the site then the user's next click after 30 minutes idol time will be considered as another visit, but if he clicks before 30 minutes then it will be considered as same visit.

I hope this article will help all to integrate this cool API with your application. Also I have attached a report just to give an idea about how the report will look like


  • Analytical report generated by Google analytics (44199-14841-Analytical-report-generated-by-Google-analytics.pdf)
  • Comments

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: