Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/innfactory/react-native-aws-mobile-analytics
A react-native module for using Amazon's AWS Mobile Analytics with the aws-sdk
https://github.com/innfactory/react-native-aws-mobile-analytics
amazon analytics aws deprecated mobile-analytics react-native
Last synced: about 1 month ago
JSON representation
A react-native module for using Amazon's AWS Mobile Analytics with the aws-sdk
- Host: GitHub
- URL: https://github.com/innfactory/react-native-aws-mobile-analytics
- Owner: innFactory
- License: mit
- Created: 2017-06-16T10:40:37.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-06-23T06:07:25.000Z (over 6 years ago)
- Last Synced: 2024-08-09T06:39:01.081Z (5 months ago)
- Topics: amazon, analytics, aws, deprecated, mobile-analytics, react-native
- Language: JavaScript
- Size: 52.7 KB
- Stars: 16
- Watchers: 5
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# react-native-aws-mobile-analytics
[![Build Status](https://travis-ci.org/innFactory/react-native-aws-mobile-analytics.svg?branch=master)](https://www.npmjs.com/package/react-native-aws-mobile-analytics)
[![Version](https://img.shields.io/npm/v/react-native-aws-mobile-analytics.svg)](https://www.npmjs.com/package/react-native-aws-mobile-analytics)
[![Downloads](https://img.shields.io/npm/dt/react-native-aws-mobile-analytics.svg)](https://www.npmjs.com/package/react-native-aws-mobile-analytics)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](https://github.com/aws/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`
``````
Add aws-sdk
```
npm install --save aws-sdk
```react-native-aws-mobile-analytics needs the [react-native-device-info](https://github.com/rebeccahughes/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:
```javascript
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:
```javascript
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 (
);
}
};
```
Now you are able to send event in all your components:
```javascript
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](https://github.com/innFactory/react-native-aws-mobile-analytics-demo)
## Contributors
[Anton Spöck](https://github.com/spoeck)
Powered by [innFactory](https://innfactory.de/)