PostHog / posthog-js

Send usage data from your web app or site to PostHog, with autocapture.
https://posthog.com/docs/libraries/js
Other
278 stars 114 forks source link

feat: Treat self referrals as direct #1426

Closed robbie-c closed 1 week ago

robbie-c commented 1 week ago

Changes

We handle the $referrer property in a potentially confusing way when an internal link is clicked. The latest example is https://posthog.slack.com/archives/C03C60FT1J7/p1726670676997629.

This happens because we use document.referrer directly, and this can be self-referential in the following example

  1. User is on https://referrer.com
  2. User clicks a link to https://tracked.com
  3. Referrer is referrer.com
  4. User is inactive long enough for the session to expire
  5. User clicks an internal link to https://tracked.com
  6. Referrer is tracked.com

This PR changes this, so that the referrer in 6) would be $direct

To be clear about this: it is a breaking change, however I believe it's more in line with what the expected behaviour would be. One might argue that the original behaviour is a bug

Checklist

vercel[bot] commented 1 week ago

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

Name Status Preview Updated (UTC)
posthog-js ✅ Ready (Inspect) Visit Preview Sep 20, 2024 10:00am
github-actions[bot] commented 1 week ago

Size Change: +303 B (+0.02%)

Total Size: 1.21 MB

Filename Size Change
dist/array.full.js 347 kB +75 B (+0.02%)
dist/array.js 163 kB +76 B (+0.05%)
dist/main.js 164 kB +76 B (+0.05%)
dist/module.js 163 kB +76 B (+0.05%)
ℹ️ View Unchanged | Filename | Size | | :--- | :---: | | `dist/exception-autocapture.js` | 10.4 kB | | `dist/recorder-v2.js` | 111 kB | | `dist/recorder.js` | 111 kB | | `dist/surveys-preview.js` | 59.8 kB | | `dist/surveys.js` | 66 kB | | `dist/tracing-headers.js` | 8.26 kB | | `dist/web-vitals.js` | 10.3 kB |

compressed-size-action

pauldambra commented 1 week ago

Asked a question about this in the private slack posthog.slack.com/archives/C03C60FT1J7/p1726670676997629

robbie-c commented 1 week ago

Closing PR following discussion on slack

robbie-c commented 1 week ago

See https://github.com/PostHog/posthog.com/pull/9408#pullrequestreview-2318570882 instead