Signup · Login
Stardeveloper.com  
Home · Tutorials · Forums · ASP.NET Newsletter Application · Web Hosting Plans · Faisal Khan's Blog · Contact
Search Stardeveloper.com
Newsletter
Enter your email address to receive full length articles at Stardeveloper:


Article Categories
.NET  .NET
  ASP (16)
  ASP.NET (43)
  ADO (16)
  ADO.NET (11)
  COM (6)
  Web Services (4)
  C# (1)
  VB.NET (3)
  IIS (2)

J2EE  J2EE
  JSP (15)
  Servlets (9)
  Web Services (1)
  EJB (4)
  JDBC (4)
  E-Commerce (1)
  J2ME (1)
  Products (1)
  Applets (1)
  Patterns (1)

Main Category  Other
  Website Maintenance (3)
Log In
UserName Or Email:

Password:

Auto-Login:

Hosted by Securewebs.com
 
Home : .NET : ASP.NET : Tracking Referring Domains and URLs to our Website using ASP.NET
 
Read full length articles at Stardeveloper using Twitter Follow on Twitter Facebook Facebook fan page Email Get Articles via Email RSS Get Articles via RSS Feed
	<asp:SqlDataSource ID="SqlDataSource2"
	SelectCommand="SD_Tut_GetMonthlyReport"
	SelectCommandType="StoredProcedure"
	ConnectionString="<%$ ConnectionStrings:SD_Tut_TrackerDB %>"
		runat="server">
		<SelectParameters>
			<asp:QueryStringParameter
				Name="ForYear" QueryStringField="forYear"
				Type="Int32" />
		</SelectParameters>
	</asp:SqlDataSource>

	Unique Users and Page Views in the year: 
	<b><asp:Label ID="YearLabel1" runat="server" /></b><br /><br />

	<asp:GridView ID="GridView2" DataSourceID="SqlDataSource2"
		AutoGenerateColumns="false"
		Width="700" runat="server">
		<HeaderStyle BackColor="Beige" />
		<Columns>
			<asp:HyperLinkField HeaderText="Month"
				DataNavigateUrlFields="Year,Month"
				DataNavigateUrlFormatString=
				"report.aspx?forYear={0}&forMonth={1}"
				DataTextField="Month" />
			<asp:BoundField HeaderText="Unique Users"
				DataField="UniqueUsers" />
			<asp:BoundField HeaderText="Page Views"
				DataField="PageViews" />
		</Columns>
	</asp:GridView><br />

The last report displays the unique users and page views on a daily basis.

	<asp:SqlDataSource ID="SqlDataSource3"
	SelectCommand="SD_Tut_GetDailyReport"
	SelectCommandType="StoredProcedure"
	ConnectionString="<%$ ConnectionStrings:SD_Tut_TrackerDB %>"
		runat="server">
		<SelectParameters>
			<asp:QueryStringParameter
				Name="ForYear" QueryStringField="forYear"
				Type="Int32" />
			<asp:QueryStringParameter
				Name="ForMonth" QueryStringField="forMonth"
				Type="Int32" />	
		</SelectParameters>
	</asp:SqlDataSource>

	Unique Users and Page Views in the month: 
	<b><asp:Label ID="MonthLabel" runat="server" />/<asp:Label
	ID="YearLabel2" runat="server" /></b>
	<br /><br />
		
	<asp:GridView ID="GridView3" DataSourceID="SqlDataSource3"
		Width="700" runat="server">
		<HeaderStyle BackColor="Beige" />
	</asp:GridView>

report.aspx.cs
We will now code the back-end class file for report.aspx page. Open Notepad and create a new text file. Copy and paste following text in it and then save it as "report.aspx.cs":

