rn-yandex-metrics
v1.0.1
Published
React Native bridge for Yandex Appmetrica
Downloads
4
Maintainers
Readme
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 fileAdd
new YandexMetricsPackage()
to the list returned by thegetPackages()
method2.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';
// Initialize
YandexMetrics.activateWithApiKey('KEY');
// OR
YandexMetrics.activateWithConfig({
apiKey: 'KEY',
sessionTimeout: 120,
firstActivationAsUpdate: true,
});
YandexMetrics.setUserProfileID('12345');
YandexMetrics.setUserProfileAttributes({ ... })
// Sends a custom event message and additional parameters (optional).
YandexMetrics.reportEvent('My event');
YandexMetrics.reportEvent('My event', 'Test');
YandexMetrics.reportEvent('My event', { foo: 'bar' });
// Send a custom error event and additional parameters (optional).
YandexMetrics.reportError('My error');
YandexMetrics.reportError('My error', 'Test');
YandexMetrics.reportError('My error', { foo: 'bar' });
YandexMetrics.reportError('My error', new Error('test'));