0

Problem: I'm trying to implement form tracking basis Google's tracking snippet I tested the form submission locally and on staging but the form won't submit (not sure why) and I keep seeing massive 307 redirects ga hits

Massive 307 redirects

enter image description here

enter image description here

Here's my django form code:

<form autocomplete="off" enctype="multipart/form-data" method="POST" action="{{request.path}}" id="jsSecondStepRegistration">
    {{form.errors}}
    <div class="row">
       <div class="col-xs-12">
           <div id="location_form" class="fields-wrapper form-select">
               {{form.location}}
           </div>
       </div>
    </div>
    <div class="row">
        <div class="col-xs-12">
            {% csrf_token %}
            <p>We'll never share your information with third parties</p>
        </div>
    </div>
    <div class="row">
        <div class="col-xs-12">
            <button type="submit" class="btn btn-primary"><i class="text">Register & Apply</i></button>
        </div>
    </div>          
</form>

Javascript

<script type="text/javascript">
    $("#jsSecondStepRegistration").submit(function (e) {

        // Prevents the browser from submitting the form
        // and thus unloading the current page.
        e.preventDefault();
        ....        
        const $that = $(this);

        let formSubmitted = false,
            submitForm = () => {
                if (!formSubmitted) {
                    formSubmitted = true;
                    $that.submit();
                }
            };

        // If 1 second passes after the user clicks the submit button
        // and the `hitCallback` has not run, the form is resubmitted
        setTimeout(submitForm, 1000);

        // Sends the event to Google Analytics and
        // resubmits the form once the hit is done
        ga("send", "event", "Form submission", "Registration (immersive)", {
            "hitCallback": submitForm
        });
    });
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.