Davide Taraborrelli Davide Taraborrelli - 2 months ago 68
Javascript Question

Onclick Event Tracking Google Analytics Wordpress Visual Composer Plugin

I'd like to add this code for GA event tracking:

onclick="ga('send', 'event', { eventCategory: 'Contact', eventAction: 'ContactRequest'});"

on this Call To Action

<div class="vc_btn3-container vc_btn3-center vc_custom_1477135392137"><a class="vc_general vc_btn3 vc_btn3-size-md vc_btn3-shape-rounded vc_btn3-style-modern vc_btn3-block vc_btn3-color-grey" href="http://davidetaraborrelli.it/contatti/" title="" target="_blank">CONTATTAMI</a></div>

However, I don't know how to do it in Wordpress, my knowledge of coding are limited to coding a simple page from scratch, in that case I would simply have added the piece of code after HREF.

Since this page uses Visual Composer I don't know how to add that onclick piece of code to that div.

Any help is really appreciated, I hope it makes sense.

Thank you!


Looks like you want to add this tracking code on a CTA button in Visual Composer. There is this Advanced on click action option that Visual Composer provides. You can use that. It is fairly straight forward. Check out the following screenshot.

enter image description here

EDIT: This solution is tested on Visual Composer version 4.12, may not work if you have an older version.