Under normal circumstances, you can code your link so that it includes an onclick Javascript event that can fire a Google Analytics function.
WordPress page builder plugins tend not to play nicely with this in my experience.
I’ve found a way around it that works for me.
I wanted to track how many times my Direct Deposit plugin is being downloaded, as it’s one of my most visited pages. I’ve made it generic in case I want to use it on another page. It uses the ID #track-me, which is easy to attach to any element, no matter which page builder you might be using, in my case Avada’s Fusion Builder.
Paste the following into the custom Javascript area of your theme. I put it in the footer or after the body tag. The console.log lines can be commented out.
<script>
jQuery(document).ready(function(){
try {
jQuery('#track-me').click(function(){
console.log('#track-me click fired.');
ga('send', 'event', 'Zip', 'download', jQuery('#track-me').attr('title'), {
nonInteraction: true
});
console.log('#track-me ga event sent.');
});
} catch(err) {
console.log(err);
}
});
</script>
Proof that it works.
Hi,
Thank you for the guide – I’m having some trouble getting it to work on my Avada page. I want to track clicks on a button. I inserted the code into the “Space before ” and added “#track-me” in the “CSS ID” of the button. But it does not fire any event in my Analytics. Am I adding the javascript or #track-me in a wrong place?
Hi Johannes,
When you enter the track-me in the CSS ID field of the button, you don’t need the #. That might be the problem.
Hi Melissa,
It didn’t quite fix it, but then I also noticed that it was due to MonsterInsights using “__gaTracker” instead og “ga”, so after editing that in the script, it works.
Thank you for your help and useful article – much appreciated :)
Thank you for sharing this! Second result on google for me when searching for Avada specific. But this will technically work for any theme, so great way to write the code. Maybe we should write a plugin to do this for Avada specific websites? :D
Thanks for letting me know it worked for you, Ellis!