Custom form tracking using Javascript tracker v3

I’m having trouble with the configuration options for custom form tracking using the Javascript version 3 tracker. I want to track only fields which do not have the class “private”.

Following the custom form tracking documentation I decided to use the filter option to filter out fields which contain the private class. Here’s the code I wrote to set the form tracking options:

const config = {
      forms: {
        denylist: []
      },
      fields: {
        filter: function (elt) {
          return !elt.classList.contains("private")
        }
      }
    };
   
    window.snowplow('enableFormTracking', { config });

With the above code I can see using the snowplow debugger chrome extension that the tracker is still capturing events for fields with the “private” class.

Any ideas what I could be doing wrong?

Hi Lauren,

A common pitfall is placing/running the snippet before the form and its fields exist, therefore the snippet has no concept of the private class.

Kind Regards,
Kyle

Hi @Lauren_Ribeiro
The property to configure the enableFormTracking options is options.

You should be able to use:

    const opts = {
      fields: {
        filter: function (elt) {
          return !elt.classList.contains("private")
        }
      }
    };
   
    window.snowplow('enableFormTracking', { options: opts });

Thanks Paul and Kyle for the responses. Paul’s suggestion worked for me!

1 Like

thanks, my issue has been fixed.

1 Like