craft-freeform icon indicating copy to clipboard operation
craft-freeform copied to clipboard

GTM integration fails if another script messes with the `form` global variable.

Open nitriques opened this issue 4 months ago • 0 comments

What happened?

We get many many reports in Sentry regarding this error

null is not an object (evaluating 'form.freeform')

It is coming from the GTM integration.

image

Errors and Stack Trace (if available)

null is not an object (evaluating 'form.freeform') 

When evaluating ar pushEvent = form.freeform._dispatchEvent(

How can we reproduce this?

  1. Enable GTM integration for all forms.
  2. Load a page with a form with GTM enabled.
  3. Before submitting the form, open the console and run form = null (which any other script can do).
  4. After submit, we get an error.

Adding an iife around the whole block would solve the scoping issue.

(function () {
    // code here
})();

Freeform Edition

Pro

Freeform Version

5.6.2

Craft Version

4.12.4.1

When did this issue start?

After upgrading from older Freeform version, After upgrading from older Craft version

Previous Freeform Version

from latest 4.x, updated last week

nitriques avatar Oct 03 '24 15:10 nitriques