Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add hubspot cookie tracking #4539

Merged
merged 18 commits into from
Sep 9, 2024
Merged

Conversation

zachaysan
Copy link
Contributor

Changes

Fixes #3855

This change adds in a form in the background of a Hubspot contact creation to add in the special Hubspot tracking cookie to give extra visibility in our user's journey in places like the activity tab of the Hubspot dashboard.

How did you test this code?

Manually tested it with my own Hubspot cookie and I added programatic tests after gaining confidence that it worked.

@zachaysan zachaysan requested a review from a team as a code owner August 26, 2024 19:51
@zachaysan zachaysan requested review from khvn26 and removed request for a team August 26, 2024 19:51
Copy link

vercel bot commented Aug 26, 2024

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

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs ⬜️ Ignored (Inspect) Visit Preview Sep 6, 2024 6:25pm
flagsmith-frontend-preview ⬜️ Ignored (Inspect) Visit Preview Sep 6, 2024 6:25pm
flagsmith-frontend-staging ⬜️ Ignored (Inspect) Visit Preview Sep 6, 2024 6:25pm

@github-actions github-actions bot added api Issue related to the REST API feature New feature or request labels Aug 26, 2024
Copy link
Contributor

github-actions bot commented Aug 26, 2024

Docker builds report

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

Copy link
Contributor

github-actions bot commented Aug 26, 2024

Uffizzi Preview deployment-55574 was deleted.

Copy link

codecov bot commented Aug 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.16%. Comparing base (b2a1899) to head (e7685b9).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4539   +/-   ##
=======================================
  Coverage   97.15%   97.16%           
=======================================
  Files        1157     1160    +3     
  Lines       40023    40107   +84     
=======================================
+ Hits        38886    38970   +84     
  Misses       1137     1137           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 49 to 57
hubspot_cookie = request.COOKIES.get(HUBSPOT_COOKIE_NAME)

if hubspot_cookie:
if not HubspotTracker.objects.filter(user=request.user).exists():
HubspotTracker.objects.create(
user=request.user,
hubspot_cookie=hubspot_cookie,
)

Copy link
Member

@khvn26 khvn26 Aug 28, 2024

Choose a reason for hiding this comment

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

I'd like to avoid code duplication, which occurs further in join_organisation_from_link. This code can be extracted to either of the following:

  • A HubspotTracker class method
  • A function in services.py — that's how I'd do it, see existing services.py modules for reference

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure this is easy.

Comment on lines 76 to 83
hubspot_cookie = request.COOKIES.get(HUBSPOT_COOKIE_NAME)

if hubspot_cookie:
if not HubspotTracker.objects.filter(user=request.user).exists():
HubspotTracker.objects.create(
user=request.user,
hubspot_cookie=hubspot_cookie,
)
Copy link
Member

Choose a reason for hiding this comment

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

See here.

Comment on lines 114 to 121
hubspot_cookie = request.COOKIES.get(HUBSPOT_COOKIE_NAME)

if hubspot_cookie:
if not HubspotTracker.objects.filter(user=request.user).exists():
HubspotTracker.objects.create(
user=request.user,
hubspot_cookie=hubspot_cookie,
)
Copy link
Member

Choose a reason for hiding this comment

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

See here.


if hubspot_cookie:
if not HubspotTracker.objects.filter(user=request.user).exists():
HubspotTracker.objects.create(
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to update the stored cookie in case it's regenerated for some reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I've switched the code to an update_or_create method to handle that if it ever comes up.

Copy link
Member

@khvn26 khvn26 left a comment

Choose a reason for hiding this comment

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

I've got a nitpick, a code improvement proposal, and a question.

@github-actions github-actions bot removed the feature New feature or request label Sep 3, 2024
@@ -58,6 +58,12 @@ def create_lead(self, user: FFAdminUser, organisation: Organisation = None) -> N

HubspotLead.objects.create(user=user, hubspot_id=response["id"])

if HubspotTracker.objects.filter(user=user).exists():
Copy link
Member

Choose a reason for hiding this comment

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

nit: we can use walrus here and get rid of the exists

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch 👍🏼

@github-actions github-actions bot added feature New feature or request and removed feature New feature or request labels Sep 6, 2024
@github-actions github-actions bot added feature New feature or request and removed feature New feature or request labels Sep 6, 2024
@zachaysan zachaysan added this pull request to the merge queue Sep 9, 2024
Merged via the queue into main with commit 6714384 Sep 9, 2024
35 checks passed
@zachaysan zachaysan deleted the feat/add_hubspot_cookie_tracking branch September 9, 2024 13:02
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 feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Original source > HubSpot
3 participants