-
AuthorPosts
-
August 10, 2021 at 4:38 pm #1316099
Hello,
I cannot track avia contact form.
I tried using this code I found in these thread here.but it does not work.
add_filter(‘avf_contact_form_submit_button_attr’,’avia_add_submit_attributes_to_cf’, 10, 3);
function avia_add_submit_attributes_to_cf($att, $formID, $form_params){
$att = “onclick=\”_gaq.push([‘_trackEvent’,’Contact Form’,’Invio’]);\””;
return $att;
}Since I use Universal Google Analytics, I found out that in the following should be used in a different format, but does not work either.
add_filter(‘avf_contact_form_submit_button_attr’,’avia_add_submit_attributes_to_cf’, 10, 3);
function avia_add_submit_attributes_to_cf($att, $formID, $form_params){
$att = “onClick=\”ga(‘send’, ‘event’, ‘Contact Form’, ‘Invio’]);\””;
return $att;
}my event:
Please can you help?
Thank you!- This topic was modified 3 years, 3 months ago by marcie73.
August 11, 2021 at 6:03 pm #1316313Hello,
I found the error. It is my fault.
There was an extra square bracket I left adapting the code.I would like to ask if possible to track different contact forms: I have 2 of those, 1 on the homepage, the other in the contact page, but the function above adds the attribute to all forms.
Thank you!
August 14, 2021 at 9:32 pm #1316761Hi,
Thank you for your patience, to change the attribute for different pages you could use an IF statment that includes the page ID like this:add_filter('avf_contact_form_submit_button_attr','avia_add_submit_attributes_to_cf', 10, 3); function avia_add_submit_attributes_to_cf($att, $formID, $form_params){ if(is_page('500'){ $att = "onclick=\"_gaq.push(['_trackEvent','Contact Form one Send','Click/Touch','Footer']);\""; } if(is_page('400'){ $att = "onclick=\"_gaq.push(['_trackEvent','Contact Form two Send','Click/Touch','Footer']);\""; } return $att; }
there are Conditional Tags For Home, Front & others if you wish.
Best regards,
MikeAugust 19, 2021 at 2:38 pm #1317504Hello Mike,
It seems working! (after adding a second close round bracket after the page id in both “if” statements)
It took a while to understand where the error was… ;)))
Thank you so much!August 20, 2021 at 12:35 pm #1317624Hi,
Glad to hear this helped and thanks for pointing out the error, I have posted the correction below for future readers.
If you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.add_filter('avf_contact_form_submit_button_attr','avia_add_submit_attributes_to_cf', 10, 3); function avia_add_submit_attributes_to_cf($att, $formID, $form_params){ if(is_page('500')){ $att = "onclick=\"_gaq.push(['_trackEvent','Contact Form one Send','Click/Touch','Footer']);\""; } if(is_page('400')){ $att = "onclick=\"_gaq.push(['_trackEvent','Contact Form two Send','Click/Touch','Footer']);\""; } return $att; }
Best regards,
Mike -
AuthorPosts
- The topic ‘Tracking contact form with Google Analytics’ is closed to new replies.