Skip to Content
Menu

updateFormFlow()

Create a string of form fields/events as the user moves through a form.

JavaScript February 7, 2021

Usage

JavaScript
nebula.updateFormFlow(formID, field, info)

Parameters

formID
(Required) (String) A unique ID of the form
Default: None

field
(Required) (String) The name of the form field or event action
Default: None

info
(Optional) (String) Additional information
Default: None

Parameter Notes

Form flow data is stored in a window object called formFlow. The form ID is used as a key to store the field data.

Request or provide clarification »

Additional Notes

This function concatenates the new field/event to the existing string and then sets a custom dimension (if used). As the user moves through the form, the data is sent to Google Analytics scoped to their session.

Abandonment can be deciphered when the form flow does not end with a [success].

This function is already built into Contact Form 7 detections, but can be manually added to other forms too.

Was this page helpful? Yes No


    A feedback message is required to submit this form.


    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!

    Source File

    Located in /assets/js/modules/forms.js on line 375.

    No Hooks

    This function does not have any filters or actions available. Request one?
    JavaScript
    nebula.updateFormFlow = function(formID, field, info = ''){
        if ( typeof nebula.formFlow === 'undefined' ){
            nebula.formFlow = {};
        }
    
        if ( info !== '' ){
            if ( info.length > 25 ){
                info = info.substring(0, 25) + '...'; //Truncate long info text
            }
    
            info = ' (' + info + ')';
        }
    
        if ( nebula.formFlow[formID] ){ //If this form ID already exists
            nebula.formFlow[formID] += ' > ' + field + info; //Append the next field to the string
        } else {
            nebula.formFlow[formID] = formID + ': ' + field + info; //Otherwise start a new form flow string beginning with the form ID
        }
    
        ga('set', nebula.analytics.dimensions.formFlow, nebula.formFlow[formID]); //Update form field history. scope: session
    };
    

    Override

    To override or disable this JavaScript function, simply redeclare it with the exact same function name.

    JavaScript
    nebula.updateFormFlow = function(formID, field, info){
        //Write your own code here, leave it blank, or return false.
    }