Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds React Native Amplitude with Expo target #172

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -97,6 +97,7 @@ events off to a target. Read more about offline event collection in the
- [Amplitude](https://rangle.github.io/redux-beacon/docs/targets/amplitude.html)
- [_(React Native)_ Google Analytics](https://rangle.github.io/redux-beacon/docs/targets/react-native-google-analytics.html)
- [_(React Native)_ Google Tag Manager](https://rangle.github.io/redux-beacon/docs/targets/react-native-google-tag-manager.html)
- [_(React Native)_ Amplitude with Expo](https://rangle.github.io/redux-beacon/docs/targets/react-native-amplitude-expo.html)
- [_(Cordova)_ Google Analytics](https://rangle.github.io/redux-beacon/docs/targets/cordova-google-analytics.html)

## Docs
Expand Down
1 change: 1 addition & 0 deletions docs/SUMMARY.md
Expand Up @@ -15,6 +15,7 @@
* [Amplitude](docs/targets/amplitude.md)
* [(React Native) Google Analytics](docs/targets/react-native-google-analytics.md)
* [(React Native) Google Tag Manager](docs/targets/react-native-google-tag-manager.md)
* [(React Native) Amplitude with Expo](docs/targets/react-native-amplitude-expo.md)
* [(Cordova) Google Analytics](docs/targets/cordova-google-analytics.md)
* [Extensions](docs/extensions/index.md)
* [logger](docs/extensions/logger.md)
Expand Down
20 changes: 20 additions & 0 deletions docs/targets/react-native-amplitude-expo.md
@@ -0,0 +1,20 @@
# React Native Amplitude with Expo

### Usage Instructions

1. Sign up for Amplitude if you haven't already, and
[create a new project](https://amplitude.zendesk.com/hc/en-us/articles/207108137-Introduction-Getting-Started).

2. Take note of your [Amplitude API key](https://amplitude.zendesk.com/hc/en-us/articles/207108137-Introduction-Getting-Started#getting-started).

3. Create a new [Expo](https://expo.io/learn) project, or [use ExpoKit](https://docs.expo.io/versions/latest/guides/expokit.html) in your project.

4. Import the target, then provide it when creating the middleware:

```js
import { Amplitude } from 'expo';
import { AmplitudeExpo } from 'redux-beacon/targets/react-native';

const target = AmplitudeExpo('YOUR_API_KEY', AmplitudeExpo);
const analyticsMiddleware = createMiddleware(eventsMap, target);
```
12 changes: 12 additions & 0 deletions src/targets/react-native/amplitude-expo/amplitude-expo.js
@@ -0,0 +1,12 @@
export function AmplitudeExpo(apiKey, Amplitude) {
Amplitude.initialize(apiKey);
return function AmplitudeExpoTarget(events) {
events.forEach(targetEvent => {
const properties = Object.keys(targetEvent)
.filter(key => key !== 'event')
.reduce((result, key) => (result[key] = obj[key], result), {});

Amplitude.logEventWithProperties(targetEvent.event, properties);
});
};
}
1 change: 1 addition & 0 deletions src/targets/react-native/amplitude-expo/index.js
@@ -0,0 +1 @@
export { AmplitudeExpo } from './amplitude-expo';
1 change: 1 addition & 0 deletions src/targets/react-native/index.d.ts
@@ -1,2 +1,3 @@
export function GoogleAnalytics(trackingId: string, GABridge: any): void;
export function GoogleTagManager(trackingId: string, GTMBridge: any): void;
export function AmplitudeExpo(apiKey: string, Amplitude: any): void;
2 changes: 2 additions & 0 deletions src/targets/react-native/index.js
@@ -1,7 +1,9 @@
const { GoogleAnalytics } = require('./google-analytics');
const { GoogleTagManager } = require('./google-tag-manager');
const { AmplitudeExpo } = require('./amplitude-expo');

module.exports = {
GoogleAnalytics,
GoogleTagManager,
AmplitudeExpo,
};