Google analytics event tracking with jQuery automatically

It’s easy to track the user behavior from your web application or webpages like you can track where your user is clicking, what are they doing, etc…. with the help of Google analytics custom event tracking.

        $('a').on('click', function() {
            var anchorText = $(this).text();
            var anchorUrl = $(this).attr('href');

            ga('send', 'event', 'link', 'click', anchorText, anchorUrl);


In the above code I am just triggering ga() function (analytics function provided by Google analytics js script) when anyone will click any link in the whole documents. Then when user will click on any link (anchor text) then the ga() function will be triggered with my custom url, action, text value.

So from now on you can get this report from Google analytics.

Shaharia is a professional software engineer with more than 10 years of experience in the relevant fields. Digital ad certified, cloud platform architect, Big data enthusiasts, tech early adopters.

Site Footer