# Connect analytics to the CRM if relevant

- Check 41.19 · Tracking and analytics setup · Critical
- Source: https://checklist-seo-geo.com/en/tracking-analytics-setup/connect-analytics-crm-if-relevant
- Pass the source of each lead (organic, AI, campaign) to the CRM through hidden fields, then send qualification and sales back to GA4 or Matomo.
- Updated on 2026-11-25
- Licence: CC BY 4.0. Credit “Checklist SEO & GEO” with a link to https://checklist-seo-geo.com/en/tracking-analytics-setup/connect-analytics-crm-if-relevant.
- Plugin checklist-seo-geo: 1.3.1 · https://github.com/maximegaul/checklist-seo-geo

## In short

Connecting the analytics tool to the CRM (Customer Relationship Management software) means making the source of the visit travel with each contact request: the CRM then knows that a given signed quote came from organic search or from a ChatGPT answer. In the other direction, the CRM can send the sales stages (qualified lead, signed customer, amount) back to GA4 or Matomo. The task only concerns sites that sell through forms, quotes or appointments, with a sales cycle handled outside the site.

## Why it matters

The analytics tool sees the visit and the submitted form, then nothing more. The CRM sees the lead, its qualification and the signed revenue, but not where it came from. As long as the two are not linked, SEO is judged on the number of forms, while the only question that matters is: which channels bring in customers?

The gap can be large. A well-ranked blog page can produce many poorly qualified requests; a comparison page cited by an AI assistant can produce few, but signed at a high rate. Without the link, these differences remain invisible and the budget follows lead volume rather than lead value.

The link works in two directions:

| Direction | What travels | Use |
|---|---|---|
| Site to CRM | Source, medium, campaign, landing page, referrer, analytics tool identifier | Sales reports by channel in the CRM |
| CRM to analytics tool | “Qualified lead” and “signed customer” events, with an amount | Value conversions in GA4 or Matomo |

The first direction is enough in most cases and only requires a few hidden fields. The second requires development work and identifier management.

## What it improves

