Marketing skills for Claude Code and AI agents. CRO, copywriting, SEO, analytics, and growth engineering.
JavaScript agent-skillsai-agentsai-seoclaudeclaude-codeclaude-code-pluginclaude-skillscodexcontent-marketingconversion-rate-optimizationcopywritingcursoremail-marketinggenerative-engine-optimizationgrowth-marketingmarketingmarketing-automationsaas-marketingseoskill-md
fix(conversion-tracking): listen for Framer submits in the capture phase
Aaron Beashel1bf18a730195
diff --git a/skills/conversion-tracking/assets/gtm-recipes/detect/detect-framer-forms.json b/skills/conversion-tracking/assets/gtm-recipes/detect/detect-framer-forms.jsonindex de6b6f5..4114573 100644--- a/skills/conversion-tracking/assets/gtm-recipes/detect/detect-framer-forms.json+++ b/skills/conversion-tracking/assets/gtm-recipes/detect/detect-framer-forms.json@@ -29,7 +29,7 @@{"type": "TEMPLATE","key": "html",- "value": "<script>\n(function () {\n // SUBMIT-BASED BEST EFFORT. Framer exposes no success event, so this fires\n // on a submit that passed browser validation and that no other handler\n // cancelled. A server-side rejection or spam block still counts. For exact\n // counts, set the form to redirect to a thank-you page and use\n // thank-you-page.js instead.\n if (window.__ctDetectFramerForms) return;\n window.__ctDetectFramerForms = true;\n window.dataLayer = window.dataLayer || [];\n\n function fireConversion(formName) {\n window.dataLayer.push({\n event: 'framer_form_submitted',\n form_name: formName || ''\n });\n }\n\n function isFramerForm(formEl) {\n if (!formEl) return false;\n if (formEl.hasAttribute && formEl.hasAttribute('data-framer-name')) return true;\n var cls = typeof formEl.className === 'string' ? formEl.className : '';\n if (/(^|\\s)framer-[A-Za-z0-9_-]+/.test(cls)) return true;\n try {\n if (formEl.closest && formEl.closest('[data-framer-component-type]')) return true;\n if (formEl.closest && formEl.closest('[data-framer-name]')) return true;\n } catch (e) {\n // .closest not available — fall through\n }\n return false;\n }\n\n function handleSubmit(event) {\n try {\n var formEl = event.target;\n if (!formEl || (formEl.tagName || '').toLowerCase() !== 'form') return;\n if (!isFramerForm(formEl)) return;\n\n // A submission another handler already cancelled never happened.\n if (event.defaultPrevented) return;\n\n // Constraint validation gate: an invalid form cannot have submitted.\n try {\n if (typeof formEl.checkValidity === 'function' && formEl.checkValidity() === false) return;\n } catch (e) {\n // constraint validation unavailable — fall through\n }\n\n var formName = formEl.getAttribute('data-framer-name') || formEl.id || '';\n\n fireConversion(formName);\n } catch (e) {\n // Never throw back into Framer's own form handling.\n }\n }\n\n if (typeof document !== 'undefined' && document.addEventListener) {\n // Bubble phase deliberately. A capture-phase listener runs BEFORE the\n // form's own handlers, so it would count submissions that Framer's\n // validation goes on to cancel.\n document.addEventListener('submit', handleSubmit, false);\n }\n})();\n</script>"+ "value": "<script>\n(function () {\n // SUBMIT-BASED BEST EFFORT. Framer cancels the native submit and sends\n // the form by script, so a bubble-phase listener always sees it cancelled\n // and never fires. This listens in the capture phase, before Framer's own\n // handler runs, and fires on a submit that passes browser validation. It\n // is still submit-based, so a server-side rejection, a spam block or any\n // later custom validation still counts. A 2-second debounce per form only\n // collapses rapid repeats (a double click). Framer documents a\n // framer:formsubmit event, but it fires only when the form has a tracking\n // ID set and isn't documented as success-only, so this doesn't rely on\n // it. For exact counts, set the form to redirect to a thank-you page and\n // use thank-you-page.js instead.\n if (window.__ctDetectFramerForms) return;\n window.__ctDetectFramerForms = true;\n window.dataLayer = window.dataLayer || [];\n\n function fireConversion(formName) {\n window.dataLayer.push({\n event: 'framer_form_submitted',\n form_name: formName || ''\n });\n }\n\n function isFramerForm(formEl) {\n if (!formEl) return false;\n if (formEl.hasAttribute && formEl.hasAttribute('data-framer-name')) return true;\n var cls = typeof formEl.className === 'string' ? formEl.className : '';\n if (/(^|\\s)framer-[A-Za-z0-9_-]+/.test(cls)) return true;\n try {\n if (formEl.closest && formEl.closest('[data-framer-component-type]')) return true;\n if (formEl.closest && formEl.closest('[data-framer-name]')) return true;\n } catch (e) {\n // .closest not available — fall through\n }\n return false;\n }\n\n function handleSubmit(event) {\n try {\n var formEl = event.target;\n if (!formEl || (formEl.tagName || '').toLowerCase() !== 'form') return;\n if (!isFramerForm(formEl)) return;\n\n // Constraint validation gate: an invalid form cannot have submitted.\n try {\n if (typeof formEl.checkValidity === 'function' && formEl.checkValidity() === false) return;\n } catch (e) {\n // constraint validation unavailable — fall through\n }\n\n // Collapse rapid repeats on this same form element. Keyed on the\n // element itself, so two forms with the same name, or no name, don't\n // share a timestamp.\n var now = Date.now();\n if (formEl.__ctFramerLastFire && now - formEl.__ctFramerLastFire < 2000) return;\n formEl.__ctFramerLastFire = now;\n\n var formName = formEl.getAttribute('data-framer-name') || formEl.id || '';\n\n fireConversion(formName);\n } catch (e) {\n // Never throw back into Framer's own form handling.\n }\n }\n\n if (typeof document !== 'undefined' && document.addEventListener) {\n // Capture phase, so this runs before Framer's own handler cancels the\n // native submit.\n document.addEventListener('submit', handleSubmit, true);\n }\n})();\n</script>"},{"type": "BOOLEAN",diff --git a/skills/conversion-tracking/assets/snippets/README.md b/skills/conversion-tracking/assets/snippets/README.mdindex 189a9c7..96f72cc 100644--- a/skills/conversion-tracking/assets/snippets/README.md+++ b/skills/conversion-tracking/assets/snippets/README.md@@ -66,7 +66,7 @@ Not every snippet fires on a confirmed success. Some tools expose no success sig| `fluent-forms.js` | Native success event | jQuery `fluentform_submission_success` || `formidable-forms.js` | Native success event (AJAX); DOM-inferred after submit (non-AJAX) | `frmFormComplete` / `frmBeforeFormRedirect`; non-AJAX: next page shows `.frm_message` or a redirect, with no error markers || `forminator.js` | Native success event | jQuery `forminator:form:submit:success` |-| `framer-forms.js` | Submit/click-based best effort | `submit` on a Framer form, not `defaultPrevented`, passing `checkValidity()` |+| `framer-forms.js` | Submit/click-based best effort | capture-phase `submit` on a Framer form, caught before Framer's own handler cancels it, passing `checkValidity()`; repeats on the same form within 2s are collapsed || `gravity-forms.js` | Native success event | jQuery `gform_confirmation_loaded`, with a MutationObserver fallback on the confirmation message || `jotform.js` | Submission built (`submit` then `formdata`, once per form) for the source-code embed; for the iframe embed, thank-you redirect recommended; message listener kept as fallback | source embed: a capture-phase `submit` marks the form, then the `formdata` event fires once per form ID; iframe: `{action: 'submission-completed', formID}` postMessage, which Jotform doesn't document, counted only from a Jotform iframe on the page showing that form ID, once per form ID || `ninja-forms.js` | Native success event | Radio `forms` channel `submit:response` with no errors, with a MutationObserver fallback |diff --git a/skills/conversion-tracking/assets/snippets/framer-forms.js b/skills/conversion-tracking/assets/snippets/framer-forms.jsindex 4cefaba..e97feeb 100644--- a/skills/conversion-tracking/assets/snippets/framer-forms.js+++ b/skills/conversion-tracking/assets/snippets/framer-forms.js@@ -2,11 +2,17 @@* Detects: form submission. Pushes dataLayer event: framer_form_submitted* From the conversion-tracking skill in Marketing Skills */(function () {- // SUBMIT-BASED BEST EFFORT. Framer exposes no success event, so this fires- // on a submit that passed browser validation and that no other handler- // cancelled. A server-side rejection or spam block still counts. For exact- // counts, set the form to redirect to a thank-you page and use- // thank-you-page.js instead.+ // SUBMIT-BASED BEST EFFORT. Framer cancels the native submit and sends+ // the form by script, so a bubble-phase listener always sees it cancelled+ // and never fires. This listens in the capture phase, before Framer's own+ // handler runs, and fires on a submit that passes browser validation. It+ // is still submit-based, so a server-side rejection, a spam block or any+ // later custom validation still counts. A 2-second debounce per form only+ // collapses rapid repeats (a double click). Framer documents a+ // framer:formsubmit event, but it fires only when the form has a tracking+ // ID set and isn't documented as success-only, so this doesn't rely on+ // it. For exact counts, set the form to redirect to a thank-you page and+ // use thank-you-page.js instead.if (window.__ctDetectFramerForms) return;window.__ctDetectFramerForms = true;window.dataLayer = window.dataLayer || [];@@ -38,9 +44,6 @@if (!formEl || (formEl.tagName || '').toLowerCase() !== 'form') return;if (!isFramerForm(formEl)) return;- // A submission another handler already cancelled never happened.- if (event.defaultPrevented) return;-// Constraint validation gate: an invalid form cannot have submitted.try {if (typeof formEl.checkValidity === 'function' && formEl.checkValidity() === false) return;@@ -48,6 +51,13 @@// constraint validation unavailable — fall through}+ // Collapse rapid repeats on this same form element. Keyed on the+ // element itself, so two forms with the same name, or no name, don't+ // share a timestamp.+ var now = Date.now();+ if (formEl.__ctFramerLastFire && now - formEl.__ctFramerLastFire < 2000) return;+ formEl.__ctFramerLastFire = now;+var formName = formEl.getAttribute('data-framer-name') || formEl.id || '';fireConversion(formName);@@ -57,9 +67,8 @@}if (typeof document !== 'undefined' && document.addEventListener) {- // Bubble phase deliberately. A capture-phase listener runs BEFORE the- // form's own handlers, so it would count submissions that Framer's- // validation goes on to cancel.- document.addEventListener('submit', handleSubmit, false);+ // Capture phase, so this runs before Framer's own handler cancels the+ // native submit.+ document.addEventListener('submit', handleSubmit, true);}})();diff --git a/skills/conversion-tracking/references/conversion-moments.md b/skills/conversion-tracking/references/conversion-moments.mdindex 8666d5a..64741ea 100644--- a/skills/conversion-tracking/references/conversion-moments.md+++ b/skills/conversion-tracking/references/conversion-moments.md@@ -193,10 +193,13 @@ python3 ../scripts/build_recipe.py --tool <slug> --send <google-ads|ga4|meta|lin| `ws-form` | WS Form | form submission | `ws_form_submitted` |**Detection confidence.** Most of these fire on the tool's own success event or on a-confirmed success state, which is exact. Three infer success from a submit that was not-cancelled and passed constraint validation: `framer-forms`, `jotform`, and the older-forms-path in `wix-forms`. They cannot know the server accepted the submission, so a server-error or a spam rejection would still count. Say so if precision matters to the user.+confirmed success state, which is exact. Three infer success from a submit.+`framer-forms` fires on a validated submit, caught before Framer's own handler cancels it.+The `jotform` source-code embed fires on the submit followed by the form's data being+built, once per form. The older-forms path in `wix-forms` fires on a submit that was not+cancelled and passed constraint validation. They cannot know the server accepted the+submission, so a server error or a spam rejection would still count. Say so if precision+matters to the user.## Universal patterns