Javascript tracker not tracking form submissions

Hello all,
I’m new to snowplow and having challenges tracking forms via javascript tracker 2.7.0 (logged by clojure collector 1.1.0 into s3). Pageviews are tracking fine and I can see the logs in s3, but neither authored event or unstructured event tracking is working. I am following the tutorial here for form tracking. My goal at this point is just to get the form data into s3. Any help is much appreciated.

Here is all of the javascript tracking code. First I tried this, using the authored event:

<script type="text/javascript"> 

//Load js file

//Create new tracker & load general parameters
window.sp001("newTracker", "tracker1", "", { 
  appId: "mainwebsite",
  platform: "web",
  cookieDomain: "",
  cookieName: "_gs563_", 
  sessionCookieTimeout: 3600, 
  cookieLifetime: 315576

//Load pageview tracking

//Load form tracking (authored event)


I also tried changing the authored event code to this, which didn’t work.

//Load form tracking (authored event)

After the above authored events didn’t work, I tried adding the below unstructured event code. This also failed, as I did not see the form data in the s3 logs.

<script type="text/javascript"> 

//Load form tracking (unstructured event)
        var form_id = $(this).attr('id'); //get the form's id
        var email_address = $('input[name=form[email]]').val();	//get the email address
        window.sp001('trackUnstructEvent', { 	//tell sp this is an unstructured event
            schema: 'iglu:com.mycompany/submit_form/jsonschema/1-0-0', 	//tell sp this is a submit_form event
            data: {
                form: form_id,	//load the form's id
                email: email_address	//load the email address

My form’s html:

<div id="form001" class="application-form w-form"> 
	<form action="" class="w-clearfix" data-name="Application Form" id="application-form-1" method="post" name="application-form-1" autocomplete="off"> 
		<div class="w-embed"> 
			<input type="hidden" name="form[formId]" value="3" />
			<input type="hidden" name="form[formName]" value="form3" />
		<input class="form-1-text-field w-input" data-name="form[first_name]" id="_form_first_name" maxlength="256" name="form[first_name]" placeholder="first name" required="required" type="text">
		<input class="form-1-text-field w-input" data-name="form[last_name]" id="_form_last_name" maxlength="256" name="form[last_name]" placeholder="last name" required="required" type="text">
		<input class="form-1-text-field w-input" data-name="form[company_name]" id="_form_company_name" maxlength="256" name="form[company_name]" placeholder="company name" required="required" type="text"> 
		<input class="form-1-text-field w-input" data-name="form[company_website]" id="_form_company_website" maxlength="256" name="form[company_website]" placeholder="company website" type="text">
		<input class="form-1-text-field w-input" data-name="form[email]" id="_form_email" maxlength="256" name="form[email]" placeholder="email" required="required" type="email"> 
		<input class="form-1-submit w-button" data-wait="please wait" id="form_input_application_submit" type="submit" value="submit"> 
	<div class="w-form-done">
		<p>Thank you.
			<br>You'll hear from us soon.</p>
	<div class="w-form-fail">
		<p>Error, please email us instead.</p>

Hi @rob,

I managed to track changes and submissions for exact same form using enableFormTracking in JS tracker 2.7.0, so here’s two questions to help us debug this case:

  1. Do you invoke enableFormTracking before form is rendered (DOM node constructed)? It wouldn’t work if you create form dynamically (in SPA for example) and invoke enableFormTracking after that, because tracker have to attach callbacks to existing form.
  2. Do you see HTTP requests in your browsers’ network pane in developer tools? Something like

Regarding your second attempt with self-describing event - you need to host iglu:com.mycompany/submit_form/jsonschema/1-0-0 in your Iglu Registry OR use iglu:com.snowplowanalytics.snowplow/submit_form/jsonschema/1-0-0 (which is used by built-in form tracking) with valid body. Without it it’ll appear in rotated clojure collector logs, but won’t be validated on enrichment stage, which makes it pointless. By the way, when you mention “logs in s3”, do you mean Clojure Collector rotated logs or Enriched Event TSV? And how do find that event is missing? I suspect that you may missed it because it is base64-encoded.

1 Like

Hi @anton,
Thanks for pointing out that it is base64-encoded, that was the problem. I was not able to search the logs and find the form data due to that. Thanks!

@anton how one would go about point 1?

I was able to workaround the form beeing created after my script was loaded with a settimeout, it is bad but it works for Chrome.
I was not able to make it work for Firefox even with a timeout.
It seems that Firefox falls into the DOMContentLoaded block and Chrome falls in the Webkit test block at function addReadyListener()(

Are there any solution for this case?

Thank you.

1 Like