All posts
SEO & AI search

How to Connect Website Analytics to HubSpot or Salesforce Pipeline

How to connect website analytics to CRM pipeline in HubSpot or Salesforce: UTM rules, first-touch cookies and hidden form fields, so you report revenue.

By Mehdi Hassan8 min read

The short answer

To connect website analytics to CRM pipeline, capture source data on the visitor's first visit, store it in a first-party cookie, and pass it into hidden form fields when they convert. Map those fields to contact and deal properties in HubSpot or Salesforce. Then report pipeline and closed-won by original source, not just visits by channel.

Key takeaways

  • Analytics stops at the form fill. Hidden fields carry the source across into the CRM.
  • Store first-touch UTMs, referrer and landing page in a cookie so they survive multi-day journeys.
  • Keep first-touch fields write-once. Overwriting them on every form fill erases the original source.
  • HubSpot captures source automatically with its tracking code; Salesforce needs hidden fields or a marketing tool.
  • Add the GA4 client ID as a hidden field if you want to join CRM outcomes back to analytics.

Part of Marketing Website Analytics: What B2B Teams Should Actually Measure

Why connect website analytics to CRM pipeline?

You connect website analytics to CRM pipeline so marketing can report revenue by source instead of visits by channel. GA4 knows where a visitor came from but not whether they became a customer. The CRM knows which deals closed but not how the buyer first arrived. Joining the two is what turns a traffic report into a revenue report.

Without the connection, every argument about budget runs on proxies. Paid social looks great on clicks, organic looks great on sessions, and nobody can say which one produced the deals that closed last quarter. With it, you can show which page created the most pipeline, or whether a channel with modest traffic produced the biggest deals.

This how-to is part of our hub on marketing website analytics. It covers the practical setup: UTM rules, a first-touch cookie, hidden fields and CRM properties, with notes for HubSpot and Salesforce.

What data should pass from the website to the CRM?

Pass the data that explains how a buyer arrived, at both the first and the converting visit: UTM parameters, the referrer, the landing page, the page where they converted, and a self-reported source. Store first-touch values once and never overwrite them; store last-touch values on every conversion.

Field

Captured when

Write rule

Example value

First-touch source and medium

First visit

Write once

google / organic

First-touch campaign

First visit with UTMs

Write once

q3-comparison-launch

First landing page

First visit

Write once

/compare/vendor-a

First referrer

First visit

Write once

chatgpt.com

Last-touch source and medium

Each form fill

Overwrite

linkedin / paid-social

Conversion page

Each form fill

Overwrite

/pricing

Self-reported source

Each form fill

Keep raw text

Asked ChatGPT for options

GA4 client ID

Each form fill

Overwrite

Value of the _ga cookie

The referrer field matters more than it used to. Visits from ChatGPT, Perplexity and other AI tools often carry a referrer but no UTMs, so without it they get lumped into "organic" or "direct" in the CRM. Our guide to tracking AI traffic in GA4 lists the hostnames to watch for.

How do you connect website analytics to a CRM, step by step?

You connect website analytics to a CRM in six steps: agree UTM rules, capture source on the first visit, add hidden fields to every form, populate them on submit, map them to CRM properties and build the reports. The work is mostly configuration, with a small script on the site.

  1. Agree a UTM convention

    Write down allowed values for utm_source, utm_medium and utm_campaign, in lowercase, and share a link builder sheet. Inconsistent tags like "LinkedIn", "linkedin" and "li" are the most common reason CRM source reports are unreadable.

  2. Capture first-touch data in a cookie

    On every page load, check for an existing first-touch cookie. If there isn't one, read the UTMs from the URL, the document referrer and the landing page path, and store them in a first-party cookie with a long expiry.

  3. Add hidden fields to every form

    Add hidden inputs for each field in the table above to demo, contact and trial forms. Name them to match the CRM properties you'll create.

  4. Populate the fields on submit

    When the form loads or submits, fill first-touch fields from the cookie, last-touch fields from the current URL and referrer, and the GA4 client ID from the _ga cookie.

  5. Map fields to CRM properties

    Create matching contact properties, and copy the key ones to the deal when it's created. Set first-touch properties so they're only written if empty.

  6. Build pipeline and revenue reports

    Report opportunities created, pipeline value and closed-won, grouped by first-touch source, last-touch source and self-reported source, side by side.

How does the setup differ in HubSpot and Salesforce?

HubSpot does much of this automatically: its tracking code records original source, drill-down details and page views, and attaches them to the contact when a HubSpot form is submitted. Salesforce has no built-in website tracking, so the hidden-field approach, or a marketing automation tool on top, carries the source data in.

Task

HubSpot

Salesforce

Website tracking

Tracking code records visits and source automatically

Not built in; needs hidden fields or a marketing tool

Original source

Set automatically on the contact

