2017-09-23 13:05:59 +03:00
[![Build Status ](https://travis-ci.org/doochik/react-native-appmetrica.svg?branch=master )](https://travis-ci.org/doochik/react-native-appmetrica)
[![NPM version ](https://badge.fury.io/js/react-native-appmetrica.svg )](https://www.npmjs.com/package/react-native-appmetrica)
2017-09-18 09:46:10 +03:00
# react-native-appmetrica
2017-09-30 18:10:42 +03:00
React Native bridge to the [AppMetrica ](https://appmetrica.yandex.com/ ) on both iOS and Android.
2017-09-23 13:15:11 +03:00
## Installation
2017-09-30 19:47:14 +03:00
1. **Only for iOS** : [setup AppMetrica ](https://tech.yandex.com/appmetrica/ ).
2017-09-23 13:15:11 +03:00
`YandexMobileMetrica.framework` should be placed at `<project_dir>/ios/` or `<project_dir>/ios/Frameworks/` .
Otherwise you'll get build error.
2. `npm install --save react-native-appmetrica`
3. `react-native link react-native-appmetrica`
2017-09-30 15:41:17 +03:00
**iOS notice**: If you build failed after installing SDK and `react-native-appmetrica`
make sure `YandexMobileMetrica.framework` and `libRCTAppMetrica.a` are included at Build Phase -> Link Binary With Libraries
## Example
2017-09-30 19:47:14 +03:00
```js
2017-09-30 15:41:17 +03:00
import AppMetrica from 'react-native-appmetrica';
AppMetrica.activateWithApiKey('2dee16d2-1143-4cd3-a904-39ce10ac2755');
2017-09-30 19:47:14 +03:00
AppMetrica.reportEvent('Hello world');
2017-09-30 15:41:17 +03:00
```
## Usage
2017-09-30 19:47:14 +03:00
```js
2017-09-30 15:41:17 +03:00
import AppMetrica from 'react-native-appmetrica';
2018-09-12 17:56:09 +03:00
// Start the statistics collection process.
2017-09-30 15:41:17 +03:00
AppMetrica.activateWithApiKey('...KEY...');
2018-08-30 12:13:18 +03:00
// OR
AppMetrica.activateWithConfig({
apiKey: '...KEY...',
sessionTimeout: 120,
firstActivationAsUpdate: true,
});
2017-09-30 15:41:17 +03:00
2018-09-12 17:56:09 +03:00
// Send a custom event message and additional parameters (optional).
2017-09-30 15:41:17 +03:00
AppMetrica.reportEvent('My event');
AppMetrica.reportEvent('My event', { foo: 'bar' });
2017-09-30 17:50:02 +03:00
2017-09-30 19:47:14 +03:00
// Send a custom error event.
2017-09-30 17:50:02 +03:00
AppMetrica.reportError('My error');
2018-09-12 17:56:09 +03:00
// Send user profile with predefined attributes.
AppMetrica.reportUserProfile({ name: 'User 1', age: 87 });
// Send user profile with custom attributes.
AppMetrica.reportUserProfile({
likesMusic: true,
addedToFavorites: '+1',
score: 150,
});
```
### Reporting user profile
All predefined attributes are supported. Use `null` to reset them.
```js
type UserProfileAttributes = {
name?: ?string,
gender?: 'female' | 'male' | string | void,
age?: ?number,
birthDate?: Date | [number] | [number, number] | [number, number, number] | void,
notificationsEnabled?: boolean,
/** custom attributes */
[string]: string | number | boolean,
};
2017-09-30 15:41:17 +03:00
```
2018-09-12 17:56:09 +03:00
Custom attributes are supported. They can't be reset for now.
Use values like `'+1'` , `'-10'` for counters. Current limitation is any custom attribute which value started with `'+'` or `'-'` will be considered as a counter.