Skip to content

Commit 11b50be

Browse files
authored
feat: react native surveys (#422)
1 parent 8850067 commit 11b50be

31 files changed

+2211
-55
lines changed

examples/example-expo-latest/App.tsx

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState } from 'react'
22
import { StatusBar } from 'expo-status-bar'
33
import { StyleSheet, Text, View } from 'react-native'
4-
import PostHog, { PostHogProvider } from 'posthog-react-native'
4+
import PostHog, { PostHogProvider, PostHogSurveyProvider } from 'posthog-react-native'
55
// import { WebView } from 'react-native-webview';
66

77
export const posthog = new PostHog('phc_QFbR1y41s5sxnNTZoyKG2NJo2RlsCIWkUfdpawgb40D', {
@@ -26,7 +26,7 @@ export const SharedPostHogProvider = (props: any) => {
2626
captureTouches: true,
2727
customLabelProp: 'ph-my-label',
2828
}}
29-
debug
29+
debug={true}
3030
>
3131
{props.children}
3232
</PostHogProvider>
@@ -48,12 +48,12 @@ export default function App() {
4848

4949
return (
5050
<SharedPostHogProvider>
51-
<View style={styles.container}>
52-
<Text ph-my-label="special-text-changed" onPress={handleClick}>
53-
{buttonText}
54-
</Text>
55-
<StatusBar style="auto" />
56-
</View>
51+
<PostHogSurveyProvider client={posthog}>
52+
<View style={styles.container}>
53+
<Text onPress={handleClick}>{buttonText}</Text>
54+
<StatusBar style="auto" />
55+
</View>
56+
</PostHogSurveyProvider>
5757
</SharedPostHogProvider>
5858
)
5959
}

examples/example-expo-latest/ios/exampleexpolatest.xcodeproj/project.pbxproj

+2
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@
279279
"${PODS_CONFIGURATION_BUILD_DIR}/ExpoFileSystem/ExpoFileSystem_privacy.bundle",
280280
"${PODS_CONFIGURATION_BUILD_DIR}/ExpoLocalization/ExpoLocalization_privacy.bundle",
281281
"${PODS_CONFIGURATION_BUILD_DIR}/PostHog/PostHog.bundle",
282+
"${PODS_CONFIGURATION_BUILD_DIR}/RNSVG/RNSVGFilters.bundle",
282283
"${PODS_CONFIGURATION_BUILD_DIR}/React-Core/RCTI18nStrings.bundle",
283284
);
284285
name = "[CP] Copy Pods Resources";
@@ -290,6 +291,7 @@
290291
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/ExpoFileSystem_privacy.bundle",
291292
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/ExpoLocalization_privacy.bundle",
292293
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/PostHog.bundle",
294+
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/RNSVGFilters.bundle",
293295
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/RCTI18nStrings.bundle",
294296
);
295297
runOnlyForDeploymentPostprocessing = 0;

examples/example-expo-latest/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
"posthog-react-native-session-replay": "^1.0.0",
2525
"react": "18.2.0",
2626
"react-native": "0.74.5",
27-
"react-native-webview": "^13.12.4"
27+
"react-native-webview": "^13.12.4",
28+
"react-native-safe-area-context": "^4.10.1",
29+
"react-native-svg": "^15.0.0"
2830
},
2931
"devDependencies": {
3032
"@babel/core": "^7.20.0",

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"@babel/preset-env": "^7.18.6",
3333
"@babel/preset-react": "^7.18.6",
3434
"@babel/preset-typescript": "^7.18.6",
35+
"@rollup/plugin-alias": "^5.1.1",
3536
"@rollup/plugin-babel": "^5.3.1",
3637
"@rollup/plugin-commonjs": "^22.0.1",
3738
"@rollup/plugin-json": "^4.1.0",

posthog-ai/src/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export const sendEventToPosthog = ({
167167
}
168168
}
169169

170-
let additionalTokenValues = {
170+
const additionalTokenValues = {
171171
...(usage.reasoningTokens ? { $ai_reasoning_tokens: usage.reasoningTokens } : {}),
172172
...(usage.cacheReadInputTokens ? { $ai_cache_read_input_tokens: usage.cacheReadInputTokens } : {}),
173173
...(usage.cacheCreationInputTokens ? { $ai_cache_creation_input_tokens: usage.cacheCreationInputTokens } : {}),

posthog-ai/src/vercel/middleware.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ const mapVercelPrompt = (prompt: LanguageModelV1Prompt): PostHogInput[] => {
113113
}
114114

115115
const mapVercelOutput = (result: any): PostHogInput[] => {
116-
let output = {
116+
const output = {
117117
...(result.text ? { text: result.text } : {}),
118118
...(result.object ? { object: result.object } : {}),
119119
...(result.reasoning ? { reasoning: result.reasoning } : {}),
@@ -156,10 +156,10 @@ export const createInstrumentationMiddleware = (
156156
options.posthogModelOverride ?? (result.response?.modelId ? result.response.modelId : model.modelId)
157157
const provider = options.posthogProviderOverride ?? extractProvider(model)
158158
const baseURL = '' // cannot currently get baseURL from vercel
159-
let content = mapVercelOutput(result)
159+
const content = mapVercelOutput(result)
160160
// let tools = result.toolCalls
161-
let providerMetadata = result.providerMetadata
162-
let additionalTokenValues = {
161+
const providerMetadata = result.providerMetadata
162+
const additionalTokenValues = {
163163
...(providerMetadata?.openai?.reasoningTokens
164164
? { reasoningTokens: providerMetadata.openai.reasoningTokens }
165165
: {}),

0 commit comments

Comments
 (0)