views:

1316

answers:

4

i want to add tracking to my website. I saw google analytics which seems to track what i need.

So do i stick the google analytics snippet in each page, in a master page, just in my default page? what is the best practice here to get the best metrics.

+6  A: 

The google analytics code snippet has to be on every page you want to track.

Easiest is to put the code into the master page(s) if you use them.

Otherwise put it on every page, or put it into a user control which you can include on the relevant pages or include it using a server-side include, e.g:

<!-- #include file="file_containing_google_analytics_code.js" -->
M4N
+1  A: 

We use Google Analytics, and have incorporated this into our base page - although our first implementation was done with an HttpModule.

I like the base page approach, because it is a common area for some like-minded tasks. It additionally moves the viewstate to the bottom of the form, removes whitespace, etc.

joseph.ferris
+1  A: 

It depends on the structure of your site. If you have a small number of Master Pages it makes sense in there, or you could put some code to emit it in a base class that you inherit all your pages (or master pages) from, or if you have a standard footer control that you use on all pages you can put it in there.

I generally wrap it in a Placeholder in ASP.Net and have some code the switches it on/off from a web.config setting so it doesn't appear when the site is running in test/UAT/dev machines.

Steven Robbins
+1  A: 

You should take a look here : http://blog.sb2.fr/post/2008/12/21/Google-Analytics-WebControl-for-ASPNET.aspx

Yoann. B
why not just put the code in the master page. whats the value of the webcontrol
ooo