Send Datalayer event on gform/submission/submission_started hook [RESOLVED]

Greg Slonina
Wed, 08 Apr 2026 20:48:00 +0000
Get Help

This hook gform/submission/submission_started doesn’t seem to be working for me
I’m adding the code via wp_footer but the submission hook doesn’t trigger

add_action( 'wp_footer', 'car_account_creation_datalayer_script', 100 );

function car_account_creation_datalayer_script() {
    $form = GFAPI::get_form( 7 );

    if ( empty( $form ) ) {
        return;
    }

    $form_title = rgar( $form, 'title' );
    ?>

        window.addEventListener('load', function () {

            if (typeof gform === 'undefined') {
                console.log('gform not available');
                return;
            }

            gform.addFilter('gform/submission/submission_started', function (data) {

                if (!data || data.formId !== 7) {
                    return data;
                }

                var params = new URLSearchParams(window.location.search);
                var membershipType = params.get('membership-type') || '';

                window.dataLayer = window.dataLayer || [];
                window.dataLayer.push({
                    event: 'account_creation_form_submit',
                    membership_type: membershipType,
                    form_title: <?php echo wp_json_encode( $form_title ); ?>
                });

                console.log('GF filter fired', data);

                return data;
            });

        });

    <?php
}

3 posts - 2 participants