How to track clicks in a BANS site
February 11, 2008 – 7:48 pmSo you want to track what links get clicked on your BANS site, yes? You are using Google Analytics right? Perfect, then this little tutorial is just for you.
Why?
First, why would you need this? Well, using GA alone is nice and will show you what pages are being visited on your site. With a little digging, Commission Junction will show you what items have been purchased. The missing piece is knowing what was clicked on even though the user didn’t buy anything. This is very helpful in knowing what items your visitors are most interested in allowing you to fine tune your site, target keywords better, etc.
How to do it
So, here is the meaty part, how to integrate click tracking into your bans site. NOTE: Line number are approximate as my files have been modified beyond what I describe. FIRST, BACK UP YOUR INDEX.PHP FILE!
Text below that is bold is code in your file, either existing or to be added. If it isn’t bold, it won’t exist or doesn’t need to be added. Text that is green is what you will add, and should be safe to copy & paste.
- Open up your index.php page
- From about line 30-45 or so you will see a bunch of lines that start with $front->. After those and before the line that starts with $d->(SELECT, add this code:
if($mainCat != '') { define("MAINCATNAME", $mainCat); } else { define("MAINCATNAME", 'home'); } define("SUBCATNAME", $subCat); - Find the FormatRow functions. There are three of them, but this tutorial applies to all. You can find the first one at approximately line 480
- The first line after the function declaration, add this:
$clickUrl = "'/click/".MAINCATNAME."/".SUBCATNAME."'";
- Go down to about line 503 or so where you will see where the actual link for the image is generated. It will look something like:
<a href=”‘.$link.” target=”_blank” rel=”nofollow”><img src= …. /></a>
- After the rel=”nofollow” attribute, add this:
onclick="javascript:urchinTracker('.$clickUrl.');". MAKE SURE there is a space between the ending quote on the rel=”nofollow” and the onclick.
- Apply the same onclick to the rest of the generated links. Don’t forget that there is one link for the image and one for the link text itself (the item name and such).
- You should have four links to add for each FormatRow function. There is one set of links for “buy it now” items and one set for non buy it now.
That should do it!
How to test it
Now that you have your index.php file modified, upload it to your server, replacing the old one (You DID back it up right?). Go to one of your store pages and view the page source. In the source, look for the ebay links, which isn’t too hard as they are so darn long, and look for the onclick piece you added.
What you will see now in your analytics control panel are URLs that show up like /click/cat_name/sub_cat_name. Now, this doesn’t show you individual item names, but does show you the category and sub category that the item was clicked on. While you could get the item name and such, all the items in a given category should be enough to let you know what your visitors are looking for.
I did a very similar thing for the search box, so I can see what users are searching for on my site. I’ll post about that little mod next.
Happy analyzing!









One Response to “How to track clicks in a BANS site”
Hello,
I have implemented the coding change in my index.php file. I am using the new google analytics tracking code ga.js, instad of urchin.js
Is there a way to adapt the changes in index.php to use ga.js, or, can I only use urchin.js with this mod?
-Ross-
By Ross on Apr 11, 2008