Installation and initialization

AppMetrica React Native is a plugin for the React Native platform. It includes the AppMetrica SDK support for Android and iOS.

The minimum supported version of React Native is 0.59.

The plugin accesses native Android/iOS libraries, so to use it with Expo, you need to follow the instructions for libraries that integrate with native components.

This section describes the steps to enable and initialize AppMetrica React Native:

Step 1. Integrate the AppMetrica React Native plugin

  1. Install the AppMetrica React Native plugin in your project:

    yarn add @appmetrica/react-native-analytics
    
    npm install @appmetrica/react-native-analytics
    
  2. For React Native version 0.59 and below, run the following console command to link AppMetrica to your project:

    react-native link @appmetrica/react-native-analytics
    
  3. If you're working on an iOS project, execute this command in the console:

    npx pod-install
    
  4. Rebuild your app:

    # Android:
    npx react-native run-android
    # iOS:
    npx react-native run-ios
    
  1. The plugin uses native Android and iOS libraries. To use native code, create a development build. Learn more.

    npx expo install expo-dev-client
    
  2. Install the AppMetrica React Native plugin in your project:

    npx expo install @appmetrica/react-native-analytics
    
  3. Rebuild your app:

    # Android:
    npx expo run:android
    # iOS:
    npx expo run:ios
    

Step 2. Initialize the AppMetrica library

  1. Import the library in the source code of your project:

    import AppMetrica from '@appmetrica/react-native-analytics';
    

    In this case, use AppMetrica in the source code for working with the library.

  2. Initialize the AppMetrica library using the activate() method:

    AppMetrica.activate({
      apiKey: 'Your API key',
      sessionTimeout: 120,
      logs: true
    });
    
    What is an API key?

    The API key is a unique app ID issued in the AppMetrica web interface at app registration. You can find it under Settings.

  3. Send an event to test the library:

    // 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')
    

Example of a project with the integrated AppMetrica SDK on GitHub.

Learn more

If you didn't find the answer you were looking for, you can use the feedback form to submit your question. Please describe the problem in as much detail as possible. Attach a screenshot if possible.

Contact support