react-native-appmetrica/README.md

103 lines
2.6 KiB
Markdown
Raw Normal View History

2021-01-21 07:29:24 +03:00
# react-native-appmetrica-next
2020-06-08 22:14:06 +03:00
React Native bridge to the [AppMetrica](https://appmetrica.yandex.com/) on both iOS and Android.
2021-01-21 07:29:24 +03:00
react-native-push-next library functionality is expanded [react-native-appmetrica](https://github.com/yandexmobile/react-native-appmetrica)
2020-06-08 22:14:06 +03:00
## Installation
2021-01-21 07:29:24 +03:00
`npm install react-native-appmetrica-next --save`
or
`yearn add react-native-appmetrica-next`
2021-02-17 15:06:22 +03:00
# NEXT for Android
2021-02-17 15:01:55 +03:00
2021-02-17 15:06:22 +03:00
## create file FirebaseMessagingMasterService.java in you project
2021-02-17 15:01:55 +03:00
2021-02-17 15:06:22 +03:00
```js
2021-02-17 15:01:55 +03:00
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.
}
}
2021-02-17 15:06:22 +03:00
```
## Your files to Android manifest
2021-02-17 15:01:55 +03:00
2021-02-17 15:06:22 +03:00
```js
<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>
```
2021-02-17 15:01:55 +03:00
2021-02-17 15:06:22 +03:00
# NEXT for iOS
2021-02-17 15:01:55 +03:00
2020-06-08 22:14:06 +03:00
## Usage
```js
2021-01-21 07:29:24 +03:00
import AppMetrica from "react-native-appmetrica-next";
2020-06-08 22:14:06 +03:00
// Starts the statistics collection process.
2020-12-22 15:03:52 +03:00
AppMetrica.activate({
2021-01-21 07:29:24 +03:00
apiKey: "...KEY...",
2020-06-08 22:14:06 +03:00
sessionTimeout: 120,
firstActivationAsUpdate: true,
});
// Sends a custom event message and additional parameters (optional).
2021-01-21 07:29:24 +03:00
AppMetrica.reportEvent("My event");
AppMetrica.reportEvent("My event", { foo: "bar" });
2020-06-08 22:14:06 +03:00
// Send a custom error event.
2021-01-21 07:29:24 +03:00
AppMetrica.reportError("My error");
2021-01-21 14:00:35 +03:00
// 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
2020-06-08 22:14:06 +03:00
```