Anatomy and Deployment of Links · Index · Part 1 · 2 · 3 · 4 · 5 · 6 · 7 · 8 · Expand · Web Feed

For many site owners it is very important to know, what kind of and how much traffic they send to which locations. Tracking internal links allows profiling of user behavior, this helps the webmaster to fine tune a site's navigation and look and feel. Tracking affiliate links is essential, if upselling foreign products is the site's primary source of revenue. There are only so many ways to track a user's clicks on links, and most of them are sub-optimal with regard to search engine optimization.

Most content management systems (CMS), ad management systems, links list scripts etc. offering tracking of outgoing traffic, make use of redirects. Instead of using the target page's URI in the link's href attribute, each link points to a script, which counts the click and then redirects the user to the target page. This method of tracking outbound clicks has disadvantages:

  • Depending on the underlying technology, loading the target page in the users browser can get delayed up to a few seconds. That's not a big issue if the visitor surfs on cable or DSL, but with dial-up connections, which are still used by the majority of Internet users, the time to load is crucial. Users tend to hit the back button or close the window if a page loads slow, because they expect the target site to be slow. Especially with affiliate links, redirecting outgoing traffic decreases a site's revenue.
  • Search engines can't follow all redirects with regard to rankings, they may not count the redirected link as vote for the linked page. That means that many masked links do not increase the target page's link popularity respectively PageRank™. Most webmasters refuse link trade offers if the other site makes use of redirect scripts. Incoming links are the most important factor when it comes to search engine placements. A site without a reasonable amount of incoming links will not rank high on the SERPs.
  • Search engines consider redirecting fishy. There are lots of legitimate uses for redirects, but why take the risk of red-flagging? If you are not an experienced search engine optimizer, avoid redirects. Redirect moved pages to their new location and ensure your server responds with a '301' code, but no ney never let your Web server do '302' redirects for any reason. Unfortunately '302' is the default response code, used if a script doesn't explicitly forces a '301', what most scripts don't do.
  • Unskillfully redirects can result in unintended page hijacking on search engine result pages. Under some circumstances search engines may index foreign content under your redirect-URIs. Not only is this unfair with regard to the other site, it can easily dilute your site's theming and your search engine traffic becomes less targeted or even decreases.
Below I explain a smart method of search engine friendly click tracking. It makes use of the onClick event handler and is suitable, if you can live with not 100% accurate results caused by a minority of Internet users surfing with JavaScript disabled.

You may want to download the code examples discussed below, before you read on. Download and unzip '' (3kb), then upload all files to an empty directory on your server. Do a CHMOD 666 on 'clicks.txt', then execute 'page.htm' with your browser. The sample program requires PHP 4.3.1 or later installed on your Web server.

In order to track clicks on (exit) links, you must include a JavaScript function in the HEAD section of each HTML page. Also, you must put at least one image on the page. The required image can be the page's background image, or an invisible 1x1 pixel gif-image if you've text-only pages.

<script language="JavaScript">
function trackclick(url, aid, atxt) {
        (new Image()).src="trackclick.php?url="+url+
    return true;

The function 'trackclick' is called by the onClick event handler when a user clicks on a link or tabs to a link and presses the enter key. The event handler passes three input parameters to 'trackclick':
url is the URI of the linked page, taken from the link's href attribute.
aid is the value of the link's id|name attribute. On dynamic sites, this would be the primary key of a links table or so. In order to track clicks, you must assign a unique ID to every link by populating the id and the name attribute.
atxt is a hard coded literal. The string can contain the link's anchor text or another useful value.
When calling the tracking script, the function 'trackclick' passes these variables and adds the URI of the current page. Here is the link syntax:

<a href=""
    id="link-1" name="link-1"
    title="Smart stuff that matters ;-]"
    onclick="return trackclick(this.href,, 'left navigation:Smart IT Consulting');">
    Smart IT Consulting</a>

This search engine friendly link will perfectly pass both PageRank™ and keyword relevancy to the target. As long as the user has JavaScript enabled, each click gets stored in the database. Here is a simple tracking script template:

    // trackclick.php?url=$url&aid=$aid&atxt=$atxt&loc=$loc
    // url = target (clicked link)
    // aid = id (name) of the clicked link
    // atxt = anchor text of the clicked link or another literal
    // loc = source (document where the user clicked a link)
$ip = getenv("REMOTE_ADDR");
$userAgent = getenv("HTTP_USER_AGENT");
$string = date("Y-m-d G:i:s T") .";"
        .$url .";"
        .$aid .";"
        .$atxt .";"
        .$loc .";"
        .$ip .";"
        .$userAgent .";\n";
$fp = @fopen("clicks.txt", "a");
if ($fp) {
    @fputs ($fp, $string, strlen($string));

This PHP code gets the user's IP address and user agent name, then it appends a ';' delimited line to a plain text file ('clicks.txt'):

Date/time;Clicked URI;Link ID;Tracking text;Source page;IP address;User agent name;
--------- ----------- ------- ------------- ----------- ---------- ---------------
2005-08-20 9:03:20 EDT;; documentation; Article on SE friendly click tracking;;; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1);

2005-08-20 9:03:33 EDT;; link1; link1 tracking string:root index page;;; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1);

2005-08-20 9:04:04 EDT;; link2; link2 anchor text:Smart IT Consulting;;; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1);

In real life you'd most probably track more stuff, and you'd store the values in a database. The server sided component can be developed in any other programming language, for example PERL, ASP ...

The click tracking procedure outlined above is pretty much simplified to bring the point home, but you'll get the idea. Go ahead and implement a search engine friendly redirect-free traffic monitoring and analysis on your Web site.

Previous PageOptimizing Web Site Navigation

Anatomy and Deployment of Links · Index · Part 1 · 2 · 3 · 4 · 5 · 6 · 7 · 8 · Expand · Web Feed

Author: Sebastian
Last Update: September/7/2005 [1st DRAFT]   Web Feed

· Home

· Internet

· Link Tutorial

· Web Links

· Link to us

· Contact

· What's new

· Site map

· Get Help

Most popular:

· Site Feeds

· Database Design Guide

· Google Sitemaps

· smartDataPump

· Spider Support

· How To Link Properly

Free Tools:

· Sitemap Validator

· Simple Sitemaps

· Spider Spoofer

· Ad & Click Tracking

Search Google
Web Site

Add to My Yahoo!
Syndicate our Content via RSS FeedSyndicate our Content via RSS Feed

To eliminate unwanted email from ALL sources use SpamArrest!


neat CMS:
Smart Web Publishing

Text Link Ads

Banners don't work anymore. Buy and sell targeted traffic via text links:
Monetize Your Website
Buy Relevant Traffic

[Editor's notes on
buying and selling links

Digg this · Add to · Add to Furl · We Can Help You!

Home · Categories · Articles & Tutorials · Syndicated News, Blogs & Knowledge Bases · Web Log Archives

Top of page

No Ads

Copyright © 2004, 2005 by Smart IT Consulting · Reprinting except quotes along with a link to this site is prohibited · Contact · Privacy