check for analytics enabled

This commit is contained in:
Elias Nahum 2023-01-09 11:13:11 +02:00
parent 69e27ae812
commit 252dc1e3c8
No known key found for this signature in database
GPG key ID: A2EB45B81EA1AB32

View file

@ -28,7 +28,9 @@ export class Analytics {
};
async init(config: ClientConfig) {
this.analytics = require('@rudderstack/rudder-sdk-react-native').default;
if (LocalConfig.RudderApiKey) {
this.analytics = require('@rudderstack/rudder-sdk-react-native').default;
}
if (this.analytics) {
const {height, width} = Dimensions.get('window');
@ -123,10 +125,18 @@ export class Analytics {
}
trackAPI(event: string, props?: any) {
if (!this.analytics) {
return;
}
this.trackEvent('api', event, props);
}
trackCommand(event: string, command: string, errorMessage?: string) {
if (!this.analytics) {
return;
}
const sanitizedCommand = this.sanitizeCommand(command);
let props: any;
if (errorMessage) {
@ -139,6 +149,9 @@ export class Analytics {
}
trackAction(event: string, props?: any) {
if (!this.analytics) {
return;
}
this.trackEvent('action', event, props);
}