Comments (2)
All you need to do is init amplitude once, and then just log events whenever you want to, it's a singleton, you don't need to initialise it more than once.
from react-native-amplitude-analytics.
Btw here's our production implementation:
import RNAmplitute from 'react-native-amplitude-analytics';
import {
AMPLITUDE_KEY,
} from '~/config/config';
const EVENT_PREFIX = 'M_';
class Analytics {
private instance?:RNAmplitute;
create = () => {
if (this.instance == null) {
const amplitude = new RNAmplitute(AMPLITUDE_KEY, true, EVENT_PREFIX);
this.instance = amplitude;
}
return this.instance;
}
logEvent = (name: string, properties?: Record<string, any>) => {
if (name) {
this.instance?.logEvent(name, properties);
}
}
setUserId = (userID: string | number | null) => {
if (userID) {
this.instance?.setUserId(userID);
}
}
setUserProperties = (properties: Record<string, any>) => {
if (properties) {
this.instance?.setUserProperties(properties);
}
}
}
const analyticsInstance = new Analytics();
analyticsInstance.create();
export default analyticsInstance;
and then we log an event by doing:
Analytics.logEvent('HELLO_WORLD');
from react-native-amplitude-analytics.
Related Issues (20)
- 'Amplitude.h' file not found HOT 11
- NPM install / setUserPropertyOnce is not a function HOT 2
- hard coded buildToolsVersion causing warning after upgrading to RN 0.57 HOT 1
- Updating Amplitude SDK to 4.3.1 ? HOT 2
- convertArrayToJson is missing on Android HOT 4
- Add append and prepend methods HOT 4
- Trouble building the app HOT 11
- Ошибка сборки кастомного presenter HOT 3
- TypeScript typings HOT 1
- [iOS] Not finding Amplitude-iOS SDK when building with manual SDK HOT 9
- Doubt about pod install in iOS HOT 3
- Question: how to use amplitude in different places HOT 1
- [Android] com.amplitude.api.AmplitudeClient: Invalid API key, make sure your API key is correct in initialize() HOT 3
- 0.60.x problems on Android HOT 2
- [Question]: How do I disable IDFA HOT 6
- Add setSessionId method HOT 3
- Support TrackLocation HOT 1
- Raw SQL queries used for SQLLite database HOT 1
- Deprecate this repository in favor of @amplitude/react-native
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-amplitude-analytics.