Repository navigation
feat(react-native): add $react_native_version to captured events #5206
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2a4e0fb
feat(react-native): send $react_native_version with every event
turnipdabeets 75578fb
chore(react-native): regenerate references and scope $react_native_ve…
turnipdabeets 0c2f1ea
fix(react-native): ignore malformed RN version constants and cover th…
turnipdabeets f2c8870
fix(core): keep $react_native_version on minimal $feature_flag_called…
turnipdabeets File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@posthog/core': patch | ||
| --- | ||
|
|
||
| Keep `$react_native_version` on minimal `$feature_flag_called` events |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'posthog-react-native': minor | ||
| --- | ||
|
|
||
| Add `$react_native_version` (for example `0.79.6`) to events captured from JavaScript |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import { Platform } from 'react-native' | ||
| import { minimizeFlagCalledEventProperties } from '@posthog/core' | ||
| import { PostHog } from '../src' | ||
| import { getReactNativeVersion } from '../src/utils' | ||
|
|
||
| const platform = Platform as typeof Platform & { constants?: unknown } | ||
|
|
||
| describe('$react_native_version', () => { | ||
| afterEach(() => { | ||
| delete platform.constants | ||
| }) | ||
|
|
||
| it('formats Platform.constants.reactNativeVersion', () => { | ||
| platform.constants = { reactNativeVersion: { major: 0, minor: 79, patch: 6, prerelease: null } } | ||
| expect(getReactNativeVersion()).toBe('0.79.6') | ||
| }) | ||
|
|
||
| it('appends the prerelease tag', () => { | ||
| platform.constants = { reactNativeVersion: { major: 0, minor: 80, patch: 0, prerelease: 'rc.2' } } | ||
| expect(getReactNativeVersion()).toBe('0.80.0-rc.2') | ||
| }) | ||
|
|
||
| it('is undefined when the platform does not report a version', () => { | ||
| platform.constants = {} | ||
| expect(getReactNativeVersion()).toBeUndefined() | ||
| }) | ||
|
|
||
| it('is undefined when the version object has no numeric fields', () => { | ||
| platform.constants = { reactNativeVersion: {} } | ||
| expect(getReactNativeVersion()).toBeUndefined() | ||
| }) | ||
|
|
||
| it('is undefined when reading the constants throws', () => { | ||
| Object.defineProperty(platform, 'constants', { | ||
| configurable: true, | ||
| get: () => { | ||
| throw new Error('getConstants failed') | ||
| }, | ||
| }) | ||
| expect(getReactNativeVersion()).toBeUndefined() | ||
| }) | ||
|
|
||
| it('is sent with every event', async () => { | ||
| platform.constants = { reactNativeVersion: { major: 0, minor: 79, patch: 6 } } | ||
| const posthog = new PostHog('test-token', { flushInterval: 0 }) | ||
| await posthog.ready() | ||
|
|
||
| expect(posthog.getCommonEventProperties().$react_native_version).toBe('0.79.6') | ||
|
|
||
| await posthog.shutdown() | ||
| }) | ||
|
|
||
| it('survives minimal $feature_flag_called events', () => { | ||
| expect(minimizeFlagCalledEventProperties({ $react_native_version: '0.79.6', custom: 'dropped' })).toEqual({ | ||
| $react_native_version: '0.79.6', | ||
| }) | ||
| }) | ||
|
|
||
| it('is omitted when the platform does not report a version', async () => { | ||
| const posthog = new PostHog('test-token', { flushInterval: 0 }) | ||
| await posthog.ready() | ||
|
|
||
| expect(posthog.getCommonEventProperties()).not.toHaveProperty('$react_native_version') | ||
|
|
||
| await posthog.shutdown() | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.