flagsmith icon indicating copy to clipboard operation
flagsmith copied to clipboard

fix: hubspot attribution issues

Open Zaimwa9 opened this issue 8 months ago • 4 comments

Thanks for submitting a PR! Please check the boxes below:

  • [ ] I have added information to docs/ if required so people know about the feature!
  • [x] I have filled in the "Changes" section below?
  • [x] I have filled in the "How did you test this code" section below?
  • [x] I have used a Conventional Commit title for this Pull Request

Changes

⚠️ Hubspot is now in charge of initially creating (if not exists) / associating organisation with users. Reconciliation is based on domain.

  • Pass hubspot cookie from frontend on signup action
  • Reworked the hubspot tracking flow so that:
  1. Every new sign-up creates a hubspot contact (using create_lead_form with or without cookie) and saves HubspotLeads
  2. On UsersOrganisation creation a) If organisation was just created and exists in hubspot => get company data from hubspot, saves the HubspotOrganisation object with correct id b) if doesn't exist in hubspot for X reason => creates it and saves hubspot ID
  3. On UsersOrganisation creation, associates the contact with the
  • Removed the 30min background checker as hubspot creates/associates automatically the company

How did you test this code?

Please describe.

  • Added battery of tests on client and lead_tracker Functionally: Set "ENABLE_HUBSPOT_LEAD_TRACKING": "True" and HUBSPOT_ACCESS_TOKEN Create user, organisation, invite users

Zaimwa9 avatar Jun 10 '25 15:06 Zaimwa9

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 20, 2025 7:52am
flagsmith-frontend-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 20, 2025 7:52am
flagsmith-frontend-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 20, 2025 7:52am

vercel[bot] avatar Jun 10 '25 15:06 vercel[bot]

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-api-test:pr-5560 Finished :white_check_mark: Skipped
ghcr.io/flagsmith/flagsmith-e2e:pr-5560 Finished :white_check_mark: Skipped
ghcr.io/flagsmith/flagsmith-api:pr-5560 Finished :white_check_mark: Results :white_check_mark:
ghcr.io/flagsmith/flagsmith:pr-5560 Finished :white_check_mark: Results :white_check_mark:
ghcr.io/flagsmith/flagsmith-private-cloud:pr-5560 Finished :white_check_mark: Results :white_check_mark:
ghcr.io/flagsmith/flagsmith-frontend:pr-5560 Finished :white_check_mark: Results :white_check_mark:

github-actions[bot] avatar Jun 10 '25 15:06 github-actions[bot]

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 97.76%. Comparing base (23aa20f) to head (3d84158). Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5560      +/-   ##
==========================================
+ Coverage   97.74%   97.76%   +0.02%     
==========================================
  Files        1255     1255              
  Lines       44500    44643     +143     
==========================================
+ Hits        43496    43645     +149     
+ Misses       1004      998       -6     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Jun 11 '25 15:06 codecov[bot]

Thanks for the detailed feedback.

The naming could definitely be improved in a few places

Definitely, let me know if this feels clearer

As far as I'm aware, this work should ideally have resulted in 3 tasks

That should be the case, more precisely there are 2 entrypoints:

  1. User registration triggers create_hubspot_contact_for_user and ultimately the lead_form
  2. New UserOrganisation entity triggers track_hubspot_user_organisation_association that wraps update_company if name needs to be updated (merged with update subscription)

Additionally, I added a basic retry with backoff in create_lead_form, without raising for now

Zaimwa9 avatar Jun 13 '25 16:06 Zaimwa9