Skip to content

coreyhaines31/marketingskills / skills/conversion-tracking

conversion-tracking

Verified

When the user wants to set up, audit, or fix conversion tracking to Google Ads, Meta, GA4, LinkedIn, and TikTok, or asks why conversions are missing or doubled: GTM, pixels, CAPI, Enhanced Conversions, offline imports. Fire on confirmed success, not the submit click; verify a test conversion arrives; diagnose before changing; offer free paths and disclose partner tools. For tracking plans, see analytics. For attribution, see attribution. For bidding, see ads.

FileKindSize
SKILL.mdskill md29.8 KB
assets/gtm-recipes/README.mdmarkdown6.3 KB
assets/gtm-recipes/detect/detect-acuity-scheduling.jsonconfig7.0 KB
assets/gtm-recipes/detect/detect-cal-com.jsonconfig8.8 KB
assets/gtm-recipes/detect/detect-calendly.jsonconfig7.7 KB
assets/gtm-recipes/detect/detect-contact-form-7.jsonconfig6.3 KB
assets/gtm-recipes/detect/detect-divi-forms.jsonconfig5.0 KB
assets/gtm-recipes/detect/detect-elementor-forms.jsonconfig4.4 KB
assets/gtm-recipes/detect/detect-file-download.jsonconfig5.0 KB
assets/gtm-recipes/detect/detect-fluent-forms.jsonconfig6.8 KB
assets/gtm-recipes/detect/detect-formidable-forms.jsonconfig10.8 KB
assets/gtm-recipes/detect/detect-forminator.jsonconfig5.5 KB
assets/gtm-recipes/detect/detect-framer-forms.jsonconfig6.3 KB
assets/gtm-recipes/detect/detect-generic-ajax-form.jsonconfig7.8 KB
assets/gtm-recipes/detect/detect-gravity-forms.jsonconfig15.4 KB
assets/gtm-recipes/detect/detect-hubspot-forms.jsonconfig9.3 KB
assets/gtm-recipes/detect/detect-jotform.jsonconfig3.8 KB
assets/gtm-recipes/detect/detect-ninja-forms.jsonconfig8.4 KB
assets/gtm-recipes/detect/detect-phone-click.jsonconfig4.6 KB
assets/gtm-recipes/detect/detect-squarespace-forms.jsonconfig18.5 KB
assets/gtm-recipes/detect/detect-tally.jsonconfig10.4 KB
assets/gtm-recipes/detect/detect-thank-you-page.jsonconfig6.2 KB
assets/gtm-recipes/detect/detect-typeform.jsonconfig7.9 KB
assets/gtm-recipes/detect/detect-webflow-forms.jsonconfig5.6 KB
assets/gtm-recipes/detect/detect-wix-forms.jsonconfig9.5 KB
assets/gtm-recipes/detect/detect-wix-scheduling.jsonconfig5.1 KB
assets/gtm-recipes/detect/detect-wpforms.jsonconfig11.1 KB
assets/gtm-recipes/detect/detect-ws-form.jsonconfig4.7 KB
assets/gtm-recipes/event-map.jsonconfig3.1 KB
assets/gtm-recipes/send/ga4.jsonconfig1.8 KB
assets/gtm-recipes/send/google-ads.jsonconfig2.7 KB
assets/gtm-recipes/send/linkedin.jsonconfig3.8 KB
assets/gtm-recipes/send/meta.jsonconfig4.1 KB
assets/gtm-recipes/send/microsoft.jsonconfig4.0 KB
assets/gtm-recipes/send/tiktok.jsonconfig4.4 KB
assets/snippets/README.mdmarkdown17.3 KB
assets/snippets/acuity-scheduling-field.htmlother1.3 KB
assets/snippets/acuity-scheduling.jsscript3.3 KB
assets/snippets/cal-com.jsscript5.5 KB
assets/snippets/calendly.jsscript4.8 KB
assets/snippets/contact-form-7.jsscript3.9 KB
assets/snippets/divi-forms.jsscript2.6 KB
assets/snippets/elementor-forms.jsscript2.0 KB
assets/snippets/file-download.jsscript3.2 KB
assets/snippets/fluent-forms.jsscript4.3 KB
assets/snippets/formidable-forms.jsscript8.2 KB
assets/snippets/forminator.jsscript3.1 KB
assets/snippets/framer-forms.jsscript3.9 KB
assets/snippets/generic-ajax-form.jsscript5.9 KB
assets/snippets/gravity-forms.jsscript12.8 KB
assets/snippets/hubspot-forms.jsscript6.8 KB
assets/snippets/jotform.jsscript1.4 KB
assets/snippets/ninja-forms.jsscript5.9 KB
assets/snippets/phone-click.jsscript2.8 KB
assets/snippets/squarespace-forms.jsscript15.3 KB
assets/snippets/tally.jsscript7.5 KB
assets/snippets/thank-you-page.jsscript4.3 KB
assets/snippets/typeform.jsscript5.0 KB
assets/snippets/webflow-forms.jsscript3.2 KB
assets/snippets/wix-forms.jsscript7.0 KB
assets/snippets/wix-scheduling.jsscript2.7 KB
assets/snippets/wpforms.jsscript8.6 KB
assets/snippets/ws-form.jsscript2.3 KB
evals/evals.jsonconfig21.0 KB
references/audit-playbook.mdmarkdown12.6 KB
references/browser-side.mdmarkdown22.5 KB
references/conversion-moments.mdmarkdown31.3 KB
references/discrepancies.mdmarkdown13.4 KB
references/ecommerce-platforms.mdmarkdown9.9 KB
references/google-ads.mdmarkdown29.6 KB
references/meta.mdmarkdown17.8 KB
references/other-platforms.mdmarkdown19.5 KB
references/server-side.mdmarkdown31.2 KB
scripts/build_recipe.pyscript10.8 KB
scripts/check_recipes.pyexecutablescript3.2 KB

assets/snippets/formidable-forms.js

View on GitHub
/*! Formidable Forms conversion detection (MIT)
 *  Detects: form submission. Pushes dataLayer event: formidable_forms_submitted
 *  From the conversion-tracking skill in Marketing Skills */
(function () {
  'use strict';

  // Shared with the recipe snippet so template + recipe installation is one listener.
  if (window.__ctDetectFormidableForms) return;
  window.__ctDetectFormidableForms = true;
  if (!/^https?:$/.test(window.location.protocol)) return;
  window.dataLayer = window.dataLayer || [];

  var MARKER_KEY = '__ctDetectFormidableNativePendingV2';
  var MARKER_TTL_MS = 60000;
  var handledResponses = typeof WeakSet === 'function' ? new WeakSet() : [];
  var activeAttempts = [];
  var jqueryHooked = false;

  function safeId(value) {
    var id = String(value || '');
    return /^[1-9][0-9]*$/.test(id) ? id : '';
  }

  // Formidable's hidden form_id is non-sensitive structural metadata. No other
  // field value, response property, label, HTML, or rendered text is inspected.
  function formId(form) {
    if (!form || typeof form.querySelector !== 'function') return '';
    try {
      var input = form.querySelector('input[name="form_id"]');
      return input && input.getAttribute ? safeId(input.getAttribute('value')) : '';
    } catch (e) {
      return '';
    }
  }

  function wrapperFor(id) {
    if (!id) return null;
    try { return document.getElementById('frm_form_' + id + '_container'); } catch (e) { return null; }
  }

  function hasNode(scope, selector) {
    if (!scope || typeof scope.querySelector !== 'function') return false;
    try { return !!scope.querySelector(selector); } catch (e) { return false; }
  }

  function hasRejectionMarker(id) {
    return hasNode(wrapperFor(id), '.frm_error, .frm_error_style, .frm_blank_field, [aria-invalid="true"]');
  }

  function hasSuccessMarker(id) {
    return hasNode(wrapperFor(id), '.frm_message');
  }

  function responseWasHandled(response) {
    if (!response || (typeof response !== 'object' && typeof response !== 'function')) return true;
    if (typeof WeakSet === 'function' && handledResponses instanceof WeakSet) {
      if (handledResponses.has(response)) return true;
      handledResponses.add(response);
      return false;
    }
    for (var i = 0; i < handledResponses.length; i++) {
      if (handledResponses[i] === response) return true;
    }
    handledResponses.push(response);
    if (handledResponses.length > 100) handledResponses.shift();
    return false;
  }

  function push(id) {
    if (!id) return;
    window.dataLayer.push({ event: 'formidable_forms_submitted', form_id: id });
  }

  // Optional Method 2 adapter owns any enriched push. The detector passes only
  // structural metadata and accepts only a literal true handled verdict; it
  // never receives or inspects an adapter payload.
  function emitAccepted(id, form, source) {
    var handled = false;
    try {
      if (typeof window.__ctFormidableMethod2Emit === 'function') {
        handled = window.__ctFormidableMethod2Emit(id, form, source) === true;
      }
    } catch (e) {}
    if (!handled) push(id);
  }

  // In 6.32.1 these are jQuery events: formidable.js calls
  // jQuery(document).trigger(name, [form, response]). addEventListener does not
  // receive these success events. The response is used only by object identity
  // so the redirect and completion callbacks for one response count once.
  function onAjaxSuccess(event, form, response) {
    var id = formId(form);
    if (!id || !response || responseWasHandled(response)) return;
    emitAccepted(id, form, 'ajax');
    disarmAttempt(form);
  }

  function hookJquery() {
    if (jqueryHooked) return true;
    var jq = window.jQuery || window.$;
    if (typeof jq !== 'function') return false;
    jq(document).on(
      'frmFormComplete.ctRecipe frmBeforeFormRedirect.ctRecipe',
      onAjaxSuccess
    );
    jqueryHooked = true;
    return true;
  }

  function readMarker() {
    try {
      var raw = window.sessionStorage.getItem(MARKER_KEY);
      if (!raw) return null;
      window.sessionStorage.removeItem(MARKER_KEY);
      var marker = JSON.parse(raw);
      if (!marker || typeof marker !== 'object') return null;
      if (typeof marker.t !== 'number' || Date.now() < marker.t || Date.now() - marker.t > MARKER_TTL_MS) return null;
      if (marker.hadSuccessAtSubmit === true) return null;
      return { id: safeId(marker.id), origin: marker.origin, path: marker.path };
    } catch (e) {
      try { window.sessionStorage.removeItem(MARKER_KEY); } catch (e2) {}
      return null;
    }
  }

  // Native success either renders a form-specific message or redirects away
  // from the submitted form. Rejection stays on the form page with errors.
  // Only origin and pathname are retained, never query strings or form answers.
  function processNativeMessage() {
    var marker = readMarker();
    if (!marker || !marker.id || hasRejectionMarker(marker.id)) return;
    var redirected = marker.origin === window.location.origin &&
      typeof marker.path === 'string' && marker.path !== window.location.pathname &&
      !wrapperFor(marker.id) && !hasNode(document, '.frm_error, .frm_error_style');
    if (hasSuccessMarker(marker.id) || redirected) {
      var wrapper = wrapperFor(marker.id);
      var form = null;
      try { form = wrapper && wrapper.querySelector ? wrapper.querySelector('form') : null; } catch (e) {}
      emitAccepted(marker.id, form, 'native');
    }
  }

  function getAttempt(form) {
    for (var i = 0; i < activeAttempts.length; i++) {
      if (activeAttempts[i].form === form) return activeAttempts[i];
    }
    return null;
  }

  function disarmAttempt(form) {
    var attempt = getAttempt(form);
    if (!attempt) return;
    try { window.removeEventListener('pagehide', attempt.onPageHide, true); } catch (e) {}
    var index = activeAttempts.indexOf(attempt);
    if (index !== -1) activeAttempts.splice(index, 1);
  }

  function armNativeMessageAttempt(event) {
    var form = event && event.target;
    if (!form || String(form.tagName || '').toLowerCase() !== 'form') return;
    var isFormidable = false;
    try { isFormidable = !!(form.closest && form.closest('.frm_forms')); } catch (e) {}
    if (!isFormidable) return;
    var id = formId(form);
    if (!id) return;
    var wrapper = wrapperFor(id);
    var hadSuccessAtSubmit = hasNode(wrapper, '.frm_message');
    var prior = getAttempt(form);
    if (prior) disarmAttempt(form);
    var attempt = { form: form, id: id, hadSuccessAtSubmit: hadSuccessAtSubmit, event: event, armedAt: Date.now(), onPageHide: null };
    attempt.onPageHide = function () {
      disarmAttempt(form);
      // Old server errors remain visible while a corrected native POST leaves.
      // Decide acceptance from the response page, not the departing page.
      if (attempt.hadSuccessAtSubmit) return;
      // A submit whose default was prevented never navigated natively: its
      // result arrives through frmFormComplete / frmBeforeFormRedirect, which
      // disarm this attempt on success. An AJAX submit that failed validation
      // must not leave this listener armed, or any later same-origin
      // navigation would be mistaken for the redirect of a native POST.
      if (attempt.event && attempt.event.defaultPrevented === true) return;
      try {
        window.sessionStorage.setItem(MARKER_KEY, JSON.stringify({
          // The TTL runs from the submit, not from this pagehide: a native
          // POST leaves the page within seconds of the submit, so a marker
          // stamped minutes later must read as expired on the next page.
          t: attempt.armedAt,
          id: attempt.id,
          hadSuccessAtSubmit: false,
          origin: window.location.origin,
          path: window.location.pathname
        }));
      } catch (e) {}
    };
    activeAttempts.push(attempt);
    try { window.addEventListener('pagehide', attempt.onPageHide, true); } catch (e) {}
  }

  hookJquery();
  if (!jqueryHooked) {
    document.addEventListener('DOMContentLoaded', hookJquery, { once: true });
    window.addEventListener('load', hookJquery, { once: true });
  }
  document.addEventListener('submit', armNativeMessageAttempt, true);
  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', processNativeMessage, { once: true });
  } else {
    processNativeMessage();
  }
})();
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall