Skip to content

fix: hubspot attribution issues#5560

Merged
Zaimwa9 merged 50 commits intomainfrom
fix/hubspot-attribution-issues
Jun 20, 2025
Merged

fix: hubspot attribution issues#5560
Zaimwa9 merged 50 commits intomainfrom
fix/hubspot-attribution-issues

Conversation

@Zaimwa9
Copy link
Copy Markdown
Contributor

@Zaimwa9 Zaimwa9 commented Jun 10, 2025

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

  • I have added information to docs/ if required so people know about the feature!
  • I have filled in the "Changes" section below?
  • I have filled in the "How did you test this code" section below?
  • 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 Zaimwa9 requested review from a team as code owners June 10, 2025 15:01
@Zaimwa9 Zaimwa9 requested review from gagantrivedi and kyle-ssg and removed request for a team June 10, 2025 15:01
@vercel
Copy link
Copy Markdown

vercel bot commented Jun 10, 2025

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

@github-actions github-actions bot added front-end Issue related to the React Front End Dashboard api Issue related to the REST API fix labels Jun 10, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jun 10, 2025

Docker builds report

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

@github-actions github-actions bot added fix and removed fix labels Jun 11, 2025
@github-actions github-actions bot removed the fix label Jun 11, 2025
@github-actions github-actions bot added fix and removed fix labels Jun 13, 2025
@github-actions github-actions bot added fix and removed fix labels Jun 13, 2025
@Zaimwa9
Copy link
Copy Markdown
Contributor Author

Zaimwa9 commented Jun 13, 2025

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

Copy link
Copy Markdown
Contributor

@matthewelwell matthewelwell left a comment

Choose a reason for hiding this comment

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

The code look a LOT cleaner now - so much easier to follow. I've added a few more comments, but I think that we're pretty close.

I've resolved all of the previous comments as well.

Comment thread api/integrations/lead_tracking/hubspot/lead_tracker.py
Comment thread api/integrations/lead_tracking/hubspot/lead_tracker.py Outdated
Comment thread api/integrations/lead_tracking/hubspot/lead_tracker.py Outdated
Comment thread api/integrations/lead_tracking/hubspot/lead_tracker.py
Comment thread api/integrations/lead_tracking/hubspot/lead_tracker.py Outdated
Comment thread api/integrations/lead_tracking/lead_tracking.py Outdated
Co-authored-by: Matthew Elwell <matthew.elwell@flagsmith.com>
@github-actions github-actions bot added fix and removed fix labels Jun 17, 2025
@github-actions github-actions bot added fix and removed fix labels Jun 17, 2025
@Zaimwa9 Zaimwa9 assigned Zaimwa9 and unassigned gagantrivedi Jun 17, 2025
Comment thread api/integrations/lead_tracking/hubspot/tasks.py Outdated
Comment thread api/integrations/lead_tracking/pipedrive/lead_tracker.py
@github-actions github-actions bot added fix and removed fix labels Jun 19, 2025
@Zaimwa9 Zaimwa9 merged commit 251508a into main Jun 20, 2025
29 checks passed
Comment on lines 22 to 31
if (
HubspotTracker.objects.filter(hubspot_cookie=hubspot_cookie) # type: ignore[misc]
.exclude(user=request.user)
.exclude(user=track_user)
.exists()
):
logger.info(
f"HubspotTracker could not be created for user {request.user.id}"
f"HubspotTracker could not be created for user {track_user.id}"
f" due to cookie conflict with cookie {hubspot_cookie}"
)
return
Copy link
Copy Markdown
Contributor Author

@Zaimwa9 Zaimwa9 Jul 3, 2025

Choose a reason for hiding this comment

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

@matthewelwell , I think we can remove this guard and allow for multiple identical cookies (cf the user who created 3 accounts. We lost the info on the account we cared about)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API fix front-end Issue related to the React Front End Dashboard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants