Giter Site home page Giter Site logo

ilya-uryupov / react-native-appmetrica Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yandexmobile/react-native-appmetrica

0.0 1.0 0.0 13.77 MB

React Native bridge to the AppMetrica on both iOS and Android.

License: MIT License

Java 8.31% JavaScript 8.28% Python 2.82% Objective-C 78.35% C 2.25%

react-native-appmetrica's Introduction

Build Status NPM version

react-native-appmetrica

React Native bridge to the AppMetrica on both iOS and Android.

Installation

  1. Only for iOS: setup AppMetrica. 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

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

Android Manual Linking

MainApplication.java

import android.app.Application;

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.soloader.SoLoader;

+import com.yandex.metrica.YandexMetrica;
+import com.doochik.RNAppMetrica.AppMetricaPackage;

public class MainApplication extends Application implements ReactApplication {

+   private static final String YandexAppMetricaApiKey = "YOUR_API_KEY";

    @Override
    public void onCreate() {
        super.onCreate();

+       // Initializing the AppMetrica SDK
+       YandexMetrica.activate(getApplicationContext(), YandexAppMetricaApiKey);
+   
+       // Tracking user activity
+       YandexMetrica.enableActivityAutoTracking(this);
    
        SoLoader.init(this, /* native exopackage */ false);
    }

    ...
+       // This method is inside ReactNativeHost 
        @Override
        protected List<ReactPackage> getPackages() {
            return Arrays.<ReactPackage>asList(
                            new MainReactPackage(),
+                           new AppMetricaPackage()
            );
        }
    ...
}

build.gradle

dependencies {
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"  // From node_modules
+   compile project(':react-native-appmetrica')
}

settings.gradle

rootProject.name = 'project_name'

+include ':react-native-appmetrica'
+project(':react-native-appmetrica').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-appmetrica/android')

include ':app'

Example

import AppMetrica from 'react-native-appmetrica';

AppMetrica.activateWithApiKey('2dee16d2-1143-4cd3-a904-39ce10ac2755');

AppMetrica.reportEvent('Hello world');

Usage

import AppMetrica from 'react-native-appmetrica';

// Starts the statistics collection process.
AppMetrica.activateWithApiKey('...KEY...');

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

react-native-appmetrica's People

Contributors

doochik avatar lex111 avatar merryejik avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.