Go to file
Andrey Bondarenko 8d98af6b71 change doc
2021-02-17 22:01:55 +10:00
android change doc 2021-02-17 22:01:55 +10:00
ios change 2021-02-17 19:47:34 +10:00
.gitignore release 2.0.0 2020-06-08 22:14:06 +03:00
.npmignore release 2.0.0 2020-06-08 22:14:06 +03:00
AUTHORS add reportUserProfile 2021-01-21 16:10:35 +10:00
index.js add getToken 2021-02-15 17:59:08 +10:00
LICENSE release 2.0.0 2020-06-08 22:14:06 +03:00
package.json change 2021-02-17 19:47:34 +10:00
react-native-appmetrica-next.podspec add pushSDK for Android 2021-01-21 16:18:28 +10:00
README.md change doc 2021-02-17 22:01:55 +10:00

react-native-appmetrica-next

React Native bridge to the AppMetrica on both iOS and Android. react-native-push-next library functionality is expanded react-native-appmetrica

Installation

npm install react-native-appmetrica-next --save or yearn add react-native-appmetrica-next

NEXT for Android

create file

` import com.google.firebase.messaging.FirebaseMessagingService; import com.google.firebase.messaging.RemoteMessage; import com.yandex.metrica.push.firebase.MetricaMessagingService;

public class FirebaseMessagingMasterService extends FirebaseMessagingService { @Override public void onMessageReceived(RemoteMessage message) { super.onMessageReceived(message); // AppMetrica automatically recognizes its messages and processes them only. new MetricaMessagingService().processPush(this, message);

    // Implement the logic for sending messages to other SDKs.
}

} `

Android manifest

<application> ... <service android:name=".FirebaseMessagingMasterService" android:enabled="true" android:exported="false"> <intent-filter android:priority="100"> <action android:name="com.google.firebase.MESSAGING_EVENT"/> </intent-filter> </service> <service android:name="com.yandex.metrica.push.firebase.MetricaMessagingService" tools:node="remove"/> ... </application>

Usage

import AppMetrica from "react-native-appmetrica-next";

// Starts the statistics collection process.
AppMetrica.activate({
  apiKey: "...KEY...",
  sessionTimeout: 120,
  firstActivationAsUpdate: true,
});

// Sends a custom event message and additional parameters (optional).
AppMetrica.reportEvent("My event");
AppMetrica.reportEvent("My event", { foo: "bar" });

// Send a custom error event.
AppMetrica.reportError("My error");

// reportUserProfile
    AppMetrica.activate({
      apiKey: "...KEY...",
      sessionTimeout: 120,
      firstActivationAsUpdate: true,
    });
    RNAppMetrica.setUserProfileID('id');
    RNAppMetrica.reportUserProfile({
      name: 'Andrey Bondarenko',
      floor: 'male',
      age: 34,
      isNotification: true,
    });

// init Push SDK example for iOS
 checkPermission = async () => {
    const authorizationStatus = await messaging().requestPermission();

    if (authorizationStatus === messaging.AuthorizationStatus.AUTHORIZED) {
      const deviceToken = await messaging().getToken();

      RNAppMetrica.initPush(deviceToken); -> // for iOS
      // or
      RNAppMetrica.initPush(); -> // for Android