hubspot_check_attribution
HubSpot read low risk
Part of the Tracking Audit Agent.
What it does
Audit how the connected HubSpot portal captures Google paid-search attribution, read-only. Reads the contacts created in the last `days` days (1-90, default 30) whose original source is PAID_SEARCH or that carry a Google click id (hs_google_click_id), paged 200 at a time up to 2,000 contacts. Returns the standard envelope {success:true,data,warnings} where data is {days, window_start, contacts_found, total, truncated, microsoft_excluded, denominator, gbraid_wbraid_only, gclid_filled, gclid_fill_pct, gclid_in_first_url, lost_between_page_and_crm, utm_fill_pct, fields_read, fields_not_found, fields_could_not_be_requested, form_vs_booking:{form_only, booking_only, both, neither}, stages:{lead|marketingqualifiedlead|salesqualifiedlead|opportunity|customer: {current, reached, median_days}}, first_url_with_email, checks:[{item, status, found, expected, evidence, fix, owner, priority}], check_counts}. Each check is pass, problem, not_verified or info. A click id, or utm_source, utm_medium, utm_campaign or utm_term, missing on more than 10% of the Google paid-search contacts is a problem (utm_content is reported, not judged); below 10 contacts a rate is reported as info, not judged. A gclid in the first page URL that no click-id field holds, and an email address in a first page URL (never an asset name such as logo@2x.png), are problems at any volume; a first page URL with only gbraid or wbraid (an iOS click without a gclid) is left out of the click-id rate and counted in gbraid_wbraid_only. A guessed field no contact fills, or a named one HubSpot returns on no contact, is not_verified, with the fields call that names it; hs_google_click_id alone never makes the click id known, so until the client's own field is known a click-id rate that passes is a pass and any other is not_verified; with a booking_tool naming any tool other than HubSpot Meetings (alone or listed with it; 'none' or 'n/a' name none) the form vs booking check is not_verified ('With a person'). Evidence is at most 5 HubSpot record ids per problem; emails, names, page URLs and click-id values are never returned. Requests only non-personal properties: create date, original source and its drill-down 1, first page URL (read to find click ids, msclkid and email addresses, never returned), the click-id fields (hs_google_click_id plus gclid, or the name given in fields), the UTM fields (utm_source, utm_medium, utm_campaign, utm_term, utm_content, or the names given in fields), first conversion, last meeting booked, record source, lifecycle stage and the five stage-entry dates. Microsoft Ads leads (msclkid in the first page URL, or bing in drill-down 1 or the UTM source) are left out of every rate; a contact with a Google click id always counts as Google. A rate limit is waited out once per page (2 s) and a rejected token is refreshed once. If HubSpot refuses a property (400), the read is retried once on the standard properties only and the refused names are listed.
When to use it
Use in the tracking audit (the HubSpot step of tracking_audit) to check GCLID and UTM capture and paid-search lead attribution in HubSpot: click ids lost between the landing page and the CRM, form vs booking leads, stage timing, and email addresses in landing URLs. Not for finding or listing contacts (hubspot_search_contacts).
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
days | integer | no | Window in days, 1-90 (default 30): contacts created since then. |
fields | object | no | The client's own HubSpot property internal names, keyed by canonical name: gclid, utm_source, utm_medium, utm_campaign, utm_term, utm_content -> internal name, e.g. {"gclid": "gclid__c"}. Each replaces the guessed name of the same key; hs_google_click_id is always read. Pass it when a check lists a field as not found. Name hs_google_click_id as gclid when HubSpot's integration is the client's only click-id field. |
booking_tool | string | no | The booking tool web_scan_tags found on the site, e.g. Calendly or HubSpot Meetings. Any tool other than HubSpot Meetings (alone or listed with it; 'none' or 'n/a' name none) makes the form vs booking check not_verified, because its bookings do not set HubSpot's meeting fields. |
Safeguards
Policy
Read-only. Audit ONLY the authorizing client's own HubSpot contacts, as counts, rates and record ids: never return, quote or store an email, name, page URL or click-id value, never pull data across client boundaries, and never present a guessed field as the client's. A field that could not be read is reported as not verified, never as empty.
Reminder
Rates cover Google paid-search contacts only (Microsoft Ads leads are left out), and HubSpot keeps only the most recent Google click id per contact. When a check lists a field as not found, ask the user for the client's internal name and call again with fields; pass booking_tool from web_scan_tags.
Errors
| Error class | Means | What to do | Retry |
|---|---|---|---|
connection_not_found | HubSpot is not connected for this Scalix account. | Connect HubSpot in the Scalix dashboard, then call again. | no |
needs_reauth | HubSpot rejected the access token after one refresh (401), or the connection has no portal. | Reconnect HubSpot in the Scalix dashboard. | no |
account_forbidden | HubSpot is turned off for Claude in the Scalix dashboard. | Turn it on under Choose accounts in the Scalix dashboard. | no |
forbidden | The connection lacks crm.objects.contacts.read (403 MISSING_SCOPES). | Reconnect HubSpot so it grants the contacts read scope; surface the missing scope. | no |
invalid_argument | days outside 1-90, or fields not an object of canonical name -> internal name; or HubSpot's 400 again after the retry on standard properties only. | Fix the argument named in the message; for HubSpot's own 400, surface its exact message. | no |
rate_limited | HubSpot 429 again after one 2-second wait on that page (search allows about 5 requests per second per portal), or the portal's daily limit (not retryable). | Wait 10 seconds and call again; after the daily limit, retry after midnight in the portal's time zone. | yes |
preview_mismatch | The connected HubSpot portal changed while the call ran (a reconnect during the token refresh); nothing was retried. | Call the tool again: it now runs against the newly connected portal. | no |
unavailable | HubSpot could not be reached, or did not answer. | Retry shortly. | yes |
hubspot_error | HubSpot server error (5xx), or another 4xx rejection carrying HubSpot's message. | Retry shortly for a 5xx; otherwise surface HubSpot's message. | yes |
Edge cases
- No paid-search contacts created in the window: every number is zero and the only check is not_verified (is the HubSpot tracking code on the site, and is this the client's portal?); fields_not_found is empty.
- More than 2,000 matching contacts: truncated is true, a warning says how many were read, and the numbers cover those; a shorter window reads fewer.
- HubSpot has no standard UTM property and the app cannot read the portal's schema, so gclid and utm_* are guessed names: a guessed field no contact fills, or a named one HubSpot returns on no contact, is listed in fields_not_found and its check is not_verified until the client's field is named with fields.
- A property HubSpot refuses (400): the read is retried once without the guessed and named custom properties; they are listed in fields_could_not_be_requested and their checks are not_verified.
- Below 10 Google paid-search contacts the fill rates and the form vs booking split are info, not problems.
- A contact with both a Microsoft and a Google signal (msclkid and a gclid) counts as Google.
- Stages: reached counts the hs_v2_date_entered_* dates, current counts lifecyclestage; median_days runs from createdate to the stage date and is null when no contact reached it.
- Search indexing lags a few moments: a contact created seconds ago may be missing.