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

fix: Fix the referrer changing mid-session #1314

Merged
merged 2 commits into from
Jul 23, 2024

Conversation

robbie-c
Copy link
Member

@robbie-c robbie-c commented Jul 22, 2024

Changes

As part of the personless event changes, we accidentally introduced a bug where the referrer could change mid-session. This shouldn't happen, and led to some annoying situation where e.g. if a payments workflow navigated people to checkout.stripe.com and then back to the original site, the referrer would switch to stripe, which meant that any events after that couldn't be attributed to the original referrer.

This fixes that bug, and adds some tests.

(P.S. I realised how this was broken when working on #1313, IMO with this fix merged that PR becomes a lot less useful)

Checklist

  • Tests for new code (see advice on the tests we use)
  • Accounted for the impact of any changes across different browsers
  • Accounted for backwards compatibility of any changes (no breaking changes in posthog-js!)

Copy link

vercel bot commented Jul 22, 2024

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

Name Status Preview Updated (UTC)
posthog-js ✅ Ready (Inspect) Visit Preview Jul 22, 2024 3:00pm

posthog.capture(eventName, eventProperties)
}
expect(onCapture).toHaveBeenCalledTimes(1)
expect(onCapture.mock.calls[0][0]).toBe('$$client_ingestion_warning')
Copy link
Member Author

Choose a reason for hiding this comment

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

This test was broken before, it relied on state from the previous test and failed when run in isolation.

expect(properties['$referring_domain']).toBe('referrer.example.com')
})

it('should not update the referrer within the same session', () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

This test fails without the fix in this PR

@@ -227,7 +227,7 @@ export class PostHogPersistence {
}

update_referrer_info(): void {
this.register(Info.referrerInfo())
this.register_once(Info.referrerInfo(), undefined)
Copy link
Member Author

Choose a reason for hiding this comment

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

The one-line actual fix

Copy link

github-actions bot commented Jul 22, 2024

Size Change: +48 B (0%)

Total Size: 1.19 MB

Filename Size Change
dist/array.full.js 330 kB +12 B (0%)
dist/array.js 163 kB +12 B (+0.01%)
dist/main.js 163 kB +12 B (+0.01%)
dist/module.js 163 kB +12 B (+0.01%)
ℹ️ View Unchanged
Filename Size
dist/exception-autocapture.js 10.4 kB
dist/recorder-v2.js 110 kB
dist/recorder.js 110 kB
dist/surveys-preview.js 59.6 kB
dist/surveys.js 64.7 kB
dist/tracing-headers.js 8.26 kB
dist/web-vitals.js 5.79 kB

compressed-size-action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bump minor Bump minor version when this PR gets merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants