Skip to content

Use expo-crypto for UUID on Expo, expose useGzipCompression option and fix JavaScript mode People flushing issue #288

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

Merged
merged 22 commits into from
May 30, 2025

Conversation

jaredmixpanel
Copy link
Collaborator

No description provided.

@jaredmixpanel jaredmixpanel requested a review from Copilot May 20, 2025 18:27
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR centralizes UUID generation with expo-crypto, ensures proper default imports for AsyncStorage, synchronizes user identity fields in queues, and introduces a gzip compression flag across JS, iOS, and Android modules.

  • Added expo-crypto to reliably generate randomUUID() and fall back to uuid.v4().
  • Implemented identifyUserQueue in the queue manager and wired it through core, main, and persistent layers.
  • Exposed a useGzipCompression option in the JS API and native modules, and bumped native dependency versions.

Reviewed Changes

Copilot reviewed 20 out of 21 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
package.json Added expo-crypto dependency for UUID generation fallback.
javascript/mixpanel-storage.js Detect default exports from AsyncStorage require.
javascript/mixpanel-queue.js Imported MixpanelType, added identifyUserQueue, and guard.
javascript/mixpanel-persistent.js Use randomUUID() fallback, pass token to getInstance, add isIdentified.
javascript/mixpanel-main.js Pass token to persistent, invoke identifyUserQueue, update return values.
javascript/mixpanel-core.js Exposed identifyUserQueue method.
ios/MixpanelReactNative.swift Added useGzipCompression parameter with default.
index.js Updated init signature and JSDoc for useGzipCompression.
android/src/.../MixpanelReactNativeModule.java Extended initialize signature with gzip flag.
android/build.gradle Bumped mixpanel-android to 8.1.0.
tests/queue.test.js Mocked new persistent methods and added USER-type queue tests.
tests/main.test.js Added identifyUserQueue mock and new identify tests.
tests/jest_setup.js Mocked expo-crypto’s randomUUID().
tests/index.test.js Updated tests for gzip flag and formatting.
Samples/MixpanelExpo/package.json Reordered and added metro runtime dependency.
Samples/MixpanelExpo/App.js Changed placeholder token to a real token (to be reviewed).
MixpanelReactNative.podspec Bumped Mixpanel-swift to 5.0.0.
Files not reviewed (1)
  • Samples/MixpanelExpo/package-lock.json: Language not supported
Comments suppressed due to low confidence (2)

tests/main.test.js:371

  • The test references MixpanelType but this constant is not imported in this file. Add import { MixpanelType } from './mixpanel-constants'; (or correct path) at the top.
expect(mixpanelMain.core.addToMixpanelQueue).toHaveBeenCalledWith(token, MixpanelType.EVENTS, expect.any(Object));

Samples/MixpanelExpo/App.js:17

  • [nitpick] Sample app is hardcoding a real Mixpanel token. Consider reverting to a placeholder (e.g., YOUR_MIXPANEL_TOKEN) or using an environment variable.
    "26d77caa3b67accd112d74ecfc0214a4",

@jaredmixpanel jaredmixpanel changed the title Test UUID Fix Use expo-crypto for UUID on Expo, expose useGzipCompression option and fix JavaScript mode People flushing issue May 22, 2025
@jaredmixpanel jaredmixpanel marked this pull request as ready for review May 22, 2025 23:43
@jaredmixpanel jaredmixpanel requested a review from Copilot May 30, 2025 21:49
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR integrates Expo’s crypto API for UUID generation, exposes a new useGzipCompression option across JS and native layers, and ensures user identity fields are correctly applied before flushing the USER queue.

  • Use expo-crypto.randomUUID() with fallback to uuid.v4() for device IDs.
  • Add a useGzipCompression parameter to the JS init API and native iOS/Android modules.
  • Introduce identifyUserQueue to update USER‐type queue items with up-to-date identity fields.

Reviewed Changes

Copilot reviewed 21 out of 22 changed files in this pull request and generated no comments.

Show a summary per file
File Description
package.json Added expo-crypto dependency.
javascript/mixpanel-storage.js Handle .default export for AsyncStorage module.
javascript/mixpanel-queue.js Import MixpanelType; update getQueue logic; add identifyUserQueue.
javascript/mixpanel-persistent.js Use expo-crypto.randomUUID with fallback; add isIdentified; update getInstance.
javascript/mixpanel-main.js Pass token into getInstance; call identifyUserQueue before identify; cleanup identity getters.
javascript/mixpanel-core.js Expose identifyUserQueue in core API.
ios/MixpanelReactNative.swift Expose useGzipCompression in native initializer.
index.js Add useGzipCompression parameter to public init signature.
android/src/.../MixpanelReactNativeModule.java Add useGzipCompression to init and enable gzip.
android/build.gradle Bump com.mixpanel.android to version 8.1.0.
tests/queue.test.js Add mocks and tests for the extended identifyUserQueue flow.
tests/main.test.js Mock and assert core.identifyUserQueue behavior in identify.
tests/index.test.js Update test to expect useGzipCompression argument.
tests/jest_setup.js Mock expo-crypto.randomUUID.
Samples/MixpanelExpo/App.js Replace placeholder token (note: uses a real token here).
README.md Update docs for useGzipCompression and formatting tweaks.
MixpanelReactNative.podspec Bump Mixpanel-swift dependency to 5.0.0.
Files not reviewed (1)
  • Samples/MixpanelExpo/package-lock.json: Language not supported
Comments suppressed due to low confidence (2)

javascript/mixpanel-queue.js:47

  • The helper getPersistent is not defined in this module, causing a runtime error. Import or reference the persistent instance correctly (e.g., use MixpanelPersistent.getInstance() or define getPersistent).
(type === MixpanelType.USER && !getPersistent().isIdentified(token))

Samples/MixpanelExpo/App.js:17

  • A real Mixpanel project token is exposed in the sample app. Replace it with a placeholder (e.g., YOUR_MIXPANEL_TOKEN) to avoid leaking credentials.
"26d77caa3b67accd112d74ecfc0214a4"

@jaredmixpanel jaredmixpanel added bug Something isn't working enhancement New feature or request labels May 30, 2025
@jaredmixpanel jaredmixpanel merged commit abe584b into master May 30, 2025
8 checks passed
@rajgupta027
Copy link

It won't work in applications running on bare react-native-cli, getting below error. Add a suitable fallback or handle both cases to support expo and react native cli.

Additionally I have to install "expo-crypto": "^14.1.4" & "expo-modules-core": "^2.3.13" unnecessarily to make it work.

<----------------------ERROR-LOG------------------->
ERROR Error: Unable to resolve module expo-modules-core from /Users/admin_user/Desktop/AwesomeProject/node_modules/expo-crypto/build/Crypto.js: expo-modules-core could not be found within the project or in these directories:
node_modules
1 | import { toByteArray } from 'base64-js';

2 | import { UnavailabilityError } from 'expo-modules-core';
| ^
3 | import { CryptoDigestAlgorithm, CryptoEncoding } from './Crypto.types';
4 | import ExpoCrypto from './ExpoCrypto';
5 | export * from './Crypto.types';

@jaredmixpanel
Copy link
Collaborator Author

@rajgupta027 v3.1.1 has been released which makes expo-crypto and optional dependency

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants