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

PosthogReactNativeSessionReplayModule: Value for anonymousId cannot be cast from Double to String #406

Open
1 of 4 tasks
tyrauber opened this issue Feb 22, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@tyrauber
Copy link

Bug description

We are trying to implement session replay in our expo app and are experiencing a fatal crash on launch for Android.

UnexpectedNativeTypeException
Value for distinctId cannot be cast from Double to String
Value for anonymousId cannot be cast from Double to String

com.facebook.react.bridge.ReadableNativeMap in checkInstance at line 143
com.facebook.react.bridge.ReadableNativeMap in getNullableValue at line 131
com.facebook.react.bridge.ReadableNativeMap in getString at line 165
com.posthogreactnativesessionreplay.PosthogReactNativeSessionReplayModule in start$lambda$1 at line 45
com.posthogreactnativesessionreplay.PosthogReactNativeSessionReplayModule in $r8$lambda$4lHZBEqnYa_uAoGrVwqBKk2ltOU
com.posthogreactnativesessionreplay.PosthogReactNativeSessionReplayModule$$ExternalSyntheticLambda0 in run at line 12
android.os.Handler in handleCallback at line 883
android.os.Handler in dispatchMessage at line 100
android.os.Looper in loop at line 241
android.app.ActivityThread in main at line 7604
java.lang.reflect.Method in invoke
com.android.internal.os.RuntimeInit$MethodAndArgsCaller in run at line 492
com.android.internal.os.ZygoteInit in main at line 941

How to reproduce

  1. Install dependencies:
    "posthog-react-native": "^3.9.1",
    "posthog-react-native-session-replay": "^1.0.0",
  1. Configure Posthog:
export const posthog = new PostHog(Constants?.expoConfig?.extra?.POSTHOG_API_KEY, {
  host: 'https://us.i.posthog.com',
  enableSessionReplay: true,
  sessionReplayConfig: {
    maskAllTextInputs: false,
    maskAllImages: false,
    maskAllSandboxedViews: false,
    captureLog: true,
    androidDebouncerDelayMs: 1000,
    iOSdebouncerDelayMs: 1000,
  },
});
  1. Use AppState hook to indentify user:
  useEffect(() => {
    if (posthog) {
      if (user?.id) {
        const stringId = String(user.id);
        posthog.alias(stringId);
        posthog.identify(stringId, userPayload);
        posthog.group('state', user.state);
      } else {
        posthog.group('state', 'anonymous');
      }
    }
  }, [AppState.currentState]);
  1. Implement PostHogProvider
  2. Build a store release for android and push for an internal test on google play

We were not seeing this issue until we implemented posthog-react-native-session-replay and bumped both posthog libraries.

Related sub-libraries

  • All of them
  • posthog-web
  • posthog-node
  • posthog-react-native

Additional context

Thank you for your bug report – we love squashing them!

@tyrauber tyrauber added the bug Something isn't working label Feb 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant