I have been asked to build code where I can intercept the click of a button, stop the function that fires on the click, run an analytics script, then fire the original click function. I can do this with JS/jQuery on a standard button when using onClick, but this button is built in Angular and using an ng-click instead, so I am a little out of my element.
The button I am trying to intercept is this:
<input id="btn-hero-form-try" class="btn btn-solid" data-ng-disabled="trialForm.buttonDisabled" data-ng-click="trialForm.submitTrialForm('personal')" type="submit" value="Download Free Trial">
A few things make this more difficult: I have no access to the HTML code on the CMS, so I can't add any additional parameters that way, and have been asked not to inject any via script from the page.
I have been playing with the ng-click-interceptor, but have not gotten it to work yet.
Any help, or pointing in the right direction would be greatly appreciated.
You are free to upgrade common directive ngClick - just create your own!
In common words - they share same event but called separately.
It will not affect default, it will be called later so you need to mess with priority, and you will be needed to append it to existing application.
If you are aware of changing existing code - then you need jQuery, selector like [ngClick] to find any clickable item and run asynchronous .on(click) events depending on target content or value of ngClick attribute.
I don't think to sync analytics with callbacks of actual clicks is good idea, due to possible side effects on any step.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments