How to intercept button click, run analytics code, and then continue with click function

Andrew R.

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.

Appeiron

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.

edited at
0

Comments

0 comments
Login to comment

Related

How to run a function on button click?

How to run code on server on the click of button?

How to run code on a button click in android fragment

how to intercept Button click inside UIWebview on IOS?

Run PHP code with click on Button

run a nested function on button click

Run php function on button click

How to run Jquery function on modal popup button click

How to run a function that a on form submit ajax with automatic click button

How to run a function declared in jsp from a button click

How do i run a node specific function on button click

How can calculate automatically without click any button to run function

How to call function on button click?

HTML on-click button to run javascript function

Javascript button click on event to run a function

Run a defined function on page load and on button click

How can I intercept the tweet button click event?

How to intercept a phone number click (Call button) on link in UITextView?

How to run form action and click event simultaneously on button click

How to run python scripts on button click in React?

How to run application of the first with click on the button in android?

How to run methods in onCreate() without button click

How to click the Continue button on website using selenium in python?

How I can click on a "Continue" button to finish a survey in Selenium Java

How to automatically collect analytics events for button click in android?

How to simulate a button click using code?

How to create html code when click button?

How to continue execution of Python script after evaluating a Click cli function?

how to call a function in when button click