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
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:
;;; AWSconfigregion = 'us-east-1';AWSconfigcredentials = 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 : PlatformOS === 'ios' ? 'iPhoneOS' : 'Android' //logger: console // comment in for debugging; const MobileAnalyticsClient = options;;
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:
;;; Component { super; thisstate = isMobileAnalyticsLoading: true ; MobileAnalyticsClient; } { ifthisstateisMobileAnalyticsLoading return null; return <SomeComponent/> ; };
Now you are able to send event in all your components:
; { super; // send a custom event MobileAnalyticsClient; }
Checkout the full example:
react-native-aws-mobile-analytics-demo
Contributors
Powered by innFactory