I have built several web sites and applications in the past, and I have to admit that I am a data junkie. If there is user data or any other data to be captured when someone uses my application or visits a web page, then I like to capture it (I can always delete it later). Of course, you can use a third-party Javascript plug-in for web site analytics (which I also use), but I like to gather information myself.
Most of the pages that I have written use Perl – even for the home page when possible (yes, I am “old school”, and my lack of using modern Perl code is evident). Each time a user clicks to go to another page, I like to capture as much information as possible about their visit.
Perl, PHP and other scripting languages have ways for you to capture the information about your web page visitor. For Perl, this simple script will tell you a lot of information the visitor and your server. In order for this script to work, you have to call it from a web browser.
|
I took the above script and placed it in my webserver’s cgi-bin directory, made it executable, and opened it in my browser. I added a “?test=1234567″ at the end of the script so that you could see the value of the REQUEST_URI variable.
Here is the web output:
|
This is a lot of information, and you probably don't need or want most of it. You will want to select information that you can actually or potentially use. For example, if you want to capture their computer info, HTTP referral and remote IP address, in your Perl script. you would create variables in your Perl script like this:
|
You can then insert this information into your MySQL database, along with an "action" of what they are doing on the page. I create an activity table to record what the user is doing on various web pages. If they are visiting your dashboard page, you might set their "activity" to "Dashboard Visit". I also include a date and time stamp. A sample activity table might look like this:
|
If the web site requires a user name and password to login, I also use cookies - which is usually how I retrieve the Customer_Serial_Number and/or any other personal information that they have provided to me. Or, if they fill out a "contact us" form, you can save their name and information in a cookie to be retrieved when they visit your web site later. Just be sure to set the cookie expiration date to a date in the future, or to have the cookie never expire.
Here is a quick way to create a cookie in Perl. In this example, we are creating two cookies, Customer Serial Number and Customer Email, both of which we have retrieved from MySQL after they logged into the site:
|
Here are the definitions for the cookie variables (information from http://perldoc.perl.org/CGI/Cookie.html.
|
There are a couple of other variables that you can use, so refer to the Perl cookie page for more information.
Deciding which information that you want to keep is up to you. Then, you can simply create a MySQL table to store this information. When a user registers on your site, you can store their email address in a cookie that never expires, so the next time they login, you can auto-populate the login form with their email address.
You can also redirect mobile users to a web page that is specific to their screen size. For example, when I connect to this script with my iPhone, I can tell that the connection is from an iPhone via the HTTP_USER_AGENT:
|
However, my iPhone's remote IP address is almost useless:
|
So, your Perl script can then detect that this user is on an
iPhone, and then it can redirect them with a meta refresh tag to a version of the web page
specifically designed for the iPhone screen resolution.
One web site that I designed required a user to login to get past the home screen. Once they logged in, I would grab their serial number from the MySQL database, and then create a cookie with the serial number value. With each page they visited, I would send a few bits of information to my MySQL visitor database.
Here is part of the Perl script that I would use to record customer information: (information on inserting data into MySQL via Perl may be found in an earlier post).
|
Once you have enough customer data, you can figure out the paths that your customers are taking when visiting your site. Do they login and go straight to the forum page? Or if you have a web store, do they go straight to the clearance page? Or are they logging in and then doing nothing? If a customer never visits a certain page, what can you do to drive them to visit that page? Third-party tools can provide good overall web site analytical information, but nothing beats being able to see one particular customer's activity on your own.
-----------------------------------------
Tony Darnell is a Principal Sales Consultant for MySQL, a division of
Oracle, Inc.
MySQL is the world's most popular open-source database
program. Tony may be reached at info [at] ScriptingMySQL.com and on LinkedIn. |