Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #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:

    View post on imgur.com

    Please can you help?
    Thank you!

    • This topic was modified 3 years, 3 months ago by marcie73.
    #1316313

    Hello,
    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!

    #1316761

    Hi,
    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,
    Mike

    #1317504

    Hello 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!

    #1317624

    Hi,
    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

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Tracking contact form with Google Analytics’ is closed to new replies.