Last active
August 28, 2019 13:15
-
-
Save mcousillas6/4e1a3a21aab720126f251dffe00fd3be to your computer and use it in GitHub Desktop.
Simple wrapper to use Amplitude analytics on react native.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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