Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/rn-project-token-docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'posthog-react-native': patch
---

Document `apiKey` as your PostHog project token (`phc_...`) and say "project token" in the missing-token error
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"releaseTag": "public",
"params": [
{
"description": "Your PostHog API key",
"description": "Your PostHog project token, which starts with `phc_`. Find it in your project settings: https://us.posthog.com/settings/project-details#variables",
"isOptional": false,
"type": "string",
"name": "apiKey"
Expand Down Expand Up @@ -4045,7 +4045,7 @@
"name": "PostHogProviderProps",
"properties": [
{
"description": "Your PostHog API key",
"description": "Your PostHog project token, which starts with `phc_`. Find it in your project settings: https://us.posthog.com/settings/project-details#variables",
"type": "string",
"name": "apiKey"
},
Expand Down
5 changes: 4 additions & 1 deletion packages/react-native/src/PostHogProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export interface PostHogProviderProps {
children: React.ReactNode
/** PostHog configuration options */
options?: PostHogOptions
/** Your PostHog API key */
/**
* Your PostHog project token, which starts with `phc_`. Find it in your project settings:
* https://us.posthog.com/settings/project-details#variables
*/
apiKey?: string
/** An existing PostHog client instance */
client?: PostHog
Expand Down
5 changes: 3 additions & 2 deletions packages/react-native/src/posthog-rn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,13 +383,14 @@ export class PostHog extends PostHogCore {
*
* @public
*
* @param apiKey - Your PostHog API key
* @param apiKey - Your PostHog project token, which starts with `phc_`. Find it in your project
Comment thread
turnipdabeets marked this conversation as resolved.
Resolved
* settings: https://us.posthog.com/settings/project-details#variables
* @param options - PostHog configuration options
*/
constructor(apiKey: string, options?: PostHogOptions) {
const normalizedApiKey = typeof apiKey === 'string' ? apiKey.trim() : ''
if (!normalizedApiKey) {
console.error("You must pass your PostHog project's api key. The client will be disabled.")
console.error('You must pass your PostHog project token. The client will be disabled.')
}

super(normalizedApiKey, options)
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/test/PostHogProvider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ describe('PostHogProvider', () => {
const posthog = onClient.mock.calls[0][0] as PostHog
expect(posthog.isDisabled).toEqual(true)
expect(consoleErrorSpy).toHaveBeenCalledWith(
"You must pass your PostHog project's api key. The client will be disabled."
'You must pass your PostHog project token. The client will be disabled.'
)
} finally {
consoleErrorSpy.mockRestore()
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/test/posthog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ describe('PostHog React Native', () => {

expect((globalThis as any).window.fetch).not.toHaveBeenCalled()
expect(consoleErrorSpy).toHaveBeenCalledWith(
"You must pass your PostHog project's api key. The client will be disabled."
'You must pass your PostHog project token. The client will be disabled.'
)
} finally {
consoleErrorSpy.mockRestore()
Expand Down
Loading