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

Update mixpanel setup #3138

Merged
merged 3 commits into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<meta-data android:name="com.dieam.reactnativepushnotification.notification_foreground"
android:value="true"/>


<meta-data android:name="com.dieam.reactnativepushnotification.notification_color"
android:resource="@color/white"/>

Expand Down Expand Up @@ -72,6 +73,11 @@

<!-- END Required by react-native-push-notification -->

<!-- Mixpanel -->

<meta-data android:name="com.mixpanel.android.MPConfig.UseIpAddressForGeolocation"
android:value="false" />

<!-- START Required by mixpanel push notification -->
<service
android:name="com.mixpanel.android.mpmetrics.MixpanelFCMMessagingService"
Expand All @@ -84,6 +90,8 @@

<!-- END Required by mixpanel push notification -->

<!-- END Mixpanel -->


<activity android:name=".MainActivity" android:launchMode="singleTask" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:windowSoftInputMode="adjustResize">
<intent-filter>
Expand Down
12 changes: 9 additions & 3 deletions ts/mixpanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Appearance, Platform } from "react-native";
import { mixpanelToken } from "./config";
import { isScreenReaderEnabled } from "./utils/accessibility";
import { getAppVersion } from "./utils/appVersion";
import { isAndroid, isIos } from "./utils/platform";

// eslint-disable-next-line
export let mixpanel: MixpanelInstance | undefined;
Expand All @@ -24,7 +25,12 @@ initializeMixPanel()

const setupMixpanel = async (mp: MixpanelInstance) => {
const screenReaderEnabled: boolean = await isScreenReaderEnabled();
await mp.disableIpAddressGeolocalization();
// on iOS it can be deactivate by invoking a SDK method
// on Android it can be done adding an extra config in AndroidManifest
// see https://help.mixpanel.com/hc/en-us/articles/115004494803-Disable-Geolocation-Collection
if (isIos) {
await mp.disableIpAddressGeolocalization();
}
await mp.registerSuperProperties({
isScreenReaderEnabled: screenReaderEnabled,
fontScale: DeviceInfo.getFontScaleSync(),
Expand All @@ -38,10 +44,10 @@ const setupMixpanel = async (mp: MixpanelInstance) => {

export const setMixpanelPushNotificationToken = (token: string) => {
if (mixpanel) {
if (Platform.OS === "ios") {
if (isIos) {
return mixpanel.addPushDeviceToken(token);
}
if (Platform.OS === "android") {
if (isAndroid) {
return mixpanel.setPushRegistrationId(token);
}
}
Expand Down