Free tool

See which leads came from ChatGPT

A free snippet that tags visitors from ChatGPT, Perplexity, Gemini, Copilot and Claude, sends a GA4 event and fills a hidden form field, so leads from AI answers show up in your CRM.

AI assistants send few visits, but those visits convert well: Orbit Media found visitors from AI assistants about 3x more likely to become high-intent leads across 97 B2B sites (Orbit Media, Jul 2026). Most CRMs never see them, because the source is lost by the time the form is filled. This snippet keeps it.

1. The snippet

<!-- AI referral tracker by Shruti Kaushik (shrutikaushik.com/tools/ai-referral-tracker). Free to use. -->
<script>
(function () {
  var AI = { 'chatgpt.com': 'chatgpt', 'chat.openai.com': 'chatgpt', 'perplexity.ai': 'perplexity',
    'gemini.google.com': 'gemini', 'copilot.microsoft.com': 'copilot', 'claude.ai': 'claude',
    'chat.deepseek.com': 'deepseek', 'you.com': 'you', 'meta.ai': 'meta_ai', 'grok.com': 'grok' };
  var src = '';
  try {
    var host = document.referrer ? new URL(document.referrer).hostname.replace(/^www\./, '') : '';
    Object.keys(AI).forEach(function (d) { if (host === d || host.endsWith('.' + d)) src = AI[d]; });
    var utm = new URLSearchParams(location.search).get('utm_source') || '';
    Object.keys(AI).forEach(function (d) { if (utm.indexOf(d) === 0 || utm === AI[d]) src = AI[d]; });
    if (src) { localStorage.setItem('ai_source', src); localStorage.setItem('ai_landing', location.pathname); }
    src = localStorage.getItem('ai_source') || '';
  } catch (e) {}
  if (!src) return;
  if (window.gtag) window.gtag('event', 'ai_referral', { ai_source: src });
  function fill() {
    document.querySelectorAll('input[name="ai_source"]').forEach(function (i) { i.value = src; });
    document.querySelectorAll('input[name="ai_landing"]').forEach(function (i) { i.value = localStorage.getItem('ai_landing') || ''; });
  }
  fill(); document.addEventListener('DOMContentLoaded', fill); setTimeout(fill, 2000);
})();
</script>

2. The form fields

<input type="hidden" name="ai_source">
<input type="hidden" name="ai_landing">

Setup

  1. 1Paste the snippetPut it before the closing </head> tag on every page, after your Google Analytics tag.
  2. 2Add two hidden fieldsAdd the two hidden inputs to your demo, contact and signup forms. Map them to two custom fields in HubSpot, Salesforce or your CRM.
  3. 3Mark the event in GA4In GA4, mark ai_referral as a key event and register ai_source as a custom dimension. You will see visits and conversions by assistant.
  4. 4Ask the question tooAdd "How did you hear about us?" as a free-text field. Google counts AI Mode and AI Overviews as organic search, so the self-reported answer catches what referrers miss.

It runs in the visitor’s browser, sends nothing to me, and stores only the assistant name and landing page. Want to know whether AI assistants name you at all? Get the free AI visibility check or see founder-led AI visibility.