Skip to content

Commit

Permalink
Update mixpanel setup (#3138)
Browse files Browse the repository at this point in the history
* update mixpanel config - Android

* invoke iOS setup

* fix
  • Loading branch information
Undermaken authored Jun 14, 2021
1 parent 3dfa5d4 commit 287528a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
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
14 changes: 10 additions & 4 deletions ts/mixpanel.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import DeviceInfo from "react-native-device-info";
import { MixpanelInstance } from "react-native-mixpanel";
import { Appearance, Platform } from "react-native";
import { Appearance } 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

0 comments on commit 287528a

Please sign in to comment.