Attach Analytics events on Buttons

For example if you want to attache a Google Analytics goal event on a button, you can do so with a few lines on custom JS. This is a rough example though and i would suggest hiring a developer if you’re not familiar with these codes.

Here’s an interesting read here http://www.wpbeginner.com/wp-tutorials/how-to-add-google-analytics-event-tracking-in-wordpress/ in which explains several ways to track clicks on buttons, with events. My suggestions would be:

1) First you will need to figure out the selector of the button. Click on the button’s options and access the Help tab. Here you can find the element’s unique ID http://hogash.d.pr/1e8h9 . Since there’s an iteration of multiple buttons inside the element, you will also need to get the button’s class, eg: http://hogash.d.pr/15sSH . You can see the code by right clicking onto the button and hit Inspect element, the developer console will open.

So now we should end up with a selector such as .eluidac7595fc .btn-element-0 .

2) Now we’ll need to create the JS code, that can be pasted in THEME options > Advanced > Custom JS. This code will basically listen the button if it’s clicked, and trigger an action, eg:

jQuery('.eluidac7595fc .btn-element-0').on('click', function(){
  // this will be triggered if the button is clicked
});

3) Prepare the event code to add it into the trigger.

jQuery('.eluidac7595fc .btn-element-0').on('click', function(){
  ga('send', 'event', 'Downloads', 'Click', 'Ebook downloaded', '0'); 
});

The ga(send.. snippet is just used from http://www.wpbeginner.com/wp-tutorials/how-to-add-google-analytics-event-tracking-in-wordpress/ as now it can be triggered otherwise than attached to the button attribute.