Form Tracking API
Contents
Learn how to use an API to track form submission and abandonment events, including what visitors enter in your forms.
About the Form Tracking API
In order to track customer activities on your website, you must first deploy the tracking snippet. After you do that, you can track form-level activity with the Form tracking API.
In order to be tracked, a form must have an ID, name, or action field that uniquely identifies it. By default, the values of the input, select, and textarea elements entered in the form (fields with personal information such as name, email, phone number and company name) are sent with the form submission and abandoned events. The customer profile is updated accordingly upon form submission.
Enable form tracking
To enable form tracking, call forms:track and specify the CSS selector of the form(s) that you want to track. For example:
ac('forms:track', '.hs-form');To enable tracking for all forms call the function without specifying the selector. For example:
ac('forms:track');To enable tracking for multiple forms based on the CSS selector specify a group of selectors as a comma-separated list. For example:
ac('forms:track', '#firstFormId, #secondFormId');ac('forms:track', '#firstFormId, #secondFormId');Manage form field data
To manage how form field data is sent with form submission and abandonment events, use the captureFormDataOnAbandon and captureFormDataOnSubmit options with the forms:track method. Set these options to true or false, depending on the result you want to obtain.
For example, to record a form abandonment event, but exclude any form field data, set captureFormDataOnAbandon to false.
ac('forms:track', '.hs-form', {
captureFormDataOnAbandon: false
});To capture serialized form data for form submission events, set the captureFormDataOnSubmit option to true.
You can set both options at the same time, as shown in the following example.
ac('forms:track', '.hs-form', {
captureFormDataOnAbandon: false,
captureFormDataOnSubmit: false
});Transform data before sending it
To configure the format of the data that is sent with the form submission and abandonment events, specify a custom transform function in the forms:track options. This function receives an object with the form data; it should return an object with the data to be sent with the form events. You can exclude certain fields, rename fields that are not meaningful, or make any other transformations to the form data before it is sent. The data object is a JSON object of "name-value" pairs, where:
- "name" is the value of the element's id or name attribute
- "value" is the visitor's input
ac('forms:track', 'form', {
transform: function (data) {
return {
deliveryOption: data['radioButton_3'],
acceptedLicense: data['checkbox_license']
}
}
});Sensitive form fields that are never tracked
/pass|billing|creditcard|cardnum|^cc|ccnum|exp|seccode|securitycode|securitynum|cvc|cvv|ssn|socialsec|socsec|csc/i.
If we track a field that you consider to be sensitive, please contact customercare@genesys.com.