Printer Friendly Version
Email this thread to a friend
|
Simple Hit counter (In: Coding & Databases - PHP, ASP, Perl, etc.)
Featured Web Site Template |
|
Reflects user activity within the last 5 minutes
|
|
| Member |
Message |
jcokos
Staff
Joined: Eons Ago
# Posts: 145
|
Posted: 2003-Nov-18 00:42
Let's work this week on a really simple application that will help you to better gauge the success of your paid marketing efforts. In a future Gazette issue, as well as in an article series on JimWorld.com, we'll get more advanced, but for now, let's get you up and running with a very basic ROI tracking system that will help you to track and calculate your ROI.
First, let's look at the 2 basic things we need to know.
- How many people are coming to my Web site from these campaigns
- How many of them bought my product/service
Addressing item #1, logging your visitors is easy using PHP. First, add the code snippet below to the VERY TOP of your index.php file. This will intercept the "c" query string variable coming in from with your visitors from your various campaigns. For example, when bidding at Overture, link people not to http://www.yourdomain.com, but http://www.yourdomain.com?c=overture. Similarly, use c=adwords for your Google Adwords links, c=inktomi for your Inktomi PFI listings, etc. You can use c=ANYTHING you like, to match whatever campaign you're trying to track. This simple PHP script will create a separate text log for each campaign to track the total incoming unique hits:
<?php
$campaign_id = $_GET['c'];
$prevcookie = $_COOKIE['logged'];
// If this is the first time this person has come here
// from this campaign, log it as a new hit
if ( $campaign_id && ! $prevcookie ) {
// Set a cookie called "logged" so we know to skip it, and tag
// that with the campaign ID, so that we know who to attribute the sales to.
setcookie( 'logged', $campaign_id, time()+(86400*365) ); /* expire in 1 year */
// Generate the filename
$filename = "./" . $campaign_id . ".hits";
// Get the number of hits to this campaign so far
if ( ! file_exists($filename) ) { $num_hits = 0; }
else { $num_hits = implode("", file($filename)); }
// Add One
$num_hits++;
// Open the file, rewrite the count and save it
$tmpfile = fopen($filename,"w");
fwrite($tmpfile,$num_hits);
fclose($tmpfile);
}
?>
Now, on the flip side, whenever a user buys your product or service, we need to see if that user happens to be someone that we've logged earlier as coming in from one of your paid campaigns. What we'll be doing is looking for a cookie called "logged," which will contain the campaign ID that they came in from initially, and if it exists, log a sale for that campaign. The trick here is that because we're reading from a cookie, this PHP snippet has to be run from a page on the same domain that we originally set the cookie from. Typically, what this means, is that after your user has made the purchase, your shopping cart program or merchant program will send them back to a "Thank You" type of page on your main domain. This is the page to place the following code:
<?php
$campaign_id = $_COOKIE['logged'];
// If this person came in originally from a campaign, log the sale
if ( $campaign_id ) {
// Generate the filename
$filename = "./" . $campaign_id . ".sales";
// Get the number of hits to this campaign so far
if ( ! file_exists($filename) ) { $num_hits = 0; }
else { $num_hits = implode("", file($filename)); }
// Add One
$num_hits++;
// Open the file, rewrite the count and save it
$tmpfile = fopen($filename,"w");
fwrite($tmpfile,$num_hits);
fclose($tmpfile);
}
?>
Now, for every campaign that you run, you have a ".hits" and a ".sales" file on your server. You can easily view these files to see how many hits each campaign got, how many sales they each generated, and then calculate your ROI accordingly. In future articles on this topic, we'll make this tracking system more advanced by tracking keywords, referring URLs, and going "SQL" with it, to allow for big-time growth and better reporting.
|
 |
You are not permitted to post messages in this forum or topic, because of one or more of the following reasons:
- You have not yet logged in, or registered properly as a member
- You are a member, but no longer have posting rights.
- This is a private forum, for which you do not have permissions.
If you are a recent member, it's possible that you simply have not yet confirmed your account. Please
check your email for a message entitled 'JimWorld Forums: Confirm Your Account' and follow the instructions
contained within.
If you cannot find this message, click here to Re-Send it.
|
If you are still experiencing problem, please read the
Login Assistance
Article for some advice on what may be causing your login not to work properly.
|
Switch to Advanced Editor and ...
Create a New Topic
or Reply to this Thread
|
|