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

chore: deduplicate subsequent identify calls #1649

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

joshsny
Copy link

@joshsny joshsny commented Jan 14, 2025

Often duplicate $identify calls are made due to the SDK being incorrectly setup in the app, or due to re-rendering of providers.

The current behaviour is to only deduplicate $identify calls with no properties, but most $identify calls include properties like email, so they are not deduplicated. This PR extends deduplication to calls with properties.

Note: this is my first contribution to js sdk so would appreciate a thorough review.
...

Checklist

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

Copy link

vercel bot commented Jan 14, 2025

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

Name Status Preview Updated (UTC)
posthog-js ✅ Ready (Inspect) Visit Preview Jan 14, 2025 6:04pm

Copy link

github-actions bot commented Jan 14, 2025

Size Change: +3.46 kB (+0.11%)

Total Size: 3.24 MB

Filename Size Change
dist/array.full.es5.js 264 kB +350 B (+0.13%)
dist/array.full.js 367 kB +346 B (+0.09%)
dist/array.full.no-external.js 365 kB +346 B (+0.09%)
dist/array.js 180 kB +345 B (+0.19%)
dist/array.no-external.js 179 kB +345 B (+0.19%)
dist/main.js 181 kB +345 B (+0.19%)
dist/module.full.js 367 kB +346 B (+0.09%)
dist/module.full.no-external.js 365 kB +346 B (+0.09%)
dist/module.js 180 kB +345 B (+0.19%)
dist/module.no-external.js 179 kB +345 B (+0.19%)
ℹ️ View Unchanged
Filename Size
dist/all-external-dependencies.js 207 kB
dist/customizations.full.js 12.6 kB
dist/dead-clicks-autocapture.js 14.4 kB
dist/exception-autocapture.js 9.48 kB
dist/external-scripts-loader.js 2.64 kB
dist/recorder-v2.js 115 kB
dist/recorder.js 115 kB
dist/surveys-preview.js 58.1 kB
dist/surveys.js 63.8 kB
dist/tracing-headers.js 1.76 kB
dist/web-vitals.js 10.4 kB

compressed-size-action

src/posthog-core.ts Outdated Show resolved Hide resolved
@@ -306,7 +307,7 @@ export class PostHog {
this.analyticsDefaultEndpoint = '/e/'
this._initialPageviewCaptured = false
this._initialPersonProfilesConfig = null

this._cachedIdentify = null
Copy link
Member

Choose a reason for hiding this comment

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

was trying to decide if we should store this in local storage but i think i prefer this isn't cached outside of memory...

i'm not super familiar with identify and person processing so this feels like a safe step to take to test the waters

Copy link
Author

Choose a reason for hiding this comment

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

Yeah was also thinking about that, the current implementation helps in SPA setups, but hard page reloads would only be fixed by local storage...

// If the distinct_id is not changing, but we have user properties to set, we can go for a $set event
this.setPersonProperties(userPropertiesToSet, userPropertiesToSetOnce)
if (
this._cachedIdentify !==
Copy link
Member

Choose a reason for hiding this comment

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

i think it's ok to do this as an effectively "breaking change"... folk might be depending on the $set for duplicate identify calls but that'd be surprising to me

and we could always add an opt-out option if people ask for it 🤔

Copy link
Author

Choose a reason for hiding this comment

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

Hopefully, it should be okay, since we were already ignoring duplicate identify calls without properties. But in reality, few people make identify calls without properties so it's possible someone does rely on this behaviour...

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

@pauldambra pauldambra left a comment

Choose a reason for hiding this comment

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

brain dumped from a quick scan... i've not really worked with identify so haven't thought about whether we should 🙈

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.

2 participants