Tracking “Button onClick” Event

Updated on August 19, 2020

Tracking the “Button onClick” event is useful for Facebook Pixel, Google Analytics or Google Tag Manager.


Note:
 It’s assumed that you are already familiar with JavaScript, and using the developer tool in browsers to inspect elements. To learn more about it, read the Inspecting elements and Inserting Custom JavaScript Codes articles.

Follow the steps bellow to track Button onClick events:

1. Using the browser developer tool, inspect your Button element and get its ID.

2. From the WordPress left menu, go to Jupiter X > Control Panel > Settings > Tracking Codes.

3. Paste the following codes:

<script>document.addEventListener("DOMContentLoaded", function(event) { 
jQuery('#My_Button a').click(function(){
// tracking code here
// for example Facebook Pixel:
fbq('track','AddToCart');
});
});
</script>


Note:
 Replace #My_Button a ID with the ID or class name that you found in the Inspector Tools.

4. Click on the Close and Publish the changes.

Use Growmatik to measure the performance of your Jupiter X website and get actionable insights to promote growth.

Did this answer your question?