This article provides example Javascript to send data to Lytics from a form.
Accepted form data is as follows:
- Default field data: https://activate.getlytics.com/resources/documentation/data_jstag_send
- "form_name" - this will populate two user fields: "Last Time Web Form Submitted" and "Web Forms Submitted" in the UI.
- For any other custom data, prefix a field so that it starts with "formdata_" . If you can't find the data you're sending in #1, prefixing the field will cause it to automatically get mapped into the Lytics platform into the "Web Form Data" field
This code adds a function to the "submit" button and waits for the Lytics "jstag.send" javascript command to complete before submitting the form, ensuring data transfer.
jQuery is required for this implementation.
In the following example, we assume the following:
- The submit button has an HTML attribute "id" with a value of "submitbutton"
- The <form> tag has an HTML attribute "id" with a value of "myform"
- The form has an email <input> tag with the HTML attribute "name" with a value of "email"
- The form has a company <input> tag with the HTML attribute "name" with a value of "company"
- The fields "email" and "company" are sent to Lytics
Note: Please use this script as an example, and modify the HTML ids, form values, data, and the Javascript to fit your situation.
Include the following script anywhere in the <body> tag of your website.
<script type="text/javascript"> //Send lytics on email submit $('#submitbutton').on('click', function(e) { var form = $('#myform'); if ('jstag' in window && 'send' in jstag) { jstag.send({
"form_name": "My Form",
"formdata_custom_field": "My custom data", "email": $("input[name='email']").val(),
"company": $("input[name='company']").val() }, function() { form.submit(); }); } else { form.submit(); }; }); }); </script>
Comments
0 comments
Please sign in to leave a comment.