How Lantern sets Original Source Drill-Down, AI Engine, and AI Prompt on every HubSpot contact that arrived via an AI answer engine — including the mobile-referrer-stripped edge cases.
Every contact that arrives from ChatGPT, Perplexity, Claude, or Gemini gets tagged at the moment of creation with a clean, queryable ai_source value — not dumped into 'Direct' or 'Other Campaigns' where HubSpot defaults it. Lantern handles the three hard cases: (1) direct clicks with document.referrer intact, (2) mobile referrer stripped sessions, (3) sessions that hit a middle page before signing up (UTM on first hit is preserved across navigations).
Lantern's JS snippet runs before HubSpot's tracking code and does three things: detects AI hostname in document.referrer, rewrites the URL with utm_source=chatgpt&utm_medium=ai-referral via history.replaceState, stores the source in a first-party cookie with 30-day TTL. When HubSpot's tracking code fires, it sees the UTM and picks up ai_source correctly. The cookie handles the case where a user lands from ChatGPT, browses three pages, then converts on page 4 (referrer is lost but cookie persists).
The snippet Lantern installs is ~1.5KB minified and runs synchronously before HubSpot's _hsq queue initializes. It checks a whitelist of ~30 AI engine hostnames (chat.openai.com, chatgpt.com, perplexity.ai, claude.ai, gemini.google.com, and variations), matches them to engine names, writes the UTM, and sets the lantern_ai_src cookie. If the hostname isn't in the list, the snippet is a no-op — it won't alter normal referrer traffic.
// Lantern AI source detection — inline before HubSpot tracking
(function() {
var AI_HOSTS = {
'chat.openai.com': 'chatgpt',
'chatgpt.com': 'chatgpt',
'openai.com': 'chatgpt',
'perplexity.ai': 'perplexity',
'www.perplexity.ai': 'perplexity',
'claude.ai': 'claude',
'anthropic.com': 'claude',
'gemini.google.com': 'gemini',
'bard.google.com': 'gemini'
};
function getEngine() {
// 1. Check first-party cookie (persists across pages)
var c = document.cookie.match(/lantern_ai_src=([^;]+)/);
if (c) return c[1];
// 2. Check document.referrer
try {
var host = new URL(document.referrer).hostname;
if (AI_HOSTS[host]) return AI_HOSTS[host];
} catch (e) {}
return null;
}
var engine = getEngine();
if (!engine) return;
// Set cookie (30 days)
document.cookie = 'lantern_ai_src=' + engine + ';max-age=2592000;path=/;SameSite=Lax';
// Rewrite URL with UTMs if not already present
var url = new URL(window.location.href);
if (!url.searchParams.has('utm_source')) {
url.searchParams.set('utm_source', engine);
url.searchParams.set('utm_medium', 'ai-referral');
window.history.replaceState({}, '', url.toString());
}
})();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.
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