Tracking links(custom module)

Discussion in 'Drupal' started by kawal24, May 18, 2012.

  1. #1
    Hi,
    I am looking to create a custom module for tracking clicks which have a onclick function in their html.
    So far i have come to following point
    A javascript function with code:

    var clicks = 0;
    function incrementClicks() {
        clicks+= 1;
    }
    Code (markup):
    For tracking only certains links i will create a view that displays those links on node page and will rewrite the link html using "views inbuilt rewrite option" as:

    <a href="[field_url-url]" onclick="incrementClicks()" target="_blank"  >Visit website</a>
    Code (markup):
    where [field_url-url] is the cck link field which needs to be tracked.

    Then i will pass/get "clicks" variable in a new variable in my custom module's .module file using drupal api.
    I guess this should work.
    But what i am concerned about is:
    I want to assign these clicks to authors of the node through which the clicks have been made.

    For e.g
    A link is clicked on user number 5's node ,the incrementClicks() function will be called.I want to keep a record of clicks that were made on user number 5's all nodes and so for every other user on the website in the same way.

    I am new to creating drupal modules and even javascript.

    So it would be great if someone can point me in the right direction.

    Thanks in advance
     
    kawal24, May 18, 2012 IP