HubSpot Forms AEO Source Tracking: capturing AI attribution on submit

How Lantern wires HubSpot Forms to capture ai_source, ai_engine, and ai_prompt on every submission — including hidden field setup that survives page refreshes and cross-domain embeds.

Updated 2026-04-20 · HubSpot integration · ~6 min read

What this does

HubSpot Forms are where most contacts are actually created. If AI source data isn't captured at form submit, you lose attribution for the single most important event in the funnel. Lantern configures three hidden fields (ai_source, ai_engine, ai_prompt) on every HubSpot form, pre-populates them from the first-party cookie Lantern set on landing, and validates the values against the AI engine allowlist.

How Lantern fits

The configuration is automatic for forms embedded via HubSpot's standard embed snippet — Lantern's JS intercepts form init, injects the hidden fields, and pre-populates values from lantern_ai_src cookie. For forms embedded via the raw HubSpot API (common in React/Vue apps), you add two lines of code. Lantern's customer-success docs include copy-paste React and Vue wrappers.

Setup preview

For standard HubSpot embedded forms: nothing to do. Lantern's snippet wires the hidden fields automatically. For React/Next.js apps using the HubSpot Forms API (hbspt.forms.create): add an onFormReady callback that calls the Lantern helper function. For non-HubSpot forms that post to HubSpot (custom API calls): include the ai_source, ai_engine, ai_prompt fields in the contact properties payload.

HubSpot Forms API with AI source injection (React) · javascript
// React component: HubSpot form with AEO source tracking
import { useEffect, useRef } from 'react';

export function HubSpotForm({ portalId, formId }) {
  const formRef = useRef(null);

  useEffect(() => {
    const script = document.createElement('script');
    script.src = '//js.hsforms.net/forms/v2.js';
    script.onload = () => {
      window.hbspt.forms.create({
        portalId,
        formId,
        target: '#hubspot-form-container',
        onFormReady: (form) => {
          // Lantern AEO hidden field injection
          const aiSrc = window.Lantern?.getAISource() || '';
          const aiEngine = window.Lantern?.getAIEngine() || '';
          const aiPrompt = window.Lantern?.getAIPrompt() || '';

          // Append hidden inputs
          const form$ = form[0];
          ['ai_source', 'ai_engine', 'ai_prompt'].forEach((name, i) => {
            const input = document.createElement('input');
            input.type = 'hidden';
            input.name = name;
            input.value = [aiSrc, aiEngine, aiPrompt][i];
            form$.appendChild(input);
          });
        }
      });
    };
    document.head.appendChild(script);
  }, [portalId, formId]);

  return <div id="hubspot-form-container" ref={formRef} />;
}

Where this fits in the bigger picture

This page describes one specific surface inside HubSpot where Lantern's AEO pipeline attribution plugs in. The full integration stitches together across HubSpot Contacts, Deals, Workflows, Lists, Reports, Forms, CMS, and the Marketing/Sales/Service Hub stack. If you're evaluating where to start, the comparison hub has side-by-side comparisons of Lantern against Profound, Scrunch, Peec AI, AthenaHQ, and HubSpot's own AEO product — scored on the dimensions that matter for a CMO buyer (CRM integration depth, reporting quality, prompt-scaling economics).

If you're about to walk this work into a renewal review or budget conversation, the CFO's Guide to AEO Budget Defense has the memo template, the five-slide deck structure, the attribution-math cheat sheet, and the three most-common CFO objections with counter-arguments. It's the long-form companion that translates the technical HubSpot setup on this page into a defensible dollar number for finance.

FAQ

Common questions.

What if the AI cookie is set after the form loaded (SPA edge case)?
Lantern's JS listens for cookie changes and re-injects hidden field values on form interaction if they were empty at form mount. This handles the SPA case where the landing page and form page are different route renders.
Does this work with HubSpot Marketing Forms AND CRM Forms?
Both. HubSpot has two form products (Marketing Hub forms and standalone CRM forms). Lantern's wiring works on both. The hidden-field approach is universal to HubSpot's form API.
Can I require ai_source to be present before form submission?
Technically yes, but we don't recommend it. Only ~30-45% of traffic is AI-sourced, so requiring ai_source would block the majority of legit signups. The correct pattern: allow empty ai_source, let HubSpot's standard Original Source pick up the rest.
What about Google reCAPTCHA and form validation?
Hidden fields don't interfere with reCAPTCHA. Lantern's fields are injected before submit event, so validation runs against the complete payload including AI source data. No conflicts observed in production.

Lantern ships this as a one-click HubSpot install.

Instead of hand-wiring properties, workflows, and tracking snippets, Lantern installs the full HubSpot integration in under 30 minutes — then ships the monthly AEO pipeline ROI report your CFO signs off on. $99/mo Starter or Enterprise. 14-day free trial.

Start free trial