Skip to content

Commit abe584b

Browse files
jaredmixpanelBen King
andauthored
Use expo-crypto for UUID on Expo, expose useGzipCompression option and fix JavaScript mode People flushing issue (#288)
* Try creating uuid from Expo * Update package lock * Fix retrieving device ID * Use supplied storage * Fix MixpanelPersistent.instance.initializationCompletePromise * Fix storage module import * Fix persistence * only flush engage when identified * npm audit fix * configure jest for expo-crypto * mock expo-crypto * add useGzipCompression arg, bump native lib versions * update tests and gitignore * update test * add tests * update README with DeepWiki badge * update gitignore * tweak README * remove token and update .gitignore * add more tests * add new test file --------- Co-authored-by: Ben King <ben@lionfeet.com>
1 parent 78c155c commit abe584b

23 files changed

+7937
-3289
lines changed

.gitignore

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ DerivedData
2525
*.ipa
2626
*.xcuserstate
2727
ios/project.xcworkspace
28-
28+
2929
# Android
3030
android/build/
3131
android/app/
@@ -48,3 +48,16 @@ logs/
4848
buck-out/
4949
\.buckd/
5050
*.keystore
51+
52+
# yalc
53+
**/.yalc/
54+
yalc.lock
55+
56+
# AI
57+
CLAUDE.md
58+
claude/
59+
.claude/
60+
.cursor/
61+
.github/copilot-*
62+
.github/instructions/
63+
.github/prompts/

MixpanelReactNative.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ Pod::Spec.new do |s|
1919
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
2020

2121
s.dependency "React-Core"
22-
s.dependency "Mixpanel-swift", '4.4.0'
22+
s.dependency "Mixpanel-swift", '5.0.0'
2323
end

README.md

Lines changed: 67 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,101 @@
1-
2-
31
<div align="center" style="text-align: center">
42
<img src="https://user-images.githubusercontent.com/71290498/231855346-12c8fc52-5f24-485c-b9e6-24468599fb87.png" alt="Mixpanel React Native Library" height="150"/>
53
</div>
64

7-
#####
5+
#####
6+
87
## Table of Contents
98

109
<!-- MarkdownTOC -->
10+
1111
- [Introduction](#introduction)
1212
- [Quick Start Guide](#quick-start-guide)
13-
- [Install Mixpanel](#1-install-mixpanel)
14-
- [Initialize Mixpanel](#2-initialize-mixpanel)
15-
- [Send Data](#3-send-data)
16-
- [Check for Success](#4-check-for-success)
17-
- [Complete Code Example](#complete-code-example)
13+
- [Install Mixpanel](#1-install-mixpanel)
14+
- [Initialize Mixpanel](#2-initialize-mixpanel)
15+
- [Send Data](#3-send-data)
16+
- [Check for Success](#4-check-for-success)
17+
- [Complete Code Example](#complete-code-example)
1818
- [FAQ](#faq)
1919
- [I want to know more!](#i-want-to-know-more)
2020

2121
<!-- /MarkdownTOC -->
2222

23-
2423
## Introduction
24+
2525
Welcome to the official Mixpanel React Native library.
26-
The Mixpanel React Native library is an open-source project, and we'd love to see your contributions!
26+
The Mixpanel React Native library is an open-source project, and we'd love to see your contributions!
2727
We'd also love for you to come and work with us! Check out **[Jobs](https://mixpanel.com/jobs/#openings)** for details.
2828

2929
## Quick Start Guide
3030

3131
Mixpanel's React Native SDK is a wrapper around Mixpanel’s native iOS and Android SDKs and it supports offline tracking. Check out our **[official documentation](https://developer.mixpanel.com/docs/react-native)** for more in depth information on installing and using Mixpanel on React Native.
3232

3333
<a name="installation"></a>
34+
3435
### 1. Install Mixpanel
36+
3537
#### Prerequisites
38+
3639
- React Native v0.6+
3740
- [Setup development environment for React Native](https://reactnative.dev/docs/environment-setup)
41+
3842
#### Steps
39-
1. Under your app's root directory, install Mixpanel React Native SDK.
43+
44+
1. Under your app's root directory, install Mixpanel React Native SDK.
45+
4046
```
4147
npm install mixpanel-react-native
4248
```
49+
4350
2. Under your application's ios folder, run
51+
4452
```
4553
pod install
46-
```
47-
Please note: You do not need to update your Podfile to add Mixpanel.
54+
```
4855

49-
3. Since Xcode 12.5, there is a known swift compile issue, please refer to this **[workaround](https://github.com/mixpanel/mixpanel-react-native/issues/43#issuecomment-829599732)**. However the compile issue has been resolved in Xcode 13.2.1+, there is no extra step required as long as you upgrade to Xcode 13.2.1+.
56+
Please note: You do not need to update your Podfile to add Mixpanel.
5057

58+
3. Since Xcode 12.5, there is a known swift compile issue, please refer to this **[workaround](https://github.com/mixpanel/mixpanel-react-native/issues/43#issuecomment-829599732)**. However the compile issue has been resolved in Xcode 13.2.1+, there is no extra step required as long as you upgrade to Xcode 13.2.1+.
5159

5260
### 2. Initialize Mixpanel
61+
5362
To start tracking with the library you must first initialize with your project token. You can get your project token from [project settings](https://mixpanel.com/settings/project).
5463

5564
```js
56-
import { Mixpanel } from 'mixpanel-react-native';
65+
import { Mixpanel } from "mixpanel-react-native";
5766

5867
const trackAutomaticEvents = false;
5968
const mixpanel = new Mixpanel("Your Project Token", trackAutomaticEvents);
6069
mixpanel.init();
61-
6270
```
71+
6372
Once you've called this method once, you can access `mixpanel` throughout the rest of your application.
73+
6474
### 3. Send Data
75+
6576
Let's get started by sending event data. You can send an event from anywhere in your application. Better understand user behavior by storing details that are specific to the event (properties). After initializing the library, Mixpanel will automatically track some properties by default. [learn more](https://help.mixpanel.com/hc/en-us/articles/115004613766-Default-Properties-Collected-by-Mixpanel)
77+
6678
```js
6779
// Track with event-name
68-
mixpanel.track('Sent Message');
80+
mixpanel.track("Sent Message");
6981
// Track with event-name and property
70-
mixpanel.track('Plan Selected', {'Plan': 'Premium'});
82+
mixpanel.track("Plan Selected", { Plan: "Premium" });
7183
```
84+
7285
In addition to event data, you can also send [user profile data](https://developer.mixpanel.com/docs/react-native#storing-user-profiles). We recommend this after completing the quickstart guide.
86+
7387
### 4. Check for Success
74-
[Open up Events in Mixpanel](http://mixpanel.com/report/events) to view incoming events.
88+
89+
[Open up Events in Mixpanel](http://mixpanel.com/report/events) to view incoming events.
7590
Once data hits our API, it generally takes ~60 seconds for it to be processed, stored, and queryable in your project.
7691
<a name="i-want-to-know-more"></a>
7792

7893
### Complete Code Example
79-
```js
8094

81-
import React from 'react';
95+
```js
96+
import React from "react";
8297
import { Button, SafeAreaView } from "react-native";
83-
import { Mixpanel } from 'mixpanel-react-native';
98+
import { Mixpanel } from "mixpanel-react-native";
8499

85100
const trackAutomaticEvents = false;
86101
const mixpanel = new Mixpanel("Your Project Token", trackAutomaticEvents);
@@ -91,27 +106,30 @@ const SampleApp = () => {
91106
<SafeAreaView>
92107
<Button
93108
title="Select Premium Plan"
94-
onPress={() => mixpanel.track("Plan Selected", {"Plan": "Premium"})}
109+
onPress={() => mixpanel.track("Plan Selected", { Plan: "Premium" })}
95110
/>
96111
</SafeAreaView>
97112
);
98-
}
113+
};
99114

100115
export default SampleApp;
101-
102116
```
117+
103118
### Expo and React Native for Web support (3.0.2 and above)
104-
Starting from version 3.0.2, we have introduced support for Expo, React Native for Web, and other platforms utilizing React Native that do not support iOS and Android directly.
105-
To enable this feature,
106-
<br>Step 1:
119+
120+
Starting from version 3.0.2, we have introduced support for Expo, React Native for Web, and other platforms utilizing React Native that do not support iOS and Android directly.
121+
To enable this feature,
122+
<br>Step 1:
123+
107124
```
108125
npm install @react-native-async-storage/async-storage
109126
```
127+
110128
When JavaScript mode is enabled, Mixpanel utilizes [AsyncStorage](https://react-native-async-storage.github.io/async-storage/) to persist data. If you prefer not to use it, or if AsyncStorage is unavailable in your target environment, you can import or define a different storage class. However, it must follow a subset (see: [`MixpanelAsyncStorage`](index.d.ts)) of the same interface as [AsyncStorage](https://react-native-async-storage.github.io/async-storage/) The following example demonstrates how to use a custom storage solution:
111129

112130
```
113131
// Optional: if you do not want to use the default AsyncStorage
114-
const MyAsyncStorage = require("@my-org/<library-path>/AsyncStorage");
132+
const MyAsyncStorage = require("@my-org/<library-path>/AsyncStorage");
115133
const trackAutomaticEvents = false;
116134
const useNative = false;
117135
const mixpanel = new Mixpanel('YOUR_TOKEN', trackAutomaticEvents, useNative, MyAsyncStorage);
@@ -120,6 +138,7 @@ mixpanel.init();
120138

121139
<br>Step 2:
122140
Initialize Mixpanel with an additional parameter, `useNative`, set to false.
141+
123142
```
124143
const trackAutomaticEvents = false;
125144
const useNative = false;
@@ -128,44 +147,46 @@ const mixpanel = new Mixpanel(
128147
trackAutomaticEvents,
129148
useNative
130149
);
131-
```
132-
This will activate JavaScript mode.
133-
150+
```
134151

135-
👋 👋 Tell us about the Mixpanel developer experience! [https://www.mixpanel.com/devnps](https://www.mixpanel.com/devnps) 👍 👎
152+
This will activate JavaScript mode.
136153

154+
👋 👋 Tell us about the Mixpanel developer experience! [https://www.mixpanel.com/devnps](https://www.mixpanel.com/devnps) 👍 👎
137155

138156
## FAQ
139-
**I want to stop tracking an event/event property in Mixpanel. Is that possible?**
140-
Yes, in Lexicon, you can intercept and drop incoming events or properties. Mixpanel won’t store any new data for the event or property you select to drop. [See this article for more information](https://help.mixpanel.com/hc/en-us/articles/360001307806#dropping-events-and-properties).
141157

142-
**I have a test user I would like to opt out of tracking. How do I do that?**
143-
Mixpanel’s client-side tracking library contains the [optOutTracking()](https://mixpanel.github.io/mixpanel-react-native/Mixpanel.html#optOutTracking) method, which will set the user’s local opt-out state to “true” and will prevent data from being sent from a user’s device. More detailed instructions can be found in the section, [Opting users out of tracking](https://developer.mixpanel.com/docs/react-native#opting-users-out-of-tracking).
158+
**I want to stop tracking an event/event property in Mixpanel. Is that possible?**
159+
Yes, in Lexicon, you can intercept and drop incoming events or properties. Mixpanel won’t store any new data for the event or property you select to drop. [See this article for more information](https://help.mixpanel.com/hc/en-us/articles/360001307806#dropping-events-and-properties).
160+
161+
**I have a test user I would like to opt out of tracking. How do I do that?**
162+
Mixpanel’s client-side tracking library contains the [optOutTracking()](https://mixpanel.github.io/mixpanel-react-native/Mixpanel.html#optOutTracking) method, which will set the user’s local opt-out state to “true” and will prevent data from being sent from a user’s device. More detailed instructions can be found in the section, [Opting users out of tracking](https://developer.mixpanel.com/docs/react-native#opting-users-out-of-tracking).
144163

145-
**Why aren't my events showing up?**
146-
First, make sure your test device has internet access. To preserve battery life and customer bandwidth, the Mixpanel library doesn't send the events you record immediately. Instead, it sends batches to the Mixpanel servers every 60 seconds while your application is running, as well as when the application transitions to the background. You can call [flush()](https://mixpanel.github.io/mixpanel-react-native/Mixpanel.html#flush) manually if you want to force a flush at a particular moment.
164+
**Why aren't my events showing up?**
165+
First, make sure your test device has internet access. To preserve battery life and customer bandwidth, the Mixpanel library doesn't send the events you record immediately. Instead, it sends batches to the Mixpanel servers every 60 seconds while your application is running, as well as when the application transitions to the background. You can call [flush()](https://mixpanel.github.io/mixpanel-react-native/Mixpanel.html#flush) manually if you want to force a flush at a particular moment.
147166

148167
```
149168
mixpanel.flush();
150169
```
151170

152-
If your events are still not showing up after 60 seconds, check if you have opted out of tracking. You can also enable Mixpanel debugging and logging, it allows you to see the debug output from the Mixpanel library. To enable it, call [setLoggingEnabled](https://mixpanel.github.io/mixpanel-react-native/Mixpanel.html#setLoggingEnabled) with true, then run your iOS project with Xcode or android project with Android Studio. The logs should be available in the console.
171+
If your events are still not showing up after 60 seconds, check if you have opted out of tracking. You can also enable Mixpanel debugging and logging, it allows you to see the debug output from the Mixpanel library. To enable it, call [setLoggingEnabled](https://mixpanel.github.io/mixpanel-react-native/Mixpanel.html#setLoggingEnabled) with true, then run your iOS project with Xcode or android project with Android Studio. The logs should be available in the console.
153172

154173
```
155174
mixpanel.setLoggingEnabled(true);
156175
```
157176

158-
**Starting with iOS 14.5, do I need to request the user’s permission through the AppTrackingTransparency framework to use Mixpanel?**
177+
**Starting with iOS 14.5, do I need to request the user’s permission through the AppTrackingTransparency framework to use Mixpanel?**
159178
No, Mixpanel does not use IDFA so it does not require user permission through the AppTrackingTransparency(ATT) framework.
160179

161-
**If I use Mixpanel, how do I answer app privacy questions for the App Store?**
162-
Please refer to our [Apple App Developer Privacy Guidance](https://mixpanel.com/legal/app-store-privacy-details/)
163-
180+
**If I use Mixpanel, how do I answer app privacy questions for the App Store?**
181+
Please refer to our [Apple App Developer Privacy Guidance](https://mixpanel.com/legal/app-store-privacy-details/)
164182

165183
## I want to know more!
166184

167185
No worries, here are some links that you will find useful:
168-
* **[Sample apps](https://github.com/mixpanel/mixpanel-react-native/tree/master/Samples)**
169-
* **[Full API Reference](https://mixpanel.github.io/mixpanel-react-native/Mixpanel.html)**
186+
187+
- **[Sample apps](https://github.com/mixpanel/mixpanel-react-native/tree/master/Samples)**
188+
- **[Full API Reference](https://mixpanel.github.io/mixpanel-react-native/Mixpanel.html)**
189+
190+
[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/mixpanel/mixpanel-react-native)
170191

171192
Have any questions? Reach out to Mixpanel [Support](https://help.mixpanel.com/hc/en-us/requests/new) to speak to someone smart, quickly.

0 commit comments

Comments
 (0)