Open/Close


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.

  1. Open up your index.php page
  2. 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);
    
  3. 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
  4. The first line after the function declaration, add this:
    $clickUrl = "'/click/".MAINCATNAME."/".SUBCATNAME."'";
  5. 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>
  6. 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.

  7. 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).
  8. 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!

Site5 $5 Hosting Deal

Like what you read? Don't miss anything, subscribe by RSSl!

Share this post:
  • StumbleUpon
  • SphereIt
  • del.icio.us
A few more you might be interested in:
  • Adding a sitemap to a BANS site
  • eBay partner network is live as promised
  • Adding keywords to your BANS site title
  • BANS - The Good, The Bad And The Ugly
  • Getting closer to a release


  • 7 Responses to “How to track clicks in a BANS site”

    1. 1

      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.

    2. 2

      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.

    3. 3

      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.

    4. 4

      Fadi Says

      Hey. I just started a directory for bans owners. Come and visit http://bansdir.com

    1. 1

      How to add Click Tracking to your BANS store using the new Analytics Code | New Affiliate Discoveries

      [...] First, take a look over at Web Mogul’s site for the initial steps, but instead replace step six with this: [...]

    2. 2

      BANS - The Good, The Bad And The Ugly at A Mogul To Be

      [...] The best thing about BANS it is has a really good community of users that are very helpful on their forums. From traffic discussions, to customizing and other topics, it has a good following that is very helpful. I myself have contributed where I could, answering questions both basic and advanced. I’ve even done a few modifications myself, such as the XML sitemap generator (which should have been a standard feature) and adding the ability to track clicks using Google Analytics. [...]

    3. 3

      Getting closer to a release at A Mogul To Be

      [...] off to ebay via the “place bid” link. This is far better than the hack I had to do for click tracking in BANS, and it happens under the covers, no javascript for this one. It tracks the item clicked by item ID [...]

    Leave a Response