Fadlan Fadlan - 10 months ago 50
jQuery Question

Google Analytics Event Not Working on Submit

I would like to send event when someone submits form on my website, but it's not working.

This is my form script:

$('.wicmsLeadSubmit').prop( 'disabled', false );

var leadForm = $(this).closest('form');
var leadImie = $('.lead_imie', leadForm);
var leadTelefon = $('.lead_telefon', leadForm);
var leadEmail = $('.lead_email', leadForm);

leadImie.attr('placeholder', 'Podaj imię');
return false;

if(leadEmail.val() == ''){
leadEmail.attr('placeholder', 'Podaj email');
return false;
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
if(reg.test(leadEmail.val()) == false) {
leadEmail.attr('placeholder', 'Podałeś błędny email');
return false;
ga('send', 'event', 'Submit', 'Modal Rejestracja', $('.reveal-modal.formularz').id());
ga('set', 'userId', leadEmail.val() );

type: 'POST',
url: '/lead',
dataType: 'json',
data: {
lead_email: leadEmail.val(),
lead_imie: leadImie.val(),
lead_source: $(':hidden.lead_source', leadForm).val(),
lead_telefon: leadTelefon.val()
success: function(data){
$('.powiadomienie', leadForm).hide();
$('.blad', leadForm).show();
$('.blad', leadForm).append(' Tresc błedu: '+data.error.message);
$('.wicmsLeadSubmit', leadForm).prop( 'disabled', true );


$('.wicmsLeadSubmit', leadForm).prop( 'disabled', true );
$('.powiadomienie', leadForm).show();

return false;

And this is what makes error: ga('send', 'event', 'Submit', 'Modal Rejestracja', $('.reveal-modal.formularz').id());

And when I try to look for errors there is only one:
$(...).id is not a function

Please help.


.id() is not a jQuery function, if you want the id attribute, do this:

ga('send', 'event', 'Submit', 'Modal Rejestracja', $('.reveal-modal.formularz').attr('id'));