Skip to content

feat: bind homepage visitor id after authentication#7319

Open
c121914yu wants to merge 5 commits into
labring:mainfrom
c121914yu:codex/source-report-webhook
Open

feat: bind homepage visitor id after authentication#7319
c121914yu wants to merge 5 commits into
labring:mainfrom
c121914yu:codex/source-report-webhook

Conversation

@c121914yu

@c121914yu c121914yu commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • accept visitor_id from the homepage and store it as fastgpt_sem.visitor_id
  • remove fastgpt_source, fastgpt_sem.source, home_source, firstsource, and lastsource
  • report the visitor identity after successful password login
  • report one normalized phone number or email as the visitor contact
  • add failure-safe CRM reporting gated by CRM_API_URL and CRM_API_KEY

Companion PRs

Validation

  • 5 CRM reporter tests passed
  • 43 visitor ID and login tests passed across 3 targeted test files

Notes

  • rebased onto the latest upstream/main
  • app typecheck is currently blocked by an unrelated upstream missing asset: @/assets/skill/runtimeUpgradeModalBg.jpg

Copilot AI review requested due to automatic review settings July 16, 2026 12:20

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 008ec7937c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

'bd_vid',
'msclkid',
'k',
'source',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid stripping the generic source query globally

Because useInitApp is mounted from projects/app/src/pages/_app.tsx, every page treats entries in this list as marketing-only parameters and getPathWithoutMarketingParams() removes them from the URL. Adding the generic source key breaks direct links such as /config/tool/marketplace?source=official or ?source=community: that page reads router.query.source to apply the marketplace source filter, but the global init strips it on mount and the filter is lost. Use a namespaced attribution query key or restrict this removal to the attribution entry flow.

Useful? React with 👍 / 👎.

@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 18.42% 1632 / 8859
🔵 Statements 18.41% 1713 / 9304
🔵 Functions 16.2% 342 / 2110
🔵 Branches 15.14% 761 / 5026
File CoverageNo changed files found.
Generated in workflow #1516 for commit eb28cd0 by the Vitest Coverage Report Action

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR wires homepage attribution (including visitor_id) into FastGPT’s existing marketing tracking, persists it on password login, and reports a CRM visitor identity binding when CRM env vars are configured.

Changes:

  • Add FastGPTSourceSchema / FastGPTTrackSemSchema and client-side parsing/validation to store home_source safely in fastgpt_sem.
  • Send fastgpt_sem through login flows and centralize “login success → clear marketing data” behavior.
  • Persist home_source as lastsource on password login and report CRM identity via a gated, failure-safe reporter; document new env vars and add deployment placeholders.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
projects/app/test/web/support/user/api.test.ts Extends user API test fixture to include fastgpt_sem.home_source.
projects/app/test/web/support/marketing/utils.test.ts Adds tests for source parsing, sem schema filtering, and login-success cleanup.
projects/app/test/api/support/user/account/loginByPassword.test.ts Adds coverage for persisting home_source into fastgpt_sem.lastsource and adjusts Call generics.
projects/app/src/web/support/marketing/utils.ts Adds schema-validated getFastGPTSem, parseFastGPTSource, and onFastGPTLoginSuccess.
projects/app/src/web/context/useInitApp.ts Parses source query param into home_source, merges UTM fallbacks, and stores in fastgpt_sem.
projects/app/src/pages/login/provider.tsx Uses onFastGPTLoginSuccess to clear marketing data post-login.
projects/app/src/pages/login/fastlogin.tsx Sends fastgpt_sem with fast login and uses onFastGPTLoginSuccess.
projects/app/src/pages/api/support/user/account/loginByPassword.ts Accepts fastgpt_sem, persists lastsource, and reports CRM visitor identity.
projects/app/src/pageComponents/login/RegisterForm.tsx Uses onFastGPTLoginSuccess to clear marketing data post-registration login.
projects/app/src/pageComponents/login/LoginForm/WechatForm.tsx Uses onFastGPTLoginSuccess to clear marketing data post-login.
projects/app/src/pageComponents/login/LoginForm/LoginForm.tsx Sends fastgpt_sem on password login and uses onFastGPTLoginSuccess.
projects/app/.env.template Documents new CRM_API_URL / CRM_API_KEY env vars.
packages/service/test/support/marketing/attribution.test.ts Adds unit tests for gated CRM identity reporting and failure safety.
packages/service/support/marketing/attribution.ts Implements reportCRMVisitorIdentity (gated by env vars, logs on failure).
packages/service/env.ts Adds CRM_API_URL / CRM_API_KEY to service env schema.
packages/global/support/marketing/type.ts Introduces FastGPTSourceSchema and separates tracking sem schema from persisted sem schema.
packages/global/openapi/support/user/account/login/api.ts Extends login request schemas with TrackRegisterParamsSchema (incl. fastgpt_sem).
document/content/self-host/config/env.mdx Documents CRM env vars (CN).
document/content/self-host/config/env.en.mdx Documents CRM env vars (EN).
deploy/version/main/docker-compose.template.yml Adds deployment placeholders for CRM env vars.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +86 to +92
await reportCRMVisitorIdentity({
source: fastgpt_sem?.home_source,
userId: String(user._id),
username: user.username,
contact: user.contact
});

@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown

Docs Preview Deployed!

🔗 👀 Click here to visit preview

ghcr.io/labring/fastgpt-docs-pr:eb28cd0509fb8dba53c148bc5852173ced631e31

🕒 Time: 2026-07-17 12:25:32 (UTC+8)

@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown

Admin Preview Image Ready!

ghcr.io/labring/fastgpt-pr:admin_eb28cd0509fb8dba53c148bc5852173ced631e31

🕒 Time: 2026-07-17 12:29:35 (UTC+8)

@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown

Build Successful - Preview fastgpt Image for this PR:

ghcr.io/labring/fastgpt-pr:fastgpt_e354525baa5eed1ee514a11954826025f8c25731

🕒 Time: 2026-07-16 23:16:10 (UTC+8)

@c121914yu c121914yu changed the title feat: connect homepage attribution to CRM identity feat: bind homepage visitor id after authentication Jul 16, 2026
@c121914yu
c121914yu force-pushed the codex/source-report-webhook branch from d752115 to e354525 Compare July 16, 2026 15:05
@c121914yu
c121914yu force-pushed the codex/source-report-webhook branch from e354525 to eb28cd0 Compare July 17, 2026 04:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants