formTrackingEvents

Type:Function
Status:stable
Since:1.0.0
Platform:js
@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 filled
  • form.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:

  1. If a data-form-id attribute is present on the form, this will be used as the form id
  2. If an input named form_id is present in the form, it’s value will be used as the form id
  3. If an id attribute is present on the form, this will be used as the form id
  4. If nothing is found, a form id is generated using the generateIdFromForm function

Params

  1. 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

  1. langtrueBoolean

    Specify if you want to emit the language specific events

  2. debugfalseBoolean

    Specify if you want to log some debug informations

  3. simplifyLangtrueBoolean

    Specify if you want to simplify the lang attribute to only the first part like en instead of en-US

Todo

  • testsnormal