• Resolved schnyger

    (@schnyger)


    Is there a way to limit this plugin so it tracks submissions on just one of our contact 7 forms?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author macbookandrew

    (@macbookandrew)

    Unfortunately not; it’s set up to be triggered whenever there’s a successful submission.

    To limit it to just one form, modify the plugin like this:

    
    function wpcf7_ga_tracking( $items, $result ) {
        $form = WPCF7_ContactForm::get_current();
    
        if ( 'mail_sent' === $result['status'] && 'insert_your_CF7_form_id_here' == $form->id() ) {
            if ( ! isset( $items['onSentOk'] ) ) {
                $items['onSentOk'] = array();
            }
    
            $items['onSentOk'][] = sprintf(
                    'if ( typeof ga !== "undefined" ) {
                        ga( "send", "event", "Contact Form", "Sent", "%1$s" );
                    }
                    if ( typeof _gaq !== "undefined" ) {
                        _gaq.push([ "_trackEvent", "Contact Form", "Sent", "%1$s" ]);
                    }
                    if ( typeof __gaTracker !== "undefined" ) {
                        __gaTracker( "send", "event", "Contact Form", "Sent", "%1$s" );
                    }',
                    esc_js( $form->title() )
                );
        }
        return $items;
    }
    add_filter( 'wpcf7_ajax_json_echo', 'wpcf7_ga_tracking', 10, 2 );
    

    or disable the plugin and add the above code to your functions.php file.

    • This reply was modified 7 years, 6 months ago by macbookandrew.

    Or maybe you could create a Goal to track that specific form, as seen on step 9 here: https://www.ads-software.com/plugins/cf7-google-analytics/#installation

    Charles

    (@charlesrodmell)

    “Optionally add a label if you want to define a goal for one specific form”

    What label should be used to match the goal to a specific form? Is it the form ID? e.g. “94” etc.?

    Plugin Author macbookandrew

    (@macbookandrew)

    @charlesrodmell You’d have to set the label to “Form ID 94” etc., since that is what the plugin sends as the event label.

    Thanks

    Charles

    (@charlesrodmell)

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Set to track specific form?’ is closed to new replies.