AJAX Linktracker

This module allows you to track clicks on arbitrary links. You can use it to track file-downloads, outgoing links or even your internal navigation links.
All you got to do is to add an unique id-attribute to any link you want to be tracked.

The module utilizes javascript and a XMLHttpRequest to count the clicks. This has the disadvantage that you will not capture clicks by people who have javascript disabled . But on the other hand I see a lot of benefits. It uses no redirects which makes it pretty unobtrusive, your links look like always and there is no rank denial. It’s easy to apply to virtually any link on-the-fly. And it’s not triggered by crawlers but only by people behind browsers.

Installation:

  1. Upload the file linktracker.js anywhere to your site and remember the URL.
  2. Upload the folder named linktracker and its content into the modules-folder of your EE system-directory.
  3. Upload the file named lang.linktracker.php into the /language/english-folder of your EE system-directory.
  4. In your Control Panel navigate to CP Home › Modules, find the AJAX Linktracker module and click Install.
  5. Now you have access to the CP Interface of the module. It is here where you can view and reset the click-statistics.

Add the javascript-snippet to your templates:

On every page that may contain links that are to be tracked the java-script call needs to be included. Preferably somewhere at the bottom of the page. If you have a footer-template that may be a good place to put it.

Add the following code to the template/s in question:

<script type="text/javascript" src="http://yourdom.ain/linktracker.js"></script>
<script type="text/javascript">
{exp:linktracker:apiurl}
</script>

Of course you need to replace the URL to the one where you uploaded your copy of linktracker.js.

Usage:

Now all you got to do is to add a unique id-attribute to any link that is supposed to be tracked. This may be links in entries as well as links you compose somehow in your templates with custom fields and the like. External links, internal links, links to files… it doesn’t matter as long as it has and id.

Example:

<a id="holiday-photos" href="http://mydom.ain/pictures.zip">My latest album</a>

This link will show up under the Link ID holiday-photos in the click-statistics.

<a href="http://expressionengine.com/">Great CMS</a>

This link will not be tracked since there’s no id present.

Special IDs

There is a set of IDs that serve a special purpose. If the id starts with either vc1_, vc2_, vc3_ or vc4_ followed by a number it is assumed that the number is an entry_id of a weblog entry.

If a link with such an id is clicked it gets tracked like usual. Additionally the corresponding view_count variable of the weblog entry is incremented by one.

Example:

<a id="vc2_93" href="http://anydom.ain/blog.php"></a>

If this is clicked, view_count_two of the weblog-entry with the entry_id 93 gets incremented.

<a id="vc4_115" href="http://another.dom.ain/index.html"></a>

If this is clicked, view_count_two of the weblog-entry with the entry_id 115 gets incremented.

I think you get the point.

An application example for this is a link directory-type of site where you have a custom field for an outgoing URL. In a template you’d do something like:

{exp:weblog:entries weblog="directory"}
<h2>{title}</h2>
{site_description}
<a id="vc1_{entry_id}" href="{sites_home}">Goto Homepage</a> (Visited {view_count_one} times)
{/exp:weblog:entries}

Then you could use

{exp:weblog:entries weblog="directory" orderby="view_count_one" sort="desc"}


to easily pull out a list of the most popular links in your directory.

Display # of clicks in templates

There’s also a tag that outputs the number of clicks for a given link_id if you don’t utilize the view_count approach. It’s a single tag that doesn’t have a closing element.

{exp:linktracker:clicks link_id="holiday-photos"}

It only has one mandatory parameter which is the link_id="” to be displayed.

Click Statistics:

Under CP Home › Modules › AJAX Linktracker you’ll find a list of all Link IDs and their number of clicks. They only show up once they have been clicked for the first time.
To the right there is a Reset-link on every line that resets the counter for the respective Link ID.
If you click on a Link ID you get a detailed listing of every click for that ID.

That’s all there is as of now.

Download: linktracker.zip
7.88 KB

If you found something useful here and want to show your appreciation feel free to


Comments:

2 of 3 pages  <  1 2 3 >

The most recent version also records IP addresses.
Update instructions can be found in ‘readme_update.txt’ which is included in the zip-archive.

Posted by  on  10/01  at  04:31 PM

I think that comment was a comment-spammer that notified me that he’s going to spam my site unless I unregister from his “service” via email.
*shakes head*
It gets worse every day ...
Concerning the IP.  This should be doable if I pass it from EE to the javascript. I don’t think you can capture the IP directly with JS.
I might give it a thought when I find the time.

Posted by  on  10/01  at  12:04 PM

Was that comment directed to me? I have no idea what you’re talking about. Sorry.

Posted by JT Thompson  on  10/01  at  06:00 AM

One suggestion.

You should capture and display the IP of the person that linked out. it would really help to establish if it’s more than one person using the link or one person that simply clicks it many times throughout the day.

For instance. I’ve got a contributor that also has a link to his site on my front page. I suspect he’s clicking it frequently as a simple way to get back to his page. Not that it’s wrong, I would do the same thing. but I’d like to be able to show that so when i see the report I can filter.

It’d also be great to be able to add IPs to a filter list that wouldn’t track.

Do I ask for too much or what smile

Posted by JT Thompson  on  10/01  at  04:01 AM

Thanks for the help on this.

It’s working great now. Very handy. It’s important to me because it allows me to accurately account for my outgoing links. when people tell me how much traffic they get from my site I can be sure I know whether they’re being honest or not smile

Posted by JT Thompson  on  09/27  at  11:07 PM

That’s the thing with the extra ? in the URL.
If it’s turned on I suppose it’s turned on for a reason.

Anyways, the updated mod.linktracker.php takes that into account.

Posted by  on  09/27  at  03:14 PM

2 of 3 pages  <  1 2 3 >