giving a +1 every time it is click would be great for a popular link block or page.

Just an Idea.

Wes/

Comments

sikjoy’s picture

+1 on this idea - I'm trying to implement this for the Drigg module (see #220242: Karma for clicking external links), and am struggling to find a SEO friendly way to do it. If I come up with a solution, I'll submit a patch for this module. Better yet, if any javascript gurus know how to do this, save me some time and post a solution.

sikjoy’s picture

Here's my problem:

  • assuming external links have a class attribute, extLnk
  • also a extLnkId attribute, could be set to nid, or whatever scheme you can dream up

Using the following jquery code:

$('a.extLnk').click(function() {
  // MENU_CALLBACK calling a module function that records clicks
  $.get('/click_tracker/'+this.attr('extLnkId'));
  return true; // go ahead and follow the link (SEO friendly)
}

Since jquery's get function loads the URL asynchronously, the clicker is already merrily on her way to the external site before the MENU_CALLBACK gets executed, and the click is not recorded.

Does anyone know how to cause jquery's get function to block, i.e. not return until its job is done? Or perhaps there's another function, that I don't know about, that would accomplish the task.

sikjoy’s picture

OK - I got it. The code should look like:

$('a.extLnk').click(function() {
  var href = this.href
  // MENU_CALLBACK calling a module function that records clicks
  var x = $.get('/click_tracker/'+this.attr('extLnkId'));
  x.onreadystatechange = function() {
    if (x.readyState == 4) {
      document.location = href; // go ahead and follow the link
    }
  }
  return false;
}

Give me a day or so, and I'll post a patch for this module.

quicksketch’s picture

Once again (I feel like this comes up every week). I do not want this as a feature of link module (which is a CCK field). Please create a separate project for these efforts.

sikjoy’s picture

OK - will do.

Encarte’s picture

Subscribing.

quicksketch’s picture

My previous post I thought this was in the "link" module issue queue (where I also get similar requests). Here's the on going effort to do link tracking within that project: http://drupal.org/node/236183

wwwoliondorcom’s picture

Hi,

On a digg-like website, any idea how to make a list of the websites to which I send visitors ?

http://drupal.org/node/295425

Thanks.

quicksketch’s picture

Status: Active » Closed (won't fix)

Regardless, this module should not be used to track link clicks because it is a JavaScript-only solution. However that hasn't stopped Google Analytics from offering the same thing, even though it's JS-only also. However I have no interest in implementing this functionality as it would easily double or triple the size of the module. Link tracking is best handled with a dedicated solution.