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: swap the default to identified_only #1468

Merged
merged 11 commits into from
Oct 17, 2024

Conversation

raquelmsmith
Copy link
Member

@raquelmsmith raquelmsmith commented Oct 15, 2024

Warning

This should only be merged after we support the field response from /decide.

Changes

We want to make the person_profiles: identified_only config the default for everyone. It will save everyone money - even if they don't change their config - and is better for our customers and our pipeline.

Instead of just pushing out a change to posthog-js for this, we want to be able to control the behavior and roll it out slowly, just in case there are any problems.

So, this PR changes the default, but also listens to a field from decide that will say if we should be defaulting people into identified_only, or using the old default always. If someone has set their config manually, then we will continue using that setting.

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 Oct 15, 2024

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

Name Status Preview Updated (UTC)
posthog-js ✅ Ready (Inspect) Visit Preview Oct 15, 2024 7:31pm

@posthog-bot
Copy link
Collaborator

Hey @raquelmsmith! 👋
This pull request seems to contain no description. Please add useful context, rationale, and/or any other information that will help make sense of this change now and in the distant Mars-based future.

@@ -387,6 +401,7 @@ describe('posthog core', () => {
properties: () => ({ distinct_id: 'abc', persistent: 'prop', $is_identified: false }),
remove_event_timer: jest.fn(),
get_property: () => 'anonymous',
props: { $groups: {} },
Copy link
Member Author

Choose a reason for hiding this comment

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

adding this made most the tests pass with the new identified_only default config. Does this indicate that something else needs to happen somewhere to make sure real users always have this in their props? Or is it just a test fixture thing? (I imagine the latter because people can use identifed_only with no problem, but want to be certain)

Copy link
Member

Choose a reason for hiding this comment

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

It feels like the latter, but I'll stare at this code a little to convince myself a bit more

Copy link
Member

Choose a reason for hiding this comment

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

Ok, it was the absence of props in the mock that made the test fail, it didn't actually need $groups: {}, so I've slightly changed this line to have a more minimal mock

@@ -179,7 +179,7 @@ export const defaultConfig = (): PostHogConfig => ({
bootstrap: {},
disable_compression: false,
session_idle_timeout_seconds: 30 * 60, // 30 minutes
person_profiles: 'always',
person_profiles: 'identified_only',
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 main change for swapping the default

Comment on lines +395 to +397
if (config.person_profiles) {
this._initialPersonProfilesConfig = config.person_profiles
}
Copy link
Member Author

Choose a reason for hiding this comment

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

in order to roll this out slowly, we need to know if the person has already set their config - that it's not just using the default. So we need to store the initial config somewhere.

@@ -408,6 +414,8 @@ export class PostHog {
this.config.persistence === 'sessionStorage'
? this.persistence
: new PostHogPersistence({ ...this.config, persistence: 'sessionStorage' })

// should I store the initial person profiles config in persistence?
Copy link
Member Author

Choose a reason for hiding this comment

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

question

Copy link
Member

Choose a reason for hiding this comment

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

The way I've handled this so far is to save whether or not they've sent an event with person processing. If they have then we persist ENABLE_PERSON_PROCESSING to true.

I'm just wondering whether saving their config gives us anything beyond this.

Here's a couple of cases:

Case 1

  • posthog-js starts up with the user setting 'always'
  • some events are sent, with person profiles, so ENABLE_PERSON_PROCESSING is set
  • user closes the browser
  • new visit, posthog-js starts up with no setting so uses the default identified_only
  • some events are sent, as ENABLE_PERSON_PROCESSING was set then these have person profiles

Case 2

  • posthog-js starts up with the user setting 'always'
  • no events are sent, so ENABLE_PERSON_PROCESSING is not set
  • user closes the browser
  • new visit, posthog-js starts up with no setting so uses the default identified_only
  • some events are sent, these are anonymous (if we'd persisted the setting from before, they'd have person profiles)

In case 2 there's a difference, but I'd argue that those events should be sent as anonymous. Wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

TLDR no I don't think so :D

Copy link
Member

Choose a reason for hiding this comment

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

Ooooook so it turns out we don't actually handle this case correctly. I added a fix and some tests to this PR. I hope you don't mind me piggybacking like this, I can very much move it to its own PR if you prefer.

Copy link
Member Author

Choose a reason for hiding this comment

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

No this is great, thanks!

@@ -398,6 +398,7 @@ export interface DecideResponse {
isAuthenticated: boolean
siteApps: { id: number; url: string }[]
heatmaps?: boolean
defaultIdentifiedOnly?: boolean
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 will be returned with /decide

Copy link

github-actions bot commented Oct 15, 2024

Size Change: +3.12 kB (+0.11%)

Total Size: 2.83 MB

Filename Size Change
dist/array.full.js 355 kB +347 B (+0.1%)
dist/array.full.no-external.js 354 kB +347 B (+0.1%)
dist/array.js 169 kB +347 B (+0.21%)
dist/array.no-external.js 168 kB +347 B (+0.21%)
dist/main.js 170 kB +347 B (+0.2%)
dist/module.full.js 355 kB +347 B (+0.1%)
dist/module.full.no-external.js 354 kB +347 B (+0.1%)
dist/module.js 169 kB +347 B (+0.21%)
dist/module.no-external.js 168 kB +347 B (+0.21%)
ℹ️ View Unchanged
Filename Size
dist/all-external-dependencies.js 192 kB
dist/exception-autocapture.js 11.1 kB
dist/external-scripts-loader.js 2.35 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.36 kB
dist/web-vitals.js 10.3 kB

compressed-size-action

src/posthog-core.ts Outdated Show resolved Hide resolved
@robbie-c
Copy link
Member

robbie-c commented Oct 15, 2024

Woohoo!

A caveat I just wanted to flag - this PR does the right thing but if we did things the other way round (set always as the default and override that to identified_only in decide) then it wouldn't work. Once we send an event with $process_person_profile: true then we persist a flag called ENABLE_PERSON_PROCESSING to ensure all following events also have $process_person_profile: true. If the default was always then the first pageview (which happens before decide returns) would set that flag and we'd never send any anonymous events.

Either way, this PR does the right thing, so maybe you already knew all of this :D

Edit: I found a bug in how we were handling the logic above, so I've added a fix and some tests to this PR

Copy link
Member

@robbie-c robbie-c left a comment

Choose a reason for hiding this comment

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

LGTM! I added some stuff, so please make sure those changes LGTY

@raquelmsmith
Copy link
Member Author

raquelmsmith commented Oct 15, 2024

Looks good to me! Thanks for the help @robbie-c!!

I'll wait to merge this until I get the /decide changes in today or tomorrow.

@raquelmsmith raquelmsmith marked this pull request as ready for review October 17, 2024 20:31
@raquelmsmith raquelmsmith merged commit 387d96e into main Oct 17, 2024
14 checks passed
@raquelmsmith raquelmsmith deleted the feat/identified-only-default branch October 17, 2024 20:32
@raquelmsmith
Copy link
Member Author

Oh @robbie-c I forgot to specify what type of version bump this is.... will it bump automatically? Or just with the next one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants