Click here to Skip to main content
11,928,786 members (51,927 online)
Click here to Skip to main content
Articles » Web Development » ASP.NET » Howto » Revisions
Add your own
alternative version

Tagged as


16 bookmarked

Integrate an ASP.NET website with Google Analytics

, 11 Feb 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
This article helps to track your web pages and internal links with the help of Google Analytics.
This is an old version of the currently published tip/trick.


This article helps to track your website pages and internal links with the help of Google Analytics. Google Analytics is used to track a website. We can get the following reports by configuring our site with Google Analytics.  

  1. How many people visited our site daily.
  2. Where they are going from our site.

    i.e, Tracking internal links of the page and click counts.

  3. Area wise reports.....etc. still we can get different type of reports using Google Analytic.


Steps to configure your website with Google Analytics.  

  1. Create a Gail Account . 
  2. Sign in here  
  3. After log in, click on Sign Up button displayed at ringside of the page. 
  4. Now a form get displayed. Here provide  provide your website name, your website URL ,Account Name other details.
  5. Finally click on Get Track ID button and then click on  i accept button.Now some java-script code will be displayed, which looks like
<script type="text/javascript"> 

var _gaq = _gaq || []; 

  _gaq.push(['_setAccount', 'UA-XXXXXXXX-X']); 


  (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);



Using the Code 

You just copy above generated script and  paste on the page you want track. For example if you want to track 3 pages in your website then you have to paste this script on three pages.

You have to paste the script just above the  end of body tag.



-------your design------ 

-----Here paste above generated the script--------  



The above stuff is for tracking your page.i.e We can get no.of people visited our page.

Steps to track outbound links in a page with Google Analytics.   

The links that redirects from our page to any other page are called as outbound links.If you want to track links with in the page then you have to fallow 2 steps..

  1. Paste the below script within the <head> tag  
<script type="text/javascript"> 

        function trackOutboundLink(link, category, action) {

    try {

                _gaq.push(['_trackEvent', category, action]);

            } catch (err) { }

         setTimeout(function() {

                document.location.href = link.href;

            }, 100);


  1. Call the function trackOutboundLink() from each and every link available in your page 


    suppose if your link is like 

    <a href="" ></a> 

    you just modify above link by adding a onclick event  

    <a href="" onclick="trackOutboundLink(this,
        'Outbound Links', ''); return false;"> </a> 


  1. Now you can watch all the reports by log in in to your account. 

         Sign in here:  

  2. You can't see reports immediately in Google analytics. It will take 24 hours to display all type of reports.  


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer PSPL
India India
No Biography provided

You may also be interested in...

Comments and Discussions

Discussions posted for the Published version of this article. Posting a message here will take you to the publicly available article in order to continue your conversation in public.
Questionusing GA in ashx handler ? Pin
kiquenet.com2-Nov-15 22:30
memberkiquenet.com2-Nov-15 22:30 
QuestionHow to show feeds/data of Google analytics in Website Pin
Abhishek Pant16-Jul-14 22:46
professionalAbhishek Pant16-Jul-14 22:46 
AnswerRe: How to show feeds/data of Google analytics in Website Pin
Abhishek Pant9-Dec-14 22:18
professionalAbhishek Pant9-Dec-14 22:18 
SuggestionNot an Article Pin
aspnet -i22-Jul-13 0:42
member aspnet -i22-Jul-13 0:42 
GeneralRe: Not an Article Pin
Pete O'Hanlon7-Oct-13 8:01
protectorPete O'Hanlon7-Oct-13 8:01 
GeneralVery Simple Pin
bandi-ramesh18-Feb-13 1:47
memberbandi-ramesh18-Feb-13 1:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151126.1 | Last Updated 11 Feb 2013
Article Copyright 2013 by ShaikAnwar
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid