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(flags): store setOnce properties in locally persisted feature flag props #1716

Merged
merged 3 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/__tests__/posthog-core.identify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ describe('identify()', () => {
expect(instance.featureFlags.setAnonymousDistinctId).not.toHaveBeenCalled()
expect(instance.featureFlags.reloadFeatureFlags).not.toHaveBeenCalled()
expect(instance.featureFlags.setPersonPropertiesForFlags).toHaveBeenCalledWith(
{ email: '[email protected]' },
{ email: '[email protected]', howOftenAmISet: 'once!' },
true
)
})
Expand All @@ -280,7 +280,7 @@ describe('identify()', () => {
expect(instance.featureFlags.setAnonymousDistinctId).toHaveBeenCalledWith('oldIdentity')
expect(instance.featureFlags.reloadFeatureFlags).toHaveBeenCalled()
expect(instance.featureFlags.setPersonPropertiesForFlags).toHaveBeenCalledWith(
{ email: '[email protected]' },
{ email: '[email protected]', howOftenAmISet: 'once!' },
false
)
})
Expand Down
13 changes: 9 additions & 4 deletions src/posthog-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,8 @@ export class PostHog {
* If you want to merge two identified users, you can call posthog.alias
*
* @param {String} [new_distinct_id] A string that uniquely identifies a user. If not provided, the distinct_id currently in the persistent store (cookie or localStorage) will be used.
* @param {Object} [userPropertiesToSet] Optional: An associative array of properties to store about the user
* @param {Object} [userPropertiesToSet] Optional: An associative array of properties to store about the user. Note: For feature flag evaluations, if the same key is present in the userPropertiesToSetOnce,
* it will be overwritten by the value in userPropertiesToSet.
* @param {Object} [userPropertiesToSetOnce] Optional: An associative array of properties to store about the user. If property is previously set, this does not override that value.
*/
identify(new_distinct_id?: string, userPropertiesToSet?: Properties, userPropertiesToSetOnce?: Properties): void {
Expand Down Expand Up @@ -1427,7 +1428,10 @@ export class PostHog {
this.persistence.set_property(USER_STATE, 'identified')

// Update current user properties
this.setPersonPropertiesForFlags(userPropertiesToSet || {}, false)
this.setPersonPropertiesForFlags(
marandaneto marked this conversation as resolved.
Show resolved Hide resolved
{ ...(userPropertiesToSetOnce || {}), ...(userPropertiesToSet || {}) },
false
)

this.capture(
'$identify',
Expand Down Expand Up @@ -1471,7 +1475,8 @@ export class PostHog {
* identified_only, and a Person profile has not been created yet, this will create one.
*
*
* @param {Object} [userPropertiesToSet] Optional: An associative array of properties to store about the user
* @param {Object} [userPropertiesToSet] Optional: An associative array of properties to store about the user. Note: For feature flag evaluations, if the same key is present in the userPropertiesToSetOnce,
* it will be overwritten by the value in userPropertiesToSet.
* @param {Object} [userPropertiesToSetOnce] Optional: An associative array of properties to store about the user. If property is previously set, this does not override that value.
*/
setPersonProperties(userPropertiesToSet?: Properties, userPropertiesToSetOnce?: Properties): void {
Expand All @@ -1484,7 +1489,7 @@ export class PostHog {
}

// Update current user properties
this.setPersonPropertiesForFlags(userPropertiesToSet || {})
this.setPersonPropertiesForFlags({ ...(userPropertiesToSetOnce || {}), ...(userPropertiesToSet || {}) })

// if exactly this $set call has been sent before, don't send it again - determine based on hash of properties

Expand Down
Loading