How to track clicks in a BANS site
December 14th, 2007 by Robert
So 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!






Lullabyes And Goodnight Says
Great tip for combining the power of analytics with a BANS site to give you more data on all your site visitors.
Dec 17th, 2007 at 3:45 pm
Suzanne of New Affiliate Discoveries Says
Hey Mogul, standing on the shoulders of giants, I made a small change to your code to update this to the new GA code…with attribution to you of course! I just installed it tonight and it LOOKS like it should work. we’ll see what my analytics reports say tomorrow.
Dec 19th, 2007 at 11:48 pm
Robert Says
I was looking at the new analytics code yesterday and I like it. If you use the event tracking it won’t give the impression that you have more pageviews than you really should. I plan to upgrade soon.
Dec 20th, 2007 at 9:43 am
Fadi Says
Hey. I just started a directory for bans owners. Come and visit http://bansdir.com
Dec 23rd, 2007 at 8:54 pm