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.

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 using the npm package manager:

    npm install react-native-appmetrica --save
    
    If you use yarn

    Install the AppMetrica React Native plugin in your project using the yarn package manager:

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

    react-native link react-native-appmetrica
    
  3. For iOS projects:

    • If the project has the ${PROJECT_DIR}/ios/Podfile file, run the following console command:
    npx pod-install
    

    Note

    The framework should be located in the ${PROJECT_DIR}/ios/Frameworks folder.

  4. Rebuild your app:

    # Android:
    npx react-native run-android
    # iOS:
    npx react-native run-ios
    

Step 2. Initialize the AppMetrica library

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

    import AppMetrica from 'react-native-appmetrica';
    

    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,
    firstActivationAsUpdate: false
    });
    
    What is an API key?

    The API key is a unique app ID that is issued in the AppMetrica web interface during app registration.

    Make sure you have entered it correctly.

  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.

See also

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
Previous