Welcome to TalkGraphics.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2012
    Posts
    16

    Question Javascript: Track anchor-link-clicks on table-of-content navigation-bar?

    Hi Guys,

    now this one is for the geeks... :-)

    I have one website where a have lots of internal html anchors (links to sections on the same page - using xaras "link-to-anchor") and I have table-of-content grafical navigation bar which links to those sections.

    Now in my tracking software (PIWIK) I would like to see if someone clicks on those anchors and I need to trigger a javascript-function.

    My problem is that I just cant make it work. I tried varios codes, but none worked.

    This is what Xara Generates (navigation-bar):
    HTML Code:
    	<a onclick="return(xr_nn());" target="_self" href="#Link_To_Anchor">
      	<img style="left: 488px; top: 496px; width: 220px; height: 40px;" onmousemove="xr_mo(this,0,event)" title="" alt="" src="index_html_files/25213.png" class="xr_ap">
      	<!-- MORE MOUSEOVER IMAGES-->
     </a>
    And this is the jquery Javascript I tried to call a tracking function (NOT WORKING)
    Code:
    <script>
    	function trackTheClick(e) {
    		var link = e.attr('href');
    
    		if ( link.indexOf("#") !== -1 ) {
    			_paq.push(['trackPageView', link]);
    		}
    	}
    
    	$(document).ready(function() {
    		$('a').click( function() {
    			trackTheClick($(this));
    		} );
    	});
    </script>
    Does anyone have an idea on how to do this?

    Kind regards
    Mike

  2. #2
    Join Date
    Apr 2012
    Location
    SW England
    Posts
    17,823

    Default Re: Javascript: Track anchor-link-clicks on table-of-content navigation-bar?

    Mike, a bit late on for me but where you are using jQuery for the $ phrase:
    Have you embedded this code in the page's Head placeholder?
    Are you called the jQuery library correctly (at all)?
    Replace the "trackTheClick($(this));" phrase with a test "alert($(this));" to see if the clicking of a link activates the code call.

    I don't know what your jQuery skill level is so may I suggest going to the jQuery site and following a few of their examples by running them in a Xara placeholder to check you have everything in place.

    Acorn

 

 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •