img by Coba

How to Implement Landing Page Hit Tracking in ASP.NET (Part 1)

In this series, I will show you how to implement page tracking using a SQL Server and ASP.NET system. This will work for any version of SQL Server and any version of the .NET Framework as well as C# or VB. This tutorial requires: SQL Server, Visual Studio (or any .NET-enabled IDE), and the Microsoft Enterprise Library 3.x/4.x.

Over at our IT training videos site, we track all hits to our landing pages. You know what a landing page is, right? It's a page specifically targeted to help someone perform an action. As an advertiser, you funnel all of your traffic to landing pages. For example, we might advertise for the term SharePoint training videos using the following ad:

Headline: SharePoint 2007 Training

Copy: Learn SharePoint 2007 right now with our online SharePoint tutorials


Now we wouldn't really want to dump someone who clicked such an ad onto the main home page - we want to share with them how great the tutorials are, how easy, etc, etc... So we use a landing page that tells people all about our site and has a specific goal: to get them to watch a free video.

Now that you have a basic idea of landing pages, let's get to the concept of how to track landing page hits. First - let's understand why we want to track hits:

  1. We want to be able to trace a specific purchase back to a specific ad and/or landing page
  2. We want to track effectiveness of ads and page elements

This is basic website optimization 101, right? Easy stuff - the kind of thing that Perry Marshall might teach (hint, hint...).

Now, on to the tutorial...

Tracking Users

To track this information from start to finish requires only a few items - first we need a table to store our user info; something like this:


Next up, we need to store our landing pages - something like this:


To understand the above terms, let's take a url like this: Let's dissect it:

  • QueryString - the part of the url after the page:
    • ?an=TechUrbia&source=blog
  • AbsolutePath - the page and path to the page
    • /VideoTutorials/E-Learning/3/Sql-Server-Training-Videobooks.aspx
  • AbsoluteUri
    • The entire url

Now you have two choices:

  1. You can manually enter in your landing pages
  2. You can dynamically enter in your landing pages when a user browses to that page

I prefer #2!

The LandingPage Class

I love to use the Microsoft Enterprise Library classes for working with databases and logging - so you'll need those installed to get the code samples to work for you. Get it here:

Now - to get started:

Step 1: Create a new SQL Server database. Execute the commands below in that database. This will create the two tables, "Users" and LandingPage" that we will start out with:

    Name nvarchar(255) NOT NULL,
    Email nvarchar(512) NOT NULL
CREATE TABLE dbo.LandingPage(
    AbsolutePath nvarchar(512) NOT NULL,
    AbsoluteUri nvarchar(1024) NOT NULL,
    QueryString nvarchar(512) NULL,
    AddDate datetime NOT NULL DEFAULT GETDATE()

Now - savvy users might be wondering, "Why don't you tie a UserId to a LandingPageId? How do I know when a user hits a particular landing page?" We're getting there...

In Part 2, we'll explore and expand our database design as well as explain our decision making process. On to Part 2...

scott whigham
grant moyle
chad weaver
recent comments
  • madhubabu.chinta: hi its wonderful. But i have another requirement i read more