0

I'm trying to track (with Adobe Analytics and Tealium) as an event when someone submits email form successfully.

I can get the event to fire when a user clicks submit but it fires even if the email field is empty or an error

jQuery(document).on('mousedown', 'button[name="dwfrm_requestpassword_send"]', function() {
  utag.link ({
    "link_name": "password email reset", 
    "event_name": "email password"
  });
});

but this fires on every click. Then I tried to add a condition as such:

jQuery("#dwfrm_requestpassword_email-error")[0] or if (jQuery("#dwfrm_requestpassword_email-error").length == 0) but couldn't get it to tie together.

Trying to get the following: When a user clicks submit and it's successful fire the tracking event

I expect to fire the utag.link only after an email address has been put in and hits submit with no issues

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
nseecharan
  • 41
  • 3
  • Do you have a submit handler for the form...that is where you should be doing this.. event handler for When a user clicks submit – anuragb26 Jul 19 '19 at 09:13
  • I tried submit. Here is what it looks like. How would you suggest I write the script? – nseecharan Jul 19 '19 at 09:40
  • change "mousedown" to "submit" and the selector to the id of the form would make you code fire when the form is submitted - but there is no guarantee that it will be in the event stack after the validation is done. Your best bet is to locate the code that does the validation and in the code path where validation has all passed, add your tracking. – PCaligari Jul 19 '19 at 10:44

1 Answers1

0

Assuming the dom node representing id='dwfrm_requestpassword_email-error' only exists when there is an error in the password form element ,this should do the trick.

   jQuery(document).on('click', 'button[name="dwfrm_requestpassword_send"]', function() {

  if(!jQuery("#dwfrm_requestpassword_email-error").length){
     utag.link ({
        "link_name": "password email reset", 
        "event_name": "email password"
      });
    }
});
anuragb26
  • 1,467
  • 11
  • 14