Skip to content

Instantly share code, notes, and snippets.

@mcousillas6
Last active August 28, 2019 13:15
Show Gist options
  • Save mcousillas6/4e1a3a21aab720126f251dffe00fd3be to your computer and use it in GitHub Desktop.
Save mcousillas6/4e1a3a21aab720126f251dffe00fd3be to your computer and use it in GitHub Desktop.
Simple wrapper to use Amplitude analytics on react native.
// AnalyticsTracker.js
import Config from 'react-native-config';
import amplitude from 'amplitude-js';
class AnalyticsService {
constructor(apiKey) {
amplitude.getInstance().init(apiKey, null, {
useNativeDeviceInfo: true,
});
}
setUser = ({ firstName, lastName, email }) => {
amplitude.getInstance().setUserId(email);
amplitude.getInstance().setUserProperties({ firstName, lastName });
};
clearUser = () => {
amplitude.getInstance().setUserId(null);
amplitude.getInstance().regenerateDeviceId();
};
logEvent = (event, info) => {
amplitude.getInstance().logEvent(event, info);
};
}
export default new AnalyticsService(Config.AMPLITUDE_API_KEY);
// AnalyticsEvents.js
export default {
LOGIN: 'LOGIN',
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment