Skip to content

Commit

Permalink
fix: using captureMode=form won't throw an error and retry unnecess…
Browse files Browse the repository at this point in the history
…arily (#181)
  • Loading branch information
marandaneto authored Feb 15, 2024
1 parent f2a1ab5 commit 2911a8f
Show file tree
Hide file tree
Showing 18 changed files with 184 additions and 6 deletions.
40 changes: 40 additions & 0 deletions examples/example_expo_rn_web/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Learn more https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files

# dependencies
node_modules/

# Expo
.expo/
dist/
web-build/

# Native
*.orig.*
*.jks
*.p8
*.p12
*.key
*.mobileprovision

# Metro
.metro-health-check*

# debug
npm-debug.*
yarn-debug.*
yarn-error.*

# macOS
.DS_Store
*.pem

# local env files
.env*.local

# typescript
*.tsbuildinfo

yarn.lock
yalc.lock
package-lock.json
Gemfile.lock
43 changes: 43 additions & 0 deletions examples/example_expo_rn_web/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { StatusBar } from 'expo-status-bar'
import { StyleSheet, Text, View } from 'react-native'

import PostHog from 'posthog-react-native'

export const $posthog = PostHog.initAsync('phc_pQ70jJhZKHRvDIL5ruOErnPy6xiAiWCqlL4ayELj4X8', {
host: 'https://app.posthog.com',
flushAt: 1,
captureNativeAppLifecycleEvents: false,
sendFeatureFlagEvent: false,
preloadFeatureFlags: false,
// captureMode: 'form',
// persistence: 'memory',
}).then((client) => {
client.debug(true)
// console.log('PostHog client initialized');
client.capture('test')
// console.log(`test: ${client.getFeatureFlag('test')}`);
// client.on('error', err => {
// console.error('PostHog error', err);
// });
// client.on('capture', ev => {
// console.error('PostHog ev', ev);
// });
})

export default function App() {
return (
<View style={styles.container}>
<Text>Open up App.tsx to start working on your app!</Text>
<StatusBar style="auto" />
</View>
)
}

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
})
33 changes: 33 additions & 0 deletions examples/example_expo_rn_web/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"expo": {
"name": "example_expo_rn_web",
"slug": "example_expo_rn_web",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"userInterfaceStyle": "light",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": true
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#ffffff"
}
},
"web": {
"favicon": "./assets/favicon.png"
},
"plugins": [
"expo-localization"
]
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/example_expo_rn_web/assets/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/example_expo_rn_web/assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/example_expo_rn_web/assets/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions examples/example_expo_rn_web/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = function(api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
};
};
36 changes: 36 additions & 0 deletions examples/example_expo_rn_web/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "example_expo_rn_web",
"version": "1.0.0",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"preinstall": "yarn build:posthog",
"prestart": "yarn build:posthog",
"build:posthog": "yarn build:posthog:publish && yarn build:posthog:link",
"build:posthog:publish": "cd ../../posthog-react-native && yalc publish --replace",
"build:posthog:link": "yalc add posthog-react-native"
},
"dependencies": {
"expo": "~50.0.6",
"expo-status-bar": "~1.11.1",
"react": "18.2.0",
"react-native": "0.73.4",
"posthog-react-native": "file:.yalc/posthog-react-native",
"@react-native-async-storage/async-storage": "^1.21.0",
"expo-application": "~5.8.3",
"expo-device": "~5.9.3",
"expo-localization": "~14.8.3",
"react-native-web": "~0.19.6",
"react-dom": "18.2.0",
"@expo/metro-runtime": "~3.1.3"
},
"devDependencies": {
"@babel/core": "^7.20.0",
"@types/react": "~18.2.45",
"typescript": "^5.1.3"
},
"private": true
}
6 changes: 6 additions & 0 deletions examples/example_expo_rn_web/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "expo/tsconfig.base",
"compilerOptions": {
"strict": true
}
}
6 changes: 5 additions & 1 deletion posthog-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,11 @@ export abstract class PostHogCoreStateless {
// fetch will only throw on network errors or on timeouts
throw new PostHogFetchNetworkError(e)
}
if (res.status < 200 || res.status >= 400) {
// If we're in no-cors mode, we can't access the response status
// We only throw on HTTP errors if we're not in no-cors mode
// https://developer.mozilla.org/en-US/docs/Web/API/Request/mode#no-cors
const isNoCors = options.mode === 'no-cors'
if (!isNoCors && (res.status < 200 || res.status >= 400)) {
throw new PostHogFetchHttpError(res)
}
return res
Expand Down
1 change: 1 addition & 0 deletions posthog-core/test/posthog.flush.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('PostHog Core', () => {
fetchRetryCount: 3,
fetchRetryDelay: 100,
preloadFeatureFlags: false,
captureMode: 'json',
})
})
it("doesn't fail when queue is empty", async () => {
Expand Down
4 changes: 4 additions & 0 deletions posthog-node/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 3.6.3 - 2024-02-15

1. fix: using `captureMode=form` won't throw an error and retry unnecessarily

# 3.6.2 - 2024-02-06

1. Swapped to `uuidv7` for unique ID generation
Expand Down
2 changes: 1 addition & 1 deletion posthog-node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "posthog-node",
"version": "3.6.2",
"version": "3.6.3",
"description": "PostHog Node.js integration",
"repository": {
"type": "git",
Expand Down
5 changes: 3 additions & 2 deletions posthog-react-native/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Next
# 2.11.4 - 2024-02-15

1. `$app_build` was returning the OS internal build number instead of the app's build number.
1. fix: using `captureMode=form` won't throw an error and retry unnecessarily
2. `$app_build` was returning the OS internal build number instead of the app's build number.
1. This flag was used to track app versions, you might experience a sudden increase of `Application Updated` events, but only if you're using the `react-native-device-info` library.

# 2.11.3 - 2024-02-08
Expand Down
2 changes: 1 addition & 1 deletion posthog-react-native/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "posthog-react-native",
"version": "2.11.3",
"version": "2.11.4",
"main": "lib/posthog-react-native/index.js",
"files": [
"lib/"
Expand Down
4 changes: 4 additions & 0 deletions posthog-web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2.6.2 - 2024-02-15

1. fix: using `captureMode=form` won't throw an error and retry unnecessarily

# 2.6.1 - 2024-02-06

1. Swapped to `uuidv7` for unique ID generation
Expand Down
2 changes: 1 addition & 1 deletion posthog-web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "posthog-js-lite",
"version": "2.6.1",
"version": "2.6.2",
"main": "lib/index.cjs.js",
"module": "lib/index.esm.js",
"types": "lib/index.d.ts",
Expand Down

0 comments on commit 2911a8f

Please sign in to comment.