JSFiddle - React, Tailwind, and code Playground
HTML
<a href="#home-page">Home</a>
<br>
<a href="#about-us-page">About Us</a>
JavaScript
/* <head> */
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-##-##']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
/* </head> */
$(function(){
$("a[href*='#']").on("click", function(){
var $url = $(this);
_gaq.push(['_trackEvent', 'ajaxLink', $url.text(), $url.attr('href')]);
console.log('_trackEvent', $url.text(), $url.attr('href'));
alert('_trackEvent ' + $url.text() +' '+ $url.attr('href'));
return false; /* ignore this string in your live code. it prevents going through the link */
});
});