How do I manually track clicks on outbound links?

5 replies
  • SEO
  • |
I found this link:
How do I manually track clicks on outbound links? - Analytics Help

wondering how I can implement this to my site?will this track my links www.xyz.com/gigi for example when clicked?
#clicks #links #manually #outbound #track
  • Profile picture of the author mill123
    yep if you use GA this is very easy to do. if you follow the instructions on that help page you should be right! you just need to make sure you have the GA code down the bottom of the page otherwise it wont know what onClick="javascript: pageTracker._trackPageview is.
    {{ DiscussionBoard.errors[549563].message }}
  • Profile picture of the author AndyBlackSEO
    I'm not sure about Analytics as mentioned above, but if you are familiar with a little php and mySQL you can write a very short script that will log each click along with any other information you require such as IP, date, time etc.
    Signature
    [FREE SEO TOOL] Build 29 Effective, High Authority Backlinks that Will Increase Your Google Rankings in 2020... CLICK HERE ...
    ... Instant backlinks that can get you results within 24-72hrs.
    {{ DiscussionBoard.errors[549577].message }}
    • Profile picture of the author baronig
      my hosting does not let to record clicks in a database.

      about GA I already have a general code on the page,does this going to conflict with it?
      {{ DiscussionBoard.errors[549693].message }}
      • Profile picture of the author Bruce Hearder
        Hi

        You can setup a bit of Javascript that will record all clicks on your outgoing links, its actually very easy. And you don't have to mess with your outgoing links at all (just need to add an "ID" field to the link)

        You could then use a bit of php code to write the resukts to a text file and you can analyse later..

        Here's how to do it:

        In all out going links make it have the following format :
        Code:
        <a id="id_1" href="http://www.outgoinglink.com">Outgoinglink</a>
        
        where id_1 is unique to each link you want to track, so first link is id_1, 2nd link is id_2 and so on.
        
        Otherwise they can be all id_1 and you want know which one is clicked on..
        Then somewhere on your webpage have the following Javascript code :

        Code:
        <script type="text/javascript" >
        /* <![CDATA[ */
        	var tracker = 'http://www.yoursite.com/updatehits.php';
        	var debug = false;
        	var a = document.getElementsByTagName("a");
        	for(i=0; i < a.length; i++) if (a[i].id != '')
        	   a[i].onclick = count_link;
        	function count_link()
                {
        		i = new Image();
        		s = Math.round(1E10*Math.random());
        		i.src= tracker+'?id='+this.id+'&r='+s;
        		if (debug) {
          		  alert(i.src);
        		  return false;
        		} 
                        else
        		  return true;
        	}
        /* ]]> */	
        </script>
        The code for updatehits.php is as follows :

        PHP Code:
        <?php
         $logfile 
        'logfile.txt';

         if (
        preg_match('/^id_([0-9]+)$/'$_GET['id'], $matches))
         {
            
        $id = (int)$matches[1];  
            if (
        file_exists(dirname(__FILE__).'/'.$logfile))
             {
              if (
        is_writable(dirname(__FILE__).'/'.$logfile))
               {
                 
        $fp fopen(dirname(__FILE__).'/'.$logfile),"a+");
                 
        fwrite(fp,'Link '.$id.' clicked on at '.date('M-d-Y'));
                 
        fclose($fp);
               }
             }
         }
        ?>
        Now when ever someone clicks on a links that has an id tag of "id_X" (where X>=1) it fires off the php program behind the scene and recods the time and link number that was clicked on.

        Its not the most elegant process there ever was, but it works every well..

        I'm using this on about 20+ different link directories that I own (I write the results to a DB) and its working great..

        Hope this helps

        Bruce
        {{ DiscussionBoard.errors[550056].message }}
        • Profile picture of the author baronig
          wow this is great I have to digest this code to follow what is going on,thanks Bruce
          {{ DiscussionBoard.errors[551534].message }}

Trending Topics