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:

https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js

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)

Voila!

Leave a Reply

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