- **Lead quality by channel**: qualification and close rates for organic, AI traffic and campaigns. See [measure lead quality and revenue](https://checklist-seo-geo.com/en/tracking-analytics-setup/measure-lead-quality-revenue).
- **Attributed revenue**: signed revenue is tied to its source, the basis for [calculating ROI](https://checklist-seo-geo.com/en/seo-kpis/calculate-roi).
- **Editorial trade-offs**: the pages that bring in customers, not just forms, become the priority.
- **AI traffic**: its real commercial value becomes measurable, beyond visits.
- **Rankings**: no effect. This is a measurement setup.

## How to check

1. Open the last five leads that came in through the site's form in the CRM. Each one should have a source, a medium, a landing page and a first-visit date filled in, not empty or “unknown”.
2. Send a test lead from a URL `https://www.example.com/contact/?utm_source=test&utm_medium=email&utm_campaign=test-crm`. It must arrive in the CRM with these three values.
3. If the return flow to the analytics tool is in place: qualify the test lead in the CRM and check in GA4 (`Admin > DebugView`, or the Realtime report) or in the Matomo Visits Log that the event arrives.

## How to implement

### Step 1 — Decide whether it is relevant

| Situation | Decision |
|---|---|
| Online shop, payment on the site | Unnecessary: GA4 or Matomo ecommerce already carries the revenue. See [track purchases](https://checklist-seo-geo.com/en/tracking-analytics-setup/track-purchases) |
| Fewer than 10 requests a month | A “How did you hear about us?” question and a spreadsheet are enough |
| Quote requests, appointments, free trials, sales closed offline | Relevant: do at least step 3 |
| Long cycle (B2B, software), sales team, CRM in place | Relevant: steps 3 to 5 |

Prerequisite: form conversions are already tracked. See [track conversions, forms and quote requests](https://checklist-seo-geo.com/en/tracking-analytics-setup/track-conversions-forms-quote-requests).

### Step 2 — Check the legal framework

Linking a visit source to an identified person is processing of personal data. Mention it in the privacy policy, only pass the analytics tool's identifier if the visitor has accepted measurement when your configuration requires it, and keep the fields to the strict minimum. The applicable framework is described in [handle applicable consent requirements](https://checklist-seo-geo.com/en/tracking-analytics-setup/handle-applicable-consent-requirements). If in doubt, have the setup approved by the person in charge of data protection.

### Step 3 — Capture the source and pass it to the CRM

The principle: on arrival on the site, a script records the source of the first visit and of the last one; when the form is submitted, it copies these values into hidden fields.

Add the following hidden fields to the form (adapt the names to your CRM):

```html
<input type="hidden" name="first_source">
<input type="hidden" name="first_medium">
<input type="hidden" name="first_campaign">
<input type="hidden" name="first_landing">
<input type="hidden" name="first_date">
<input type="hidden" name="last_source">
<input type="hidden" name="last_medium">
<input type="hidden" name="last_campaign">
<input type="hidden" name="last_landing">
<input type="hidden" name="channel">
<input type="hidden" name="ga_client_id">
```

Then load this script on every page, after the form or at the end of `<body>`:

```js
(function () {
  var AI = /chatgpt\.com|chat\.openai\.com|perplexity\.ai|gemini\.google\.com|copilot\.microsoft\.com|claude\.ai|chat\.mistral\.ai|chat\.deepseek\.com|grok\.com|meta\.ai/;
  var SEARCH = /(^|\.)(google|bing|qwant|duckduckgo|ecosia|yahoo|yandex|baidu)\./;

  function read(key) {
    try { return JSON.parse(localStorage.getItem(key)); } catch (e) { return null; }
  }

  function write(key, value) {
    try { localStorage.setItem(key, JSON.stringify(value)); } catch (e) {}
  }

  function channelFor(source, medium) {
    if (medium === 'ai-assistant' || AI.test(source)) { return 'AI Assistants'; }
    if (medium === 'organic' || (medium === 'referral' && SEARCH.test(source))) { return 'Organic Search'; }
    if (medium === 'email') { return 'Email'; }
    if (medium === 'social') { return 'Social'; }
    if (/^(cpc|ppc|paid)/.test(medium)) { return 'Paid'; }
    if (source === '(direct)') { return 'Direct'; }
    return 'Referral';
  }

  var params = new URLSearchParams(window.location.search);
  var referrerHost = '';

  try { referrerHost = document.referrer ? new URL(document.referrer).hostname : ''; } catch (e) {}

  var isInternal = referrerHost === window.location.hostname;
  var touch = null;

  if (params.get('utm_source')) {
    touch = {
      source: params.get('utm_source').toLowerCase(),
      medium: (params.get('utm_medium') || '(not set)').toLowerCase(),
      campaign: (params.get('utm_campaign') || '').toLowerCase()
    };
  } else if (referrerHost && !isInternal) {
    touch = { source: referrerHost, medium: 'referral', campaign: '' };
  } else if (!referrerHost && !read('attr_first')) {
    touch = { source: '(direct)', medium: '(none)', campaign: '' };
  }

  if (touch) {
    touch.landing = window.location.pathname;
    touch.date = new Date().toISOString().slice(0, 10);
    touch.channel = channelFor(touch.source, touch.medium);

    if (!read('attr_first')) { write('attr_first', touch); }

    if (touch.source !== '(direct)' || !read('attr_last')) { write('attr_last', touch); }
  }

  function fill(form) {
    var first = read('attr_first') || {};
    var last = read('attr_last') || first;
    var values = {
      first_source: first.source, first_medium: first.medium, first_campaign: first.campaign,
      first_landing: first.landing, first_date: first.date,
      last_source: last.source, last_medium: last.medium, last_campaign: last.campaign,
      last_landing: last.landing, channel: last.channel
    };

    Object.keys(values).forEach(function (name) {
      var input = form.querySelector('input[name="' + name + '"]');
      if (input && values[name]) { input.value = values[name]; }
    });

    var gaInput = form.querySelector('input[name="ga_client_id"]');
    if (gaInput && typeof gtag === 'function') {
      gtag('get', 'G-XXXXXXXXXX', 'client_id', function (id) { gaInput.value = id || ''; });
    }
  }

  document.querySelectorAll('form').forEach(fill);
})();
```

Replace `G-XXXXXXXXXX` with your measurement ID. The script only reads `localStorage` inside a `try`, because it may be unavailable (private browsing, blocked storage); the form is then submitted without these values, without an error. If your consent banner must block this storage, only load the script after consent. With Matomo, add a hidden field `matomo_visitor_id` and fill it in `fill` with `_paq.push([function () { form.querySelector('input[name="matomo_visitor_id"]').value = this.getVisitorId(); }]);`: `getVisitorId()` returns the 16-character visitor ID.

The channel calculated here is only a readable label for the CRM; the reference remains your analytics tool's channel. Keep the same AI domain lists in both as in [create a dedicated channel for AI traffic](https://checklist-seo-geo.com/en/tracking-analytics-setup/create-dedicated-channel-ai-traffic).

**WordPress.** Most form plugins offer a hidden field type; give the fields exactly the names above and load the script through your theme or a code snippet manager. Some forms load after the page: in that case, call `fill` on the form's display event.

**CRM forms embedded in the site** (HubSpot, Salesforce Web-to-Lead, Pipedrive): add the hidden fields in the CRM's form editor, then check that the embedded form exposes its fields in the page; otherwise, pass the values through the pre-fill options documented by the vendor.

### Step 4 — Prepare the fields in the CRM

| CRM field | Type | Filled by |
|---|---|---|
| First visit source | Text | `first_source` |
| First visit medium | Text | `first_medium` |
| First visit campaign | Text | `first_campaign` |
| First visit landing page | Text | `first_landing` |
| First visit date | Date | `first_date` |
| Last visit source | Text | `last_source` |
| Channel | Picklist | `channel` |
| GA4 client ID | Text | `ga_client_id` |
| How did you hear about us? | Picklist | The prospect, with an option “An AI assistant (ChatGPT, Perplexity…)” |

Where to create them:

- **HubSpot**: custom contact properties, in the data management settings. HubSpot also records its own original source for contacts tracked by its code; keep your fields as the common reference shared with GA4.
- **Salesforce**: `Setup > Object Manager > Lead > Fields & Relationships > New` (Configuration > Gestionnaire d'objets in the French interface). Then map these fields to the account, contact and opportunity with the “Map Lead Fields” button on the same page, otherwise they are lost when the lead is converted.
- **Pipedrive**: custom fields on the person or the deal, in the company settings.
- **Another CRM or a spreadsheet**: one column per field; integration goes through the CRM's API or a connector such as Zapier.

Menu labels change from one version to the next: follow your CRM's documentation, linked in “Resources”.

### Step 5 — Send sales stages back to the analytics tool

Only do this if you want to see value conversions in GA4 or Matomo. Otherwise, the CRM's reports are enough.

**GA4 through the Measurement Protocol.** Create a secret: `Admin > Data collection and modification > Data streams > (your web stream) > Measurement Protocol API secrets > Create`. When the lead's status changes in the CRM, send from the server:

```bash
curl -X POST "https://www.google-analytics.com/mp/collect?measurement_id=G-XXXXXXXXXX&api_secret=YOUR_SECRET" \
  -H "Content-Type: application/json" \
  -d '{
    "client_id": "1234567890.1700000000",
    "events": [{
      "name": "qualify_lead",
      "params": { "currency": "EUR", "value": 1500 }
    }]
  }'
```

`client_id` is the value of the lead's `ga_client_id` field. Use the events Google recommends for lead generation: `generate_lead`, `qualify_lead`, `disqualify_lead`, `working_lead`, `close_convert_lead`, `close_unconvert_lead`, with `currency` whenever `value` is set. Mark them as key events in `Admin > Data display > Events`. Test first on `https://www.google-analytics.com/debug/mp/collect`, which validates the format without recording anything.

A limit to be aware of: an event can only be backdated by 72 hours. A contract signed three months after the visit therefore arrives in GA4 on the date it is sent, tied to the user but not necessarily to the original visit in the reports. That is why the source stored in the CRM in step 3 remains the reference.

**Matomo through the HTTP Tracking API.** Create a “Signed customer” goal without an automatic trigger, then send:

```bash
curl "https://matomo.example.com/matomo.php" \
  --data-urlencode "idsite=1" \
  --data-urlencode "rec=1" \
  --data-urlencode "_id=0123456789abcdef" \
  --data-urlencode "idgoal=3" \
  --data-urlencode "revenue=1500" \
  --data-urlencode "url=https://www.example.com/crm/client-signe" \
  --data-urlencode "_rcn=crm" \
  --data-urlencode "token_auth=YOUR_TOKEN"
```

`_id` is the 16-character hexadecimal visitor ID passed through the `matomo_visitor_id` field. `token_auth` is required if you backdate the conversion by more than 24 hours with `cdt`. Keep this token on the server side, never in a public page.

> **Good to know:** Google Ads and Microsoft Advertising offer their own offline conversion imports for paid campaigns. They add nothing to the measurement of organic and AI traffic; only set them up if you buy advertising.

### Step 6 — Check every month

- Share of leads with a source filled in: aim for almost all leads from the form; a drop points to a modified form or a broken script.
- Comparison of the month's lead count in the CRM and in the analytics tool: a lasting gap points to duplicates or blocked collection. See [fix duplicate conversions](https://checklist-seo-geo.com/en/tracking-analytics-setup/fix-duplicate-conversions).
- Consistent values: no `Email` and `email` side by side, no empty source with a channel filled in.

## Common mistakes

- **Keeping only the last source**: the first visit, often organic or AI, disappears behind the direct visit that precedes the form.
- **Losing the fields when the lead is converted** in Salesforce, for lack of a mapping to the opportunity.
- **Letting salespeople enter the source by hand** without a closed list: “Google”, “google”, “Internet”, “web” become four sources.
- **Sending the email address or name to GA4**: the Google Analytics terms of service prohibit sending data that can identify a person.
- **Exposing the Measurement Protocol secret or the Matomo `token_auth`** in public JavaScript code.
- **Building the CRM-to-GA4 return flow before having clean sources in the CRM**: the first direction is what brings most of the value.

## Frequently asked questions

### How do you know which customers come from organic search?

Record the visit source in the contact form, through hidden fields filled by a script that reads the UTM parameters and the referrer. The CRM then receives, with each lead, the source, medium and landing page of the first and last visits. You then just need to filter signed customers whose channel is Organic Search.

### Can you send CRM sales into Google Analytics 4?

Yes, with the GA4 Measurement Protocol: the server sends an event such as qualify_lead or close_convert_lead, with an amount and the GA4 client ID recorded when the form was submitted. An event can only be backdated by 72 hours, so a sale closed weeks later arrives on the date it is sent. The source stored in the CRM therefore remains the reference for attribution.

### Do you need a paid CRM to link analytics and sales?

No. For a small business, a form with hidden fields that sends requests by email or into a spreadsheet is enough: each row carries the source, landing page and date of the first visit, and you add the status and signed amount by hand. A CRM becomes useful when the volume of leads or the size of the sales team makes the spreadsheet unmanageable.

### How do you measure customers who came from ChatGPT or Perplexity?

The capture script classifies the visit's referrer or utm_source parameter: chatgpt.com, perplexity.ai and the other assistant domains are given the AI Assistants channel, passed to the CRM with the lead. Add a “How did you hear about us?” question to the form with an option dedicated to AI assistants, because some of these visits arrive without a referrer and would otherwise be counted as direct traffic.

## Resources

- [Google Analytics: Measurement Protocol, send events](https://developers.google.com/analytics/devguides/collection/protocol/ga4/sending-events)
- [Google Analytics: Recommended events (lead generation)](https://developers.google.com/analytics/devguides/collection/ga4/reference/events)
- [Google Analytics: Read the client ID with gtag get](https://developers.google.com/tag-platform/gtagjs/reference#get)
- [Matomo: HTTP Tracking API](https://developer.matomo.org/api-reference/tracking-api)
- [HubSpot Knowledge Base](https://knowledge.hubspot.com/), [Salesforce Help](https://help.salesforce.com/) and [Pipedrive Help Center](https://support.pipedrive.com/)

Next steps: [measure lead quality and revenue](https://checklist-seo-geo.com/en/tracking-analytics-setup/measure-lead-quality-revenue) and [track organic revenue](https://checklist-seo-geo.com/en/seo-kpis/track-organic-revenue).
