Your own Referrer Tracking with MT 2.21
Published 6 years, 2 months ago in Moveable Type, design + devBack on September 4th, I wrote about adding ‘live referrer tracking’ to this website using a bit of Perl and PHP. I pointed at a few sources, but didn’t provide any real details on how to do it, so I’m going to try and explain what I did, and how to do it yourself in this article… so that hopefully it takes you less time than it took me.
This all assumes that you know a little about PHP, and nothing about Perl (which is my case, though I’d say, I know a little more than ‘a little’ about PHP, but I’m by no means an expert). It also assumes that you aren’t afraid to break your MT installation, and won’t hold me liable for anything you do to your webserver, or self throughout this process.
1. Download Waxy Backlink v0.5. (Right Click: Save File to Disk… on your computer somewhere, the desktop is a good place).
2. Read these directions and these directions at waxy.org to familiarize yourself with the script’s stock instructions, but don’t get bent around the axle on them.
3. Login to your website using telnet, and navigate using cd to the directory where you want to story your ‘referrer log files’ stored. Type:
mkdir backlink
That will make a directory where you’ll keep your referrer log files that this script will produce.
4. We need to make that directory ‘world writeable’ so that the processes that control Perl on your webserver can write to that directory. Type:
chmod 777 backlink
(This might be considered a security risk by some folks, but to me, it’s not all that big of a risk… as the only think you’ll be keeping in that directory are log files or referrers, which you’ll be displaying publicly anyways, so big deal right?)
5. Open backlink.txt, and then modify the backlink.txt file line that says
my $backlinkdir = '/usr/local/apache/htdocs/backlink';
So that it points to your backlink log file diretory on your server (you should specify the full path to the server directoy).
6. If you’re going to use PHP to include this file then change the line that says
my $php = 0;
to say
my $php = 1;
7. You might want to adjust the number of referrers that are displayed now, and the number of incoming hits it takes prior to displaying the referrer now, and if so, change these lines:
# The total number of links you want to display for a single entry
my $max_links = 10;
# The minimum number of hits before a link is displayed
my $min_hits = 0;
So that the numers are appropriate (I’d wait to do this if I were you, till you know its working).
8. You’re almost done with this file for now. Save, and quite your text editor (I really hope you’re using BBEdit for this).
9. Now that the file is saved, change the name to backlink.cgi and then upload it to your website (it doesn’t matter where you put it really, but the same directory as your index file for your weblog is probaly the best place).
Now we just need to include the file, and check to see if its working.
10. Go back to waxy.org’s instructions on how to include via PHP here. See Brad Choate’s comment about ‘double quotes’. Copy this:
<?php echo `perl /path/to/cgi/backlink.cgi "$HTTP_HOST" "$SCRIPT_NAME" "$HTTP_REFERER"`; ?>
And paste it into a spare text document on your computer. Now, in Movable Type’s template interface, you need to select your ‘Main Template’ and paste that line in the sidebar somewhere, just so you can see if it works. If you’re still using the stock template for MT (v2.21), then you can copy this and paste my code:
<div class="sidetitle">
<a name="referrers"></a>Referrers
</div>
<div class="side">
<?php echo `perl /path/to/cgi/backlink.cgi "$HTTP_HOST" "$SCRIPT_NAME" "$HTTP_REFERER"`; ?>
</div>
But you’ll need to modify the ‘/path/to/cgi/backlink.cgi’ part so that it’s the full path on your webserver to your backlink.cgi file.
11. Save your Main Template, then, check to see that you’re template’s ‘output file’ field has a filename in it ending with ‘.php’ like ‘index.php’ if you’re working on your Main Template. Enter an output file name of ‘index.php’ if there isn’t one, and save the template again.
12. Now rebuild your site using MT’s rebuild function (you really only need to rebuild the index page).
13. Browse to your new index page (if you dindn’t have an index.php file in your Main Template before all of this, you’ll probably have to type it in manually, as you likely still ahve an index.html file that’s getting the traffic to your domain/directory).
You’re looking to see that where you’re including the call to the backlink.cgi file, there aren’t any visible errors right now.
14. Create a link to your index.php file on a domain other than your own (might need a buddy to help you out there). Click on that dummy link, then reload your index.php file to see if the referrer shows up. It should work fine, if you’ve done everything properly, like checked your template output filename, chmod’d the directory of your referrer log files, and not screwed up the .cgi file that you created.
If it’s working, then you should delete your index.html file now. You don’t need it (and don’t want it) if it’s winning in the Apache configs over index.php (apache controls which is served to the visitor first).
15. If its not working, check your work… you probably screwed something up by following the directions I wrote above (at an ungodly hour mind you), or your webserver doesn’t support PHP or Perl. I’m definitely not the guy to help you there, though, I doubt its a Perl issue if you’ve got MT working
Lastly. If this didn’t work, get me on iChat/AIM: johnenglerworkin — I’ll answer you when I can.
You can add the include file and change the template output file name for all of your templates if you like. I’ve only added it to my individual files and the main index so far.
Some more notes:
You’ll eventually want to add things to your blacklist of sites that you don’t want displayed in your referrer list. This is what mine looks like right now:
my @blacklist = ( $localhost, 'lycos.com', 'alltheweb.com', 'srd.yahoo.com', 'mail.yahoo.com', 'search.', '216.32.180.', 'sitemeter.com', 'ureach.com', 'netscape.com', 'bravenet.', 'mail.', 'radiocomments.userland.com/comments', '127.0.', 'www.weblogs.com/top100', 'radio.xmlstoragesystem.com' );
but that’s only based on a week of running the script, and there are things I’d like to add to it in the future, and maybe delete…
Note: All of the credit for this goes to Andy and Brad Choate and all the others that have written before me. I just read what they did, applied a little grey matter and elbow grease, and got it working for me… I don’t claim to be able to get it working for anyone else.
6 Responses to “Your own Referrer Tracking with MT 2.21”
- 1 Trackback on Sep 20th, 2002 at 8:59 am
- 2 Trackback on Sep 20th, 2002 at 8:59 am
- 3 Trackback on Sep 20th, 2002 at 9:17 am
- 4 Trackback on Sep 20th, 2002 at 3:40 pm
Leave a Reply
Search
Subscribe
Archives
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006
- February 2006
- January 2006
- December 2005
- November 2005
- October 2005
- September 2005
- August 2005
- July 2005
- June 2005
- May 2005
- April 2005
- March 2005
- February 2005
- January 2005
- December 2004
- November 2004
- October 2004
- September 2004
- August 2004
- July 2004
- June 2004
- May 2004
- April 2004
- March 2004
- February 2004
- January 2004
- December 2003
- November 2003
- October 2003
- September 2003
- August 2003
- July 2003
- June 2003
- May 2003
- April 2003
- March 2003
- February 2003
- January 2003
- December 2002
- November 2002
- October 2002
- September 2002
- August 2002
- May 2002
Categories
- asides (445)
- baby (6)
- design + dev (142)
- for sale (7)
- get a job (11)
- investing (6)
- leadership + management (150)
- life stories (254)
- macintosh (320)
- marketing + advertising (224)
- Moveable Type (52)
- organization (6)
- photography + video (68)
- publishing + content (136)
- random (289)
- Saab (1)
- sales and selling (96)
- small business (147)
- startup (1)
- stuff (69)
- sysadmin (40)
- travel (42)
- Video (3)
- windows (69)
- WordPress (13)

(This might be considered a security risk by some folks, but to me, it’s not all that big of a risk… as the only think you’ll be keeping in that directory are log files or referrers, which you’ll be displaying publicly anyways, so big deal right?)
Actually, you are setting yourself up to have anyone with access to your server overwrite any of your files.
But if you are in an insecure shared environment then it’s probably fucked already and won’t make a difference.
- ask
ask, yes, you’re right on both counts.. but like I said… it’s really just referrer logs… I suppose someone could try sneaking some malicious code into that directory if they wanted… but then wouldn’t that hose the whole server? not my problem… hosted solution, and I back up every week… I can deal with that