formTrackingEvents
@blackbyte.sugar.js.tracking
This function allows you to automatically track some events on your forms like the start of the form filling, the form submission, etc… Each event has as data the form id “formId” and the language of the page “lang”. Here’s the events dispatched thgouth the dataLayer:
form.started: When the form has been started to be filledform.submitted: When the form has been submitted
Some data are automatically added to the dataLayer like the form id (formId) and the language (lang) of the page.
The form id is getter/generated using these rules:
- If a
data-form-idattribute is present on the form, this will be used as the form id - If an input named
form_idis present in the form, it’s value will be used as the form id - If an
idattribute is present on the form, this will be used as the form id - If nothing is found, a form id is generated using the
generateIdFromFormfunction
Params
- settings{}TFormTrackingEventsSettings
Some settings to configure your form tracking events
Example
import { formTrackingEvents } from '@blackbyte/sugar/tracking';
formTrackingEvents();
// Each dispatched events are like:
{
event: 'form.started',
formId: 'my-form-id',
lang: 'en'
}Settings
- langtrueBoolean
Specify if you want to emit the language specific events
- debugfalseBoolean
Specify if you want to log some debug informations
- simplifyLangtrueBoolean
Specify if you want to simplify the lang attribute to only the first part like
eninstead ofen-US
Todo
- testsnormal