Skip to Content

updateFormFlow()

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

JavaScript July 2, 2019

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.

Source File

Located in /assets/js/nebula.js on line 2623.

JavaScript
nebula.updateFormFlow = function(formID, field, info){
    if ( typeof formFlow === 'undefined' ){
        var formFlow = {};
    }

    if ( !info ){
        info = '';
    } else {
        if ( info.length > 25 ){
            info = info.substring(0, 25) + '...'; //Truncate long info text
        }

        info = ' (' + info + ')';
    }

    if ( !formFlow[formID] ){
        formFlow[formID] = formID + ': ' + field + info; //Start a new form flow string beginning with the form ID
    } else {
        formFlow[formID] += ' > ' + field + info;
    }

    ga('set', nebula.analytics.dimensions.formFlow, 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.
}