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: change captureMode to json #252

Merged
merged 7 commits into from
Aug 27, 2024
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
1 change: 0 additions & 1 deletion examples/example_expo_rn_web/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export const posthog = new PostHog('phc_pQ70jJhZKHRvDIL5ruOErnPy6xiAiWCqlL4ayELj
captureNativeAppLifecycleEvents: false,
sendFeatureFlagEvent: false,
preloadFeatureFlags: false,
// captureMode: 'form',
// persistence: 'memory',
})
posthog.debug(true)
Expand Down
2 changes: 1 addition & 1 deletion posthog-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export abstract class PostHogCoreStateless {
this.maxBatchSize = Math.max(this.flushAt, options?.maxBatchSize ?? 100)
this.maxQueueSize = Math.max(this.flushAt, options?.maxQueueSize ?? 1000)
this.flushInterval = options?.flushInterval ?? 10000
this.captureMode = options?.captureMode || 'form'
this.captureMode = options?.captureMode || 'json'

// If enable is explicitly set to false we override the optout
this.defaultOptIn = options?.defaultOptIn ?? true
Expand Down
2 changes: 1 addition & 1 deletion posthog-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export type PostHogCoreOptions = {
featureFlagsRequestTimeoutMs?: number
/** For Session Analysis how long before we expire a session (defaults to 30 mins) */
sessionExpirationTimeSeconds?: number
/** Whether to post events to PostHog in JSON or compressed format. Defaults to 'form' */
/** Whether to post events to PostHog in JSON or compressed format. Defaults to 'json' */
captureMode?: 'json' | 'form'
disableGeoip?: boolean
}
Expand Down
2 changes: 1 addition & 1 deletion posthog-core/test/posthog.capture.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('PostHog Core', () => {
await waitForPromises()
expect(mocks.fetch).toHaveBeenCalledTimes(1)
const [url, options] = mocks.fetch.mock.calls[0]
expect(url).toMatch(/^https:\/\/us\.i\.posthog\.com\/e\/\?ip=1&_=[0-9]+&v=[0-9.a-z-]+$/)
expect(url).toMatch(/^https:\/\/us\.i\.posthog\.com\/batch\//)
expect(options.method).toBe('POST')
const body = parseBody(mocks.fetch.mock.calls[0])

Expand Down
1 change: 0 additions & 1 deletion posthog-core/test/posthog.flush.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ describe('PostHog Core', () => {
fetchRetryCount: 3,
fetchRetryDelay: 100,
preloadFeatureFlags: false,
captureMode: 'json',
})
})

Expand Down
1 change: 0 additions & 1 deletion posthog-core/test/posthog.shutdown.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ describe('PostHog Core', () => {
;[posthog, mocks] = createTestClient('TEST_API_KEY', {
flushAt: 10,
preloadFeatureFlags: false,
captureMode: 'json',
})
})

Expand Down
5 changes: 1 addition & 4 deletions posthog-core/test/test-utils/test-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { LZString } from '../../src/lz-string'

export const wait = async (t: number): Promise<void> => {
await new Promise((r) => setTimeout(r, t))
}
Expand All @@ -17,6 +15,5 @@ export const waitForPromises = async (): Promise<void> => {
export const parseBody = (mockCall: any): any => {
const options = mockCall[1]
expect(options.method).toBe('POST')
const bodyText = decodeURIComponent(options.body.split('&')[0].split('=')[1])
return JSON.parse(LZString.decompressFromBase64(bodyText) || '')
return JSON.parse(options.body || '')
}
1 change: 1 addition & 0 deletions posthog-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# 4.1.1 - 2024-08-20

1. Local evaluation returns correct results on `undefined/null` values

# 4.1.0 - 2024-08-14

1. chore: change host to new address.
Expand Down
1 change: 0 additions & 1 deletion posthog-node/src/posthog-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
distinctIdHasSentFlagCalls: Record<string, string[]>

constructor(apiKey: string, options: PostHogOptions = {}) {
options.captureMode = options?.captureMode || 'json'
super(apiKey, options)

this.options = options
Expand Down
29 changes: 18 additions & 11 deletions posthog-react-native/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# Next

## Changed

1. chore: default `captureMode` changed to `json`.
1. To keep using the `form` mode, just set the `captureMode` option to `form` when initializing the PostHog client.

# 3.1.2 - 2024-08-14

## Changed

1. chore: change host to new address.

# 3.1.1 - 2024-04-25
Expand Down Expand Up @@ -121,8 +128,8 @@

# 2.9.0 - 2023-12-04

1. Renamed `personProperties` to `setPersonPropertiesForFlags` to match `posthog-js` and more clearly indicated what it does
2. Renamed `groupProperties` to `setGroupPropertiesForFlags` to match `posthog-js` and more clearly indicated what it does
1. Renamed `personProperties` to `setPersonPropertiesForFlags` to match `posthog-js` and more clearly indicated what it does
2. Renamed `groupProperties` to `setGroupPropertiesForFlags` to match `posthog-js` and more clearly indicated what it does

# 2.8.1 - 2023-10-09

Expand Down Expand Up @@ -164,9 +171,9 @@

# 2.4.0 - 2023-01-27

- Adds support for https://github.com/wix/react-native-navigation
- Allows passing of promise based `PostHog.initAsync` to `<PostHogProvider client={...} />`
- Captures text content in autocapture (configurable via autocapture option `propsToCapture`)
1. Adds support for https://github.com/wix/react-native-navigation
2. Allows passing of promise based `PostHog.initAsync` to `<PostHogProvider client={...} />`
3. Captures text content in autocapture (configurable via autocapture option `propsToCapture`)

# 2.3.0 - 2022-1-26

Expand All @@ -176,21 +183,21 @@

# 2.2.3 - 2023-01-25

- Ensures the distinctId used in `.groupIdentify` is the same as the currently identified user
1. Ensures the distinctId used in `.groupIdentify` is the same as the currently identified user

# 2.2.2 - 2023-01-05

- Fixes an issue with PostHogProvider where autocapture={false} would still capture lifecycle and navigation events.
1. Fixes an issue with PostHogProvider where autocapture={false} would still capture lifecycle and navigation events.

# 2.2.1 - 2022-11-21

- Fixes an issue with async storage selection while installing PostHog React Native
- Fixes an issue where React Hooks for feature flags were conditionally loaded
1. Fixes an issue with async storage selection while installing PostHog React Native
2. Fixes an issue where React Hooks for feature flags were conditionally loaded

# 2.2.0 - 2022-11-11

- Expo modules are no longer required. Expo apps work as before and standalone React Native apps can use the more common native dependencies or roll their own implementation of the necessary functions. See the [official docs](https://posthog.com/docs/integrate/client/react-native) for more information.
- PostHog should now be initialised via the async helper `PostHog.initAsync` to ensure persisted data is loaded before any tracking takes place
1. Expo modules are no longer required. Expo apps work as before and standalone React Native apps can use the more common native dependencies or roll their own implementation of the necessary functions. See the [official docs](https://posthog.com/docs/integrate/client/react-native) for more information.
2. PostHog should now be initialised via the async helper `PostHog.initAsync` to ensure persisted data is loaded before any tracking takes place

# 2.1.4 - 2022-10-28

Expand Down
13 changes: 10 additions & 3 deletions posthog-web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Next

## Changed

1. chore: default `captureMode` changed to `json`.
1. To keep using the `form` mode, just set the `captureMode` option to `form` when initializing the PostHog client.

# 3.0.2 - 2024-06-15

## Fixed
Expand Down Expand Up @@ -66,8 +73,8 @@

# 2.5.0 - 2023-12-04

1. Renamed `personProperties` to `setPersonPropertiesForFlags` to match `posthog-js` and more clearly indicated what it does
2. Renamed `groupProperties` to `setGroupPropertiesForFlags` to match `posthog-js` and more clearly indicated what it does
1. Renamed `personProperties` to `setPersonPropertiesForFlags` to match `posthog-js` and more clearly indicated what it does
2. Renamed `groupProperties` to `setGroupPropertiesForFlags` to match `posthog-js` and more clearly indicated what it does

# 2.4.0 - 2023-04-20

Expand Down Expand Up @@ -98,4 +105,4 @@

# 2.0.1 - 2023-01-25

- Ensures the distinctId used in `.groupIdentify` is the same as the currently identified user
1. Ensures the distinctId used in `.groupIdentify` is the same as the currently identified user