refreshFormTracking for capturing dynamic form changes

Hello has anyone tried to tackle the issue of refreshing form tracking for newly dynamically added fields in forms? I know it’s supported for links but not forms now. Maybe there’s an elegant workaround that could be employed. Right now, I can think of only to manually attach a custom event to fire change_form for new fields, but that seems a bit messy. Or if it would be possible to reset the formManager state https://github.com/snowplow/snowplow-javascript-tracker/blob/090d31314d2d3471e105589e11a8b0d39d626ae8/src/js/forms.js#L184 and then calling window.snowplow(‘enableFormTracking’); could work as well, but I’m not sure its possible to do it without fully reloading the tracker.

@evaldas, you can call enableFormTracking again - it is safe to do so multiple times

This will only work for form elements which exist when it is called. If you are creating a form programatically, call enableFormTracking again after adding it to the document to track it. (You can call enableFormTracking multiple times without risk of duplicated events.)
https://github.com/snowplow/snowplow/wiki/2-Specific-event-tracking-with-the-Javascript-tracker#3101-enableformtracking

@ihor yes this works for new dynamic forms, but doesn’t work for new fields added to existing forms like when some field is only available after user fills in some text. This is to prevent adding duplicate event listener for submit_form; Ideally you would want to form events and form element events to be handled independently.

Hey @evaldas could you add an issue on the Javascript tracker Repo with a short description and anything you have that would be helpful in reproducing? (eg sample html for a form of the type you’re referring to would be amazing).

I think your suggestion is sensible, it’s not my call whether or not it would be roadmapped/where it would be in the priority list but I think we should track this problem & look into it if the tracker behaves as you describe.

Unfortunately I can’t think of a good workaround for it short of manually instrumenting listeners (which is probably not an easy one), but I’ll mull it over and let you know if I think of something. :slight_smile:

@Colm sure thing, I’ll submit an issue a bit later and thanks for the note :slight_smile: