gazette
|
|
Issue # 207 (11-17-2003)
Pay To Play Is Here To Stay
Marketing your Web site using the search engines has moved, rather quickly, from "Hit or Miss" Optimization into a much more market driven set of options. Does the ability to paying the engines to get what you want level the playing field, or further divide the big guns from the mom and pops ?
|
|
Coders Corner
|
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.
|
Read the Coders Corner section from the
Last Issue or in the
Following Issue
JimWorld Member comments and feedback ...
Add your own comment ....
|
Sponsored Links
|