using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Report : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
	SqlDataSource2.SelectParameters["ForYear"].DefaultValue =
		DateTime.Now.Year.ToString();

	SqlDataSource3.SelectParameters["ForYear"].DefaultValue =
		DateTime.Now.Year.ToString();
	SqlDataSource3.SelectParameters["ForMonth"].DefaultValue =
		DateTime.Now.Month.ToString();

	if (Request.QueryString["forYear"] == null)
	{
		YearLabel1.Text = DateTime.Now.Year.ToString();
		YearLabel2.Text = YearLabel1.Text;
	}
	else
	{
		YearLabel1.Text = Request.QueryString["forYear"];
		YearLabel2.Text = YearLabel1.Text;
	}

	if (Request.QueryString["forMonth"] == null)
		MonthLabel.Text = DateTime.Now.Month.ToString();
	else
		MonthLabel.Text = Request.QueryString["forMonth"];

	DateTimeLabel.Text = DateTime.Now.AddHours(
		Convert.ToInt32(
			ConfigurationManager.AppSettings[
				"SD_Tut_TimeOffset"])).ToString();
    }
}

Explanation
All this class does is to set few properties of the components used in the report.aspx page. If year and month values are not given in the query string, then it uses current year and month. Lastly, we set the date and time to be displayed on the report.aspx page after adding the time zone offset hours to it. That's all.

referringdomains.aspx
Having looked at how simple the code of report.aspx was, we'll quickly move through the remaining two ASP.NET pages which will generate reports. The first of these two is referringdomains.aspx. Open Notepad and create a new text file. Then copy following text and paste in it and then save it as "referringdomains.aspx" in the same folder where you kept report.aspx.

<%@ Page Language="C#" AutoEventWireup="true"
	CodeFile="referringdomainsandurls.aspx.cs"
	EnableViewState="false" Inherits="_ReferringDomainsAndURLs" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Tracker Referring Domains Report</title>
    <style>
		body { font-family:Verdana; font-size:85%; }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div align="center">
    
	<a href="report.aspx">
		<b style="font-size:large">
			<asp:Label ID="HeaderLabel"
				Text="<%$ AppSettings:SD_Tut_WebSiteName %>"
				runat="server" /> Tracker Report</b></a><br />
			(DateTimeAfterOffset: <asp:Label ID="DateTimeLabel"
				runat="server" />)
	<br /><br />
		
	<div align="center"><a href="report.aspx">Main Page</a> · 
	Referring Domains · 
	<a href="referringurls.aspx">Referring URLs</a></div>
	<br />
    
	<asp:SqlDataSource ID="SqlDataSource1"
		SelectCommand="SD_Tut_GetYearlyReportForReferringDomains"
		SelectCommandType="StoredProcedure"
		ConnectionString="<%$ ConnectionStrings:SD_Tut_TrackerDB %>"
		runat="server"></asp:SqlDataSource>

	<asp:GridView ID="GridView1" DataSourceID="SqlDataSource1"
		AutoGenerateColumns="false" Width="700" runat="server">
		<HeaderStyle BackColor="Beige" />
		<Columns>
			<asp:HyperLinkField HeaderText="Year"
				DataNavigateUrlFields="Year"
		DataNavigateUrlFormatString="referringdomains.aspx?forYear={0}"
				DataTextField="Year" />
		<asp:BoundField HeaderText="No. of Referring Domains"
				DataField="NoOfReferringDomains" />
		<asp:BoundField HeaderText="Referrers"
				DataField="Referrers" />
		</Columns>
	</asp:GridView><br />

Previous ( 10 Gone )( 4 Remaining ) Next

Comments/Questions ( Threads: 4, Comments: 8 )
    Contains 1 or more replies by the Author of this Article.
    Contains 1 or more replies by Faisal Khan.

  1. trying to follow instruction but ran into this error which I tried to gogle out to no avail
  2. How to track Users visit time and Page Viewstime on web pages ( 1 Reply ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  3. Maybe I am dumb ( 1 Reply )
  4. Great tutorials ( 2 Replies ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.

Post Comments/Questions

In order to post questions/comments, you must be logged-in. If you are not a member yet, then signup, otherwise login. Once you login then come back to this page and you'll see a form right here which will allow you to post comments/questions.

Please note, one of the benefits of signing up is to be notified immediately by email everytime you receive a reply to the thread you have subscribed.

 
© 1999 - 2010 Stardeveloper.com, All Rights Reserved.