Giter Site home page Giter Site logo

kohei-takata / react-native-aws-mobile-analytics Goto Github PK

View Code? Open in Web Editor NEW

This project forked from innfactory/react-native-aws-mobile-analytics

0.0 1.0 0.0 53 KB

A react-native module for using Amazon's AWS Mobile Analytics with the aws-sdk

License: MIT License

JavaScript 100.00%

react-native-aws-mobile-analytics's Introduction

react-native-aws-mobile-analytics

Build Status Version Downloads

A react-native module for using Amazon's AWS Mobile Analytics with the aws-sdk

Highly inspirated by the javascript version aws-sdk-mobile-analytics-js


Usage

Add react-native-aws-mobile-analytics

npm install --save react-native-aws-mobile-analytics

Add Permission for Network State to your AndroidManifest.xml

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Add aws-sdk

npm install --save aws-sdk

react-native-aws-mobile-analytics needs the react-native-device-info package as dependency for an unique client id. Make sure it is correct linked. You may have to call react-native link:

react-native link

Create file MobileAnalytics.js where you can do the configuration:

import AWS from "aws-sdk/dist/aws-sdk-react-native";
import AMA from "react-native-aws-mobile-analytics";
import {
    Platform,
} from 'react-native';

AWS.config.region = 'us-east-1';
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
    region: 'us-east-1',
    IdentityPoolId: 'us-east-1:4c6d17ff-9eb1-4805-914d-8db8536ab130',
});


let appId_PROD = "2e9axxxxxxx742c5a35axxxxxxxxx2f";
let appId_DEV = "xxxx44be23c4xxx9xxxxxxxxxxxxx3fb";

let options = {
    appId: __DEV__?appId_DEV:appId_PROD,
    platform : Platform.OS === 'ios' ? 'iPhoneOS' : 'Android',
    //logger: console // comment in for debugging
};

const MobileAnalyticsClient  = new AMA.Manager(options);
export default MobileAnalyticsClient;

Before you could send the first event you have to call MobileAnalyticsClient.initialize(callback) and wait for the callback. You can handle that in your root component like following:

import React from "react";
import MobileAnalyticsClient from "./MobileAnalytics";
import SomeComponent from "./components/SomeComponent";

export default class App extends React.Component {
    constructor(){
        super();

        this.state = {
            isMobileAnalyticsLoading: true,
        };

        MobileAnalyticsClient.initialize(()=>this.setState({isMobileAnalyticsLoading: false}));
    }
    render() {
        if(this.state.isMobileAnalyticsLoading){
            return null;
        }
        return (
          <SomeComponent/>
        );
    }
};

Now you are able to send event in all your components:

import MobileAnalyticsClient from "../MobileAnalytics";


export default class SomeComponent extends Component {
    constructor() {
        super();
        // send a custom event
        MobileAnalyticsClient.recordEvent('analyticsDemo', { 'attribute_1': 'main', 'attribute_2': 'page' }, { 'metric_1': 1 });
    }
}

Checkout the full example:

react-native-aws-mobile-analytics-demo


Contributors

Anton Spöck

Powered by innFactory

react-native-aws-mobile-analytics's People

Contributors

jveldboom avatar kohei-takata avatar spoeck 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.