Outbound Links

Last post 04-17-2008, 11:29 AM by JFRanger. 5 replies.
Sort Posts: Previous Next
  •  04-15-2008, 8:32 AM 39243

    Outbound Links

    I'm interested in tracking the outbound links through google analytics and I was wondering what would be the best way to make it so that the links are automatically configure to that format.
     
    The links would have to be configured this way:
    <a href="http://www.example.com" onClick= pageTracker._trackPageview('/outgoing/example.com');">
     
  •  04-15-2008, 2:44 PM 39256 in reply to 39243

    Re: Outbound Links

    Gaudicia,
     
    It's possible.
     
    Please follow the steps below:
     
    1. In the CuteEditor_OnChange event, get the edit document.
     
    2. Get links Collection from edit document.
     

    var links = editdoc.links;

      if(links)
      {
       for (var j = 0; j < links.length; j++)
       {
              var lnk = links[j];  
              lnk.setAttribute("onclick","whatever");
       }
      }


    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  04-15-2008, 9:38 PM 39264 in reply to 39243

    Re: Outbound Links

    You can accomplish that by using Unobtrusive JavaScript, library like jQuery.com will do that for you.
     
     
    This will affect all link in your document:

        $(document).ready(function() {
           $('a').onclick(function() {
                   pageTracker._trackPageview(  $(this).attr("href")  ) ;
            return false;
            });
          
         });
     

     
    This will affect only links in the <DIV id="content"> in your document:

        $(document).ready(function() {
           $('#content a').onclick(function() {
                   pageTracker._trackPageview(  $(this).attr("href")  ) ;
            return false;
            });
          
         });

    Enjoy!
  •  04-16-2008, 12:47 PM 39333 in reply to 39264

    Re: Outbound Links

    This will affect all the links even the links that direct to other pages of my website?  Because I only want it to affect links to other websites.
     
    And thank you, I will experiment with the code!
  •  04-17-2008, 10:13 AM 39406 in reply to 39256

    Re: Outbound Links

    I'm a little confused in what file do I make the changes?
  •  04-17-2008, 11:29 AM 39414 in reply to 39333

    Re: Outbound Links

     
     
    1 - You must download the js file from jQuery.com and include it in your header like this
     
    <script type="text/javascript" src="js/jquery-1.2.3.js"></script>
     
     
     
    2- To  link ONLY to an external site, we have to check the presence of the string http:// at the beginning of the value of the link’s href attribute. We could select links with an href value starting with http:// with the following code in your header:

    <script>
     
        $(document).ready(function() {
           $("a[href^=http://]").onclick(function() {
                   pageTracker._trackPageview(  $(this).attr("href")  ) ;
            return false;
            });
          
         });
     
    </script>
     
    Note: After this is done, if you check the source code, "YOU" will only see the basic code <a ref="http://www.example.com" ;"> but the "BROWSER" will read ;

     For external link:
      <a href="http://www.example.com" onClick= pageTracker._trackPageview('http://www.example.com');">  

     Internal link:
      <a href="hello_world.asp">  

    This is the beauty of Unobtrusive JavaScript... no need to play in the HTML tags!

    Enjoy!

    //JF//
View as RSS news feed in XML