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
;(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[];
p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments)
};p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1;
n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,"script","//myurl.com/assets/js/53477247898.js","sp001"));
//Create new tracker & load general parameters
window.sp001("newTracker", "tracker1", "i.myurl.com", {
appId: "mainwebsite",
platform: "web",
cookieDomain: ".myurl.com",
cookieName: "_gs563_",
sessionCookieTimeout: 3600,
cookieLifetime: 315576
});
//Load pageview tracking
window.sp001('trackPageView');
//Load form tracking (authored event)
window.sp001('enableFormTracking');
</script>`
I also tried changing the authored event code to this, which didn’t work.
//Load form tracking (authored event)
sp001('enableFormTracking');
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)
$('#form001').submit(function(){
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
}
});
});
</script>
My form’s html:
<div id="form001" class="application-form w-form">
<form action="http://myurl.com/form/submit?formId=3" 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" />
</div>
<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">
</form>
<div class="w-form-done">
<p>Thank you.
<br>You'll hear from us soon.</p>
</div>
<div class="w-form-fail">
<p>Error, please email us instead.</p>
</div>
</div>