Viewing 5 replies - 1 through 5 (of 5 total)
  • I may write a companion plugin for this, but here’s the code to add to your footer.php file that piggy-backs off the GA code this plugin already adds. Edit the CSS in the code (the “.main-menu ul li a”) as needed to match the containers of your anchor links.

    [Attribution moderated]

    <script type="text/javascript">
    jQuery(document).ready(function () {
    	jQuery('.main-menu ul li a').click(function(){
    		var match = jQuery(this).attr('href').match(/#\S+/);
    		__gaTracker('send', 'pageview', location.pathname + match[0]);
    	});
    });
    </script>

    Moderator Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Rob, please don’t attribute code like that. If you’re not comfortable without that attribution then you shouldn’t share code here. Now your link will be in dozens of people’s websites, maybe that’s what you intended? Not cool, don’t do it again.

    Apologies Andrew, I think that was a copy/paste, and didn’t think about it. I’m not even sure what I had originally posted, but that was not my intent. Thanks for fixing.

    Moderator Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Ah yes, please edit the link on that one as well, I just replied to it.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Tracking Anchor Tags’ is closed to new replies.