Update analytics profiles when contact territory value changes
When a contact's territory changes in your CRM, their analytics profile row is updated (or created) with the new territory, so segments and reports stay accurate.
Install it
Set up this Zap for me, read how here: https://zapier.sh/zapier/awesome-zaps/update-analytics-profiles-when-contact-territory-value-changes/
Paste into Claude, ChatGPT, Cursor or any agent.
- Category
- Data & Analytics · Analytics automation
- Author
- Zapier
- Source
- zapier/awesome-zaps, folder zaps/update-analytics-profiles-when-contact-territory-value-changes
Set it up with the CLI
- Add it. Copies the folder into
zaps/update-analytics-profiles-when-contact-territory-value-changes/. Outside a project, it makes one first.npx zap-pack add awesome-zaps/update-analytics-profiles-when-contact-territory-value-changes - Fill in the values in
config.ts, and in any other file the list marks. Replace each one as its comment and SKILL.md say. - Deploy it. Asks for any value still left, signs you in to Zapier if you aren't, then publishes it to your account.
npx zap-pack deploy update-analytics-profiles-when-contact-territory-value-changes - Check it. Its recent runs, with status and errors.
npx zap-pack logs update-analytics-profiles-when-contact-territory-value-changes
zaps/update-analytics-profiles-when-contact-territory-value-changes/
- README.mdWhat it does, for people
- SKILL.mdHow an agent sets it up: what to ask you, and how to test it
- config.tsIts settings 2 to fill in
- connections/google-sheets.tsThe
google-sheetsaccount it uses - connections/hubspot.tsThe
hubspotaccount it uses - triggers/updated-contact-resthook.tsWhat starts it:
hubspotupdated_contact_resthook_v31 to fill in - workflow.tsThe code; each
ctx.stepis a step in the Zap
Agents: add --yes to any command so it never prompts. When it needs an answer only the user can give, it stops and names the flag that supplies it.
SKILL.md
View MarkdownWhat it does
- Trigger: a HubSpot contact's territory property changes (
hubspot,updated_contact_resthook_v3, New Contact Property Change). - HubSpot fetches the full contact: its lifecycle stage, email and territory.
- Skip checks: the run stops if the contact's lifecycle stage is inactive (
unsubscribedorother), or if the territory matches the value already stored in its profile row. - Google Sheets finds the profile row by HubSpot contact ID, then by email if there's no match.
- Google Sheets updates that row, or adds a new one if there's no profile yet. It writes the contact ID, email, territory, lifecycle stage and an updated-at time.
The Zap only writes to the profiles sheet. It never changes the contact in HubSpot.
Ask the user
Each REPLACE_… value is set per person. Resolve names to IDs with the user's own connections; don't ask them to paste an ID you can look up.
| Setting | Where | What goes there |
|---|---|---|
REPLACE_TERRITORY_PROPERTY |
config.ts, TERRITORY_PROPERTY; and triggers/updated-contact-resthook.ts, property_name |
The HubSpot internal name of the territory property, looked up from the user's HubSpot account |
REPLACE_SPREADSHEET_ID |
config.ts, SPREADSHEET_ID |
The profiles sheet, looked up from the user's Google Sheets. Its ID is the long string in its URL |
Also review these defaults with the user:
WORKSHEET_ID: the tab with the profile rows."0"is the first tab.TERRITORY_HEADER: the header of the territory column on that tab.CRM_ID_COLUMN,EMAIL_COLUMN,TERRITORY_COLUMN,LIFECYCLE_COLUMNandUPDATED_AT_COLUMNinconfig.ts(COL$AtoCOL$E): map the user's headers to their column letters, since these are column keys, not header names.INACTIVE_STAGESinworkflow.ts: the lifecycle stages to skip. Defaults tounsubscribedandother.
Before turning it on, confirm a Google Sheet is the right place for analytics profiles. If the analytics system is something else, the write steps need a different app.
Build it
If you can run shell commands, set it up with zap-pack: run npx zap-pack add awesome-zaps/update-analytics-profiles-when-contact-territory-value-changes, replace each REPLACE_… value as this file says, then run npx zap-pack deploy update-analytics-profiles-when-contact-territory-value-changes, which signs the user in to Zapier when it gets there. Otherwise build with Zapier MCP, as the steps below say. No Zapier MCP tools? Read https://docs.zapier.com/mcp/get-started/quickstart.md and follow the page for the app you are running in to get the user connected, then continue with this build.
- Accounts: bind
hubspot(the trigger and the HubSpot step) to the user's HubSpot connection for the portal that owns the contacts, andgoogle-sheets(both sheet steps) to the connection for the account that owns the profiles sheet. - Source: publish
workflow.tsandconfig.ts, with eachREPLACE_…replaced by the user's answer. The same answer fillsproperty_nameintriggers/updated-contact-resthook.ts.triggers/updated-contact-resthook.tsandconnections/are settings, not code: set the workflow's trigger and connection bindings from them. The trigger file names the app by its slug; for the trigger'sselected_api, callsearch_triggerswith that slug, find the row whosekeyis the trigger'sevent, and use<app_key>@<app_version>from it. - Build guide: load Zapier's build guide with
get_zapier_skill("zapier:build-workflows")and follow it to create, test and publish the workflow. - Fields: inspect each action's fields with the user's connections (and sample the trigger) before the first test run, and fix any key in
workflow.tsthat doesn't match.
Test it
Run it once as a draft test with a test HubSpot portal and a test sheet. Use a contact that exists in both, with a territory that differs from the sheet row:
{
"id": "123456789"
}
Check that the matching profile row's territory and updated-at changed and nothing else. Then run it on a contact whose territory is already in the sheet: the run should skip and write nothing. If run-status tools aren't available, check the result in Google Sheets directly. Then publish and confirm the trigger is active. The user deletes the test data, not the agent.
Notes
- Everything runs as steps in one workflow. There is no separate sub-zap.
- The HubSpot field names in the code (
lifecyclestage,email, and the territory property) and the contact ID the trigger delivers are not checked against a live sample. Check them on the first test run. - The workflow reads each contact through the HubSpot connection, so the Zap can't run without one.
- To extend it: post to a Slack channel after the update when a territory move is large, or append a row to a mapping sheet on each change.
- Never commit a real spreadsheet ID or HubSpot portal details.