gtag.js Event Tracking in Google Analytics with JQuery

Back in the day event tracking the volume of interactions with email (mailto) hyperlinks, click-to-call (tel:) links and PDFs was tedious. Then came Google Tag Manager and solved a variety of issues when it comes to tracking common methods of interaction – great news to many of us. The problem, however, is that many websites do not utilise Tag Manager and upgrading is not always a quick-fix.

Thankfully there’s a quick-fix solution to tracking the aforementioned types of customer interaction with the power of jquery, taking the hassle out of manual coding each link one-by-one.

Event Tracking for Mailto, Telephone & PDF Hyperlinks

The code required to track interactions with mailto links, click-to-call/telephone links and PDFs with the new Global Site Tag (gtag.js) using jquery is as follows:

Note: This is assuming that you’re already utilising the jquery library (which most sites are nowadays!). If not, then you’ll need to include the following script this code will work:

Place this code at the bottom of your page just before the tag. If you’re using WordPress then it’s as simple as modifying the footer.php file to include the above code.

Event Tracking with Legacy Google Analytics Tracking

If you’re using an older method of Google Analytics tracking, this code can also be easily adapted to work with these. For example, this can easily be modified to work with both ga.js and analytics.js.

Event Tracking with ga.js

Event Tracking with Universal Analytics (analytics.js)


1 thought on “gtag.js Event Tracking in Google Analytics with JQuery

  • Event tracking within things that are java and flash, and even onepage apps is very tricky. I’m working on a site where i don’t get any dev resources so can’t hard-code anything but have to use GTM to track everything. And with Angular that’s not the easiest of things. What do you use to show progress and reports to clients?

    And also, why have you not updated your blog Chris?


Leave a Reply

Your email address will not be published. Required fields are marked *