Custom fields populated by your hidden fields

Non-native forms

Use the Forms API and pass the hubspotutk cookie

Web-to-Lead or an API integration with hidden fields

Campaign reporting

Campaigns tool and UTM-based source reports

Campaigns and campaign influence

Self-reported field

Custom contact property

Custom lead and contact field

Even on HubSpot, add your own first-touch landing page, referrer and self-reported fields. HubSpot's built-in source buckets are useful but coarse, and they don't separate AI referrals cleanly. If you're thinking of moving the website off HubSpot while keeping the CRM, our guides to leaving HubSpot CMS and HubSpot CMS alternatives that keep your CRM explain how to preserve this tracking.

Joining CRM outcomes back to GA4

Passing the GA4 client ID into a hidden field gives you a key that links a CRM record to the analytics user who converted. With it, you can export closed-won deals and import them into GA4 as offline events, or send them through the Measurement Protocol, so GA4 reports can show which sources led to revenue, not just form fills.

This is optional and takes developer time to do well. It's worth it once you have enough closed deals per quarter to see patterns, and when your team works mainly in GA4. If your team lives in the CRM, reporting there is simpler. Either way, check your consent setup first: only collect the client ID where the visitor's consent choices allow analytics cookies.

How do you check the connection works?

Check the connection by running test conversions through each traffic source and confirming the CRM records match. Do it at launch and again after any site change, because redesigns and form swaps are a common way hidden fields break without anyone noticing.

  1. Open the site in a private window with a test UTM link, browse two pages, and submit a demo form.
  2. Confirm the contact in the CRM shows the test source, campaign, landing page and conversion page.
  3. Return a day later from a different source, submit another form, and confirm first-touch values didn't change while last-touch values did.
  4. Repeat with a visit from a link on chatgpt.com to confirm the referrer is captured.
  5. Delete the test contacts afterwards so they don't distort reports.

If you're migrating the site, add this test to the launch checklist. Our guide to analytics continuity in a migration covers the rest of the tracking that tends to break.

What can you report once analytics and CRM are connected?

Once analytics and CRM are connected, you can report pipeline and revenue by source, by landing page and by campaign, and compare what software tracked with what buyers told you. Those are the reports that change budget decisions.

  • Pipeline by first-touch source: which channels introduce the buyers who become opportunities.
  • Closed-won by conversion page: which pages close deals, which tells you where design and copy effort pays.
  • Deal size by source: some channels produce fewer but larger deals.
  • Tracked versus self-reported: where AI research and referrals drive deals that analytics files as Direct. See self-reported attribution.
  • Journey by stage: which pages buyers visit before becoming opportunities, as mapped in our guide to the B2B buyer journey on your website.

If you're tempted to add a multi-touch attribution tool on top, read multi-touch attribution for B2B first. With this connection in place, many teams find the simple reports answer their questions.

Frequently asked questions

Does GA4 integrate directly with HubSpot or Salesforce?
Don't count on a native sync that writes GA4 session data onto each contact. HubSpot relies on its own tracking code, and any GA4 connectors that exist change often, so check the current documentation. The reliable, tool-agnostic approach is hidden form fields that write source data into the CRM, plus an optional client ID field if you want to send outcomes back to GA4.
Do I need a developer to set up hidden fields?
For the first-touch cookie and the script that fills hidden fields, a developer or a technical marketer helps, though it's a small amount of code. Some form tools and CRMs offer built-in UTM capture that handles the current visit. Capturing first touch across multiple visits usually needs the cookie script, which most sites can add through a tag manager.
How long should the first-touch cookie last?
Long enough to cover your typical sales cycle, often several months to a year for B2B. Browser privacy features can shorten cookie lifetimes, especially for cookies set by JavaScript, so expect some first-touch data to be lost for returning visitors. Setting the cookie server-side, as first-party, usually makes it last longer than one set by a script.
What about visitors who decline cookies?
Respect the choice. If a visitor declines analytics cookies, don't store a first-touch cookie or the GA4 client ID for them. You can still capture source data present on the converting visit, like UTMs in the URL, if your consent setup allows it, and the self-reported field still works because the buyer provides it directly on the form.
Should source data live on the contact or the deal?
Both. Contacts hold the raw source data captured from the website. Copy the key fields, like first-touch source and self-reported source, to the deal or opportunity when it's created, so revenue reports can group deals by source without complex joins. In HubSpot, workflows can copy properties automatically; in Salesforce, flows can do the same.

· CEO & Design Director

Copywriter, designer and developer, and founder of Designify Studio. Over five years, 60+ projects across 14+ industries, for startups that have raised $300M+.

Want this done for you? Monthly retainer, $6,000.

Your ongoing design and development team, for products that keep shipping. $6,000, per month, flat fee. Book a free 30-minute call to see if it fits.

Schedule Call