craft-freeform
craft-freeform copied to clipboard
GTM integration fails if another script messes with the `form` global variable.
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.
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?
- Enable GTM integration for all forms.
- Load a page with a form with GTM enabled.
- Before submitting the form, open the console and run
form = null
(which any other script can do). - 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