rn-yandex-metrics
Install
yarn add rn-yandex-metrics
-
IOS
RN<0.60:
react-native link rn-yandex-metrics
With CocoaPods, add the following line to
your Podfile:
pod 'rn-yandex-metrics', :path => '../node_modules/rn-yandex-metrics'
pod 'YandexMobileMetrica', '3.17.0'
Then run pod install.
RN>=0.60:
With React Native 0.60 and later, linking of pods is done automatically
cd ios
pod install
-
Android
RN<0.60:
2.1. Open up android/app/src/main/java/[...]/MainApplication.java
-
Add import com.mastereugene.yandexmetrics.YandexMetricsPackage; to the imports at the top of the file
-
Add new YandexMetricsPackage() to the list returned by the getPackages() method
2.2. Append the following lines to `android/settings.gradle`:
`include ':rn-yandex-metrics'
project(':rn-yandex-metrics').projectDir = new File(rootProject.projectDir, '../node_modules/rn-yandex-metrics/android')`
2.3. Insert the following lines inside the dependencies block in `android/app/build.gradle`:
` implementation project(':rn-yandex-metrics')`
RN>=0.60:
With React Native 0.60 and later, linking is done automatically
Usage
import YandexMetrics from 'rn-yandex-metrics';
YandexMetrics.activateWithApiKey('KEY');
YandexMetrics.activateWithConfig({
apiKey: 'KEY',
sessionTimeout: 120,
firstActivationAsUpdate: true,
});
YandexMetrics.setUserProfileID('12345');
YandexMetrics.setUserProfileAttributes({ ... })
YandexMetrics.reportEvent('My event');
YandexMetrics.reportEvent('My event', 'Test');
YandexMetrics.reportEvent('My event', { foo: 'bar' });
YandexMetrics.reportError('My error');
YandexMetrics.reportError('My error', 'Test');
YandexMetrics.reportError('My error', { foo: 'bar' });
YandexMetrics.reportError('My error', new Error('test'));