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/wpforms.js

View on GitHub
/*! WPForms conversion detection (MIT)
 *  Detects: form submission. Pushes dataLayer event: wpforms_form_submitted
 *  From the conversion-tracking skill in Marketing Skills */
/* WPForms listener. Records message and redirect confirmations.
 * Native redirects use a short-lived submission marker and changed pathname.
 * Does not read form values, labels, rendered text/HTML, response bodies,
 * redirect URLs, or URL query strings. */
(function () {
  'use strict';
  if (window.__ctDetectWpforms) return;
  window.__ctDetectWpforms = true;
  if (!/^https?:$/.test(window.location.protocol)) return;
  window.dataLayer = window.dataLayer || [];

  var PENDING_KEY = '__ctWpformsNativePendingV1';
  var PENDING_TTL_MS = 120000;

  function formId(form) {
    var match = /^wpforms-form-(\d+)$/.exec((form && form.id) || '');
    return match ? match[1] : null;
  }
  function confirmationNode(id) {
    if (!id || !/^\d+$/.test(id)) return null;
    try { return document.querySelector('#wpforms-confirmation-' + id); } catch (e) { return null; }
  }
  // A delayed callback can run after another callback has already observed
  // the same inserted node. Deduplicate by node identity, not by form ID, so
  // a later accepted response with a distinct confirmation node still counts.
  var supportsWeakSet = typeof WeakSet === 'function';
  var handledConfirmationNodes = supportsWeakSet ? new WeakSet() : [];
  function markConfirmationSeen(node) {
    if (supportsWeakSet) {
      if (handledConfirmationNodes.has(node)) return false;
      handledConfirmationNodes.add(node);
      return true;
    }
    if (handledConfirmationNodes.indexOf(node) !== -1) return false;
    handledConfirmationNodes.push(node);
    return true;
  }
  function push(id) {
    if (!id || !/^\d+$/.test(id)) return;
    window.dataLayer.push({ event: 'wpforms_form_submitted', form_id: id });
  }
  // Method 2 owns and pushes its enriched payload. The detector sees only a
  // literal handled marker; arbitrary objects or PII are never read/forwarded.
  function emitConfirmed(id, form, mode) {
    var adapter = window.__ctWpformsMethod2Emit;
    try { if (typeof adapter === 'function' && adapter(id, form || null, mode) === true) return; } catch (e) {}
    push(id);
  }
  function discardAdapterSnapshot(id, form, mode) {
    var discard = window.__ctWpformsMethod2Discard;
    try { if (typeof discard === 'function') discard(id, form || null, mode); } catch (e) {}
  }
  function storePending(id) {
    if (!id) return;
    try {
      window.sessionStorage.setItem(PENDING_KEY, JSON.stringify({ id: id, time: Date.now(), path: window.location.pathname }));
    } catch (e) {}
  }
  function takePending() {
    try {
      var raw = window.sessionStorage.getItem(PENDING_KEY);
      if (!raw) return null;
      window.sessionStorage.removeItem(PENDING_KEY);
      var value = JSON.parse(raw);
      if (!value || !/^\d+$/.test(String(value.id || '')) ||
          typeof value.time !== 'number' || Date.now() - value.time > PENDING_TTL_MS ||
          Date.now() < value.time) return null;
      return { id: String(value.id), path: typeof value.path === 'string' ? value.path : null };
    } catch (e) { return null; }
  }
  function hasVisibleErrors(root) {
    var errors = root.querySelectorAll('.wpforms-error, .wpforms-error-container, [aria-invalid="true"]');
    for (var i = 0; i < errors.length; i++) {
      if (errors[i].getClientRects().length) return true;
    }
    return false;
  }
  function processNativeVerdict() {
    var marker = takePending();
    if (!marker) return;
    if (hasVisibleErrors(document)) discardAdapterSnapshot(marker.id, null, 'native-no-confirmation');
    else if (confirmationNode(marker.id)) emitConfirmed(marker.id, null, 'native-message');
    else if (marker.path && marker.path !== window.location.pathname) {
      // A clean submit followed by a new page is the redirect confirmation.
      // An optional Method 2 adapter may attach what it saved on the form page.
      emitConfirmed(marker.id, null, 'native-redirect');
    }
    else discardAdapterSnapshot(marker.id, null, 'native-no-confirmation');
  }

  // Keep one short-lived navigation watcher per form. Client validation can
  // cancel submission, so a submit attempt alone must not leave a marker.
  var nativeWatchers = new WeakMap();
  document.addEventListener('submit', function (event) {
    var form = event && event.target;
    if (!form || (form.tagName || '').toLowerCase() !== 'form') return;
    var id = formId(form);
    if (!id) return;
    var classes = typeof form.className === 'string' ? form.className : '';
    if (/(^|\s)wpforms-ajax-form(\s|$)/.test(classes)) return;
    var previous = nativeWatchers.get(form);
    if (previous) previous();
    var timer;
    function cleanup() {
      window.removeEventListener('pagehide', onPageHide, true);
      clearTimeout(timer);
      nativeWatchers.delete(form);
    }
    function onPageHide() {
      cleanup();
      // A corrected retry can still display the previous server error box.
      // Use the current client-validation result, without reading answers.
      var jq = window.jQuery;
      var validator = typeof jq === 'function' ? jq(form).data('validator') : null;
      if (validator && validator.errorList) {
        if (validator.errorList.length) return;
      } else if (hasVisibleErrors(form)) return;
      storePending(id);
    }
    nativeWatchers.set(form, cleanup);
    window.addEventListener('pagehide', onPageHide, true);
    timer = setTimeout(cleanup, 10000);
  }, true);

  // AJAX message confirmation: the callback alone is ambiguous. Wait until
  // WPForms has inserted a new, form-attributed confirmation node.
  var jqueryHooked = false;
  var redirectEpochByForm = typeof WeakMap === 'function' ? new WeakMap() : null;
  var seenRedirectEvents = typeof WeakSet === 'function' ? new WeakSet() : [];
  var seenSuccessEvents = typeof WeakSet === 'function' ? new WeakSet() : [];
  function markEventSeen(set, event) {
    if (!event || (typeof event !== 'object' && typeof event !== 'function')) return false;
    if (typeof WeakSet === 'function' && set instanceof WeakSet) {
      if (set.has(event)) return false;
      set.add(event);
      return true;
    }
    if (set.indexOf(event) !== -1) return false;
    set.push(event);
    return true;
  }
  function markRedirectEvent(event) {
    return markEventSeen(seenRedirectEvents, event);
  }
  function hookWpformsEvents() {
    if (jqueryHooked) return;
    var jq = window.jQuery || window.$;
    if (typeof jq !== 'function') return;
    jqueryHooked = true;
    jq(document).on('wpformsAjaxSubmitSuccess.ctWpforms', function (event) {
      if (!markEventSeen(seenSuccessEvents, event)) return;
      var form = event && event.target;
      var id = formId(form);
      if (!id) return;
      var redirectEpoch = redirectEpochByForm ? (redirectEpochByForm.get(form) || 0) : 0;
      var before = confirmationNode(id);
      setTimeout(function () {
        var after = confirmationNode(id);
        if (after && after !== before && markConfirmationSeen(after)) {
          emitConfirmed(id, form, 'ajax-message');
        } else if (!redirectEpochByForm || (redirectEpochByForm.get(form) || 0) === redirectEpoch) {
          discardAdapterSnapshot(id, form, 'ajax-no-confirmation');
        }
      }, 0);
    });
    jq(document).on('wpformsAjaxSubmitFailed.ctWpforms wpformsAjaxSubmitError.ctWpforms wpformsAjaxSubmitActionRequired.ctWpforms', function (event) {
      var form = event && event.target;
      var id = formId(form);
      if (id) discardAdapterSnapshot(id, form, 'ajax-rejected');
    });
    // WPForms 1.6.7 triggers this only after ajax_process_redirect has
    // produced a nonempty redirect_url from accepted processing. The URL and
    // response object are intentionally not inspected.
    jq(document).on('wpformsAjaxSubmitBeforeRedirect.ctWpforms', function (event) {
      if (!markRedirectEvent(event)) return;
      var form = event && event.target;
      var id = formId(form);
      if (!id) return;
      if (redirectEpochByForm) redirectEpochByForm.set(form, (redirectEpochByForm.get(form) || 0) + 1);
      emitConfirmed(id, form, 'ajax-redirect');
    });
  }
  function ready() {
    processNativeVerdict();
    hookWpformsEvents();
  }
  // Let sibling Method 2 tags in the same page task install their enrichment
  // delegate before a native confirmation verdict is dispatched.
  if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', ready, { once: true });
  else setTimeout(ready, 0);
  document.addEventListener('DOMContentLoaded', hookWpformsEvents, { once: true });
  window.addEventListener('load', hookWpformsEvents, { once: true });
})();
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