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 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.)
2 Specific event tracking with the Javascript tracker · snowplow/snowplow Wiki · GitHub

@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:

Hi I am having difficulty in recalling enableFormTracking. Can anybody help?

So I have a form which pops up after I click a certain button. I re-enable the form tracking by firing a GTM tag (I am using GTM with snowplow) that calls the enableFormTracking again. Basically I just add script window.snowplow('enableFormTracking').

Unfortunately it does not work. Calling the window.snowplow('enableFormTracking') from console works though.

Can anybody help or explain about this?

Thank you.

Hi @aditya

enableFormTracking must be called once the form is visible on the page. This is why calling it a second time in the Console works.

You should configure GTM to only trigger the call to enableFormTracking once the element is visible in the DOM.

You can safely call enableFormTracking multiple times, it will only scan forms that it hasn’t seen before on subsequent calls.

Thanks @PaulBoocock, I may have fired the tag which contains script reload at the same time the form loads so there might be timing issue there. Let me try to do script reloads after the form loads and see if it works.

1 Like