How to Implement Landing Page Hit Tracking in ASP.NET (Part 1)- by Scott Whigham on January 23, 2009 8:57 AM
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:
- We want to be able to trace a specific purchase back to a specific ad and/or landing page
- 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...
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: http://www.learnitfirst.com/VideoTutorials/E-Learning/3/Sql-Server-Training-Videobooks.aspx?an=TechUrbia&source=blog. Let's dissect it:
- QueryString - the part of the url after the page:
- AbsolutePath - the page and path to the page
- The entire url
Now you have two choices:
- You can manually enter in your landing pages
- 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: http://msdn.microsoft.com/en-us/library/cc467894.aspx
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:
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...