import { NativeModules } from 'react-native' ; import { Constants } from './constants' ; import { Identify } from './identify' ; import { AmplitudeReactNativeModule } from './types' ; const AmplitudeReactNative = NativeModules . AmplitudeReactNative ; export { Identify } ; export class Amplitude { private static _instances : Record < string , Amplitude > ; private static _defaultInstanceName = '$default_instance' ; instanceName : string ; private constructor ( instanceName ) { this . instanceName = instanceName ; this . _setLibraryName ( Constants . packageSourceName ) ; this . _setLibraryVersion ( Constants . packageVersion ) ; } static getInstance ( instanceName = this . _defaultInstanceName ) { if ( ! this . _instances ) { this . _instances = { } ; } if ( ! Object . prototype . hasOwnProperty . call ( this . _instances , instanceName ) ) { this . _instances [ instanceName ] = new Amplitude ( instanceName ) ; } return this . _instances [ instanceName ] ; } init ( apiKey ) { return AmplitudeReactNative . initialize ( this . instanceName , apiKey ) ; } param eventType logEvent ( eventType , eventProperties ? ) { if ( eventProperties && Object . keys ( eventProperties ) . length > 0 ) { return AmplitudeReactNative . logEventWithProperties ( this . instanceName , eventType , eventProperties ) ; } return AmplitudeReactNative . logEvent ( this . instanceName , eventType ) ; } /**
     * Enable COPPA (Children's Online Privacy Protection Act) restrictions on
     * IDFA, IDFV, city, IP address and location tracking.
     *
     * This can be used by any customer that does not want to collect IDFA, IDFV,
     * city, IP address and location tracking.
     */ enableCoppaControl ( ) { return AmplitudeReactNative . enableCoppaControl ( this . instanceName ) ; } /**
     * Disable COPPA (Children's Online Privacy Protection Act) restrictions on
     * IDFA, IDFV, city, IP address and location tracking.
     */ disableCoppaControl ( ) { return AmplitudeReactNative . disableCoppaControl ( this . instanceName ) ; } /**
     * Regenerate the DeviceId
     */ regenerateDeviceId ( ) { return AmplitudeReactNative . regenerateDeviceId ( this . instanceName ) ; } param deviceId setDeviceId ( deviceId ) { return AmplitudeReactNative . setDeviceId ( this . instanceName , deviceId ) ; } returns getDeviceId ( ) { return AmplitudeReactNative . getDeviceId ( this . instanceName ) ; } /**
     * Use the Advertising ID on Android if available from Google Play Services.
     * Must be called before init.
     */ setAdvertisingIdForDeviceId ( ) { return AmplitudeReactNative . setAdvertisingIdForDeviceId ( this . instanceName ) ; } /**
     * Use the App Set ID (fall back to this if `useAdvertisingIdForDeviceId` is used) for device ID.
     * Must be called before init.
     */ setAppSetIdForDeviceId ( ) { return AmplitudeReactNative . setAppSetIdForDeviceId ( this . instanceName ) ; } param optOut setOptOut ( optOut ) { return AmplitudeReactNative . setOptOut ( this . instanceName , optOut ) ; } param trackSessionEvents trackingSessionEvents ( trackSessionEvents ) { return AmplitudeReactNative . trackingSessionEvents ( this . instanceName , trackSessionEvents ) ; } param userId setUserId ( userId ) { return AmplitudeReactNative . setUserId ( this . instanceName , userId ) ; } param serverUrl setServerUrl ( serverUrl ) { return AmplitudeReactNative . setServerUrl ( this . instanceName , serverUrl ) ; } param useDynamicConfig setUseDynamicConfig ( useDynamicConfig ) { return AmplitudeReactNative . setUseDynamicConfig ( this . instanceName , useDynamicConfig ) ; } param userProperties logRevenue ( userProperties ) { return AmplitudeReactNative . logRevenueV2 ( this . instanceName , userProperties ) ; } param identifyInstance identify ( identifyInstance ) { return AmplitudeReactNative . identify ( this . instanceName , identifyInstance . payload ) ; } param groupType param groupName setGroup ( groupType , groupName ) { return AmplitudeReactNative . setGroup ( this . instanceName , groupType , groupName ) ; } param groupType param groupName param identifyInstance groupIdentify ( groupType , groupName , identifyInstance ) { return AmplitudeReactNative . groupIdentify ( this . instanceName , groupType , groupName , identifyInstance . payload ) ; } param userProperties setUserProperties ( userProperties ) { return AmplitudeReactNative . setUserProperties ( this . instanceName , userProperties ) ; } /**
     * Clears all properties that are tracked on the user level.
     *
     * Note: This operation is irreversible!!
     */ clearUserProperties ( ) { return AmplitudeReactNative . clearUserProperties ( this . instanceName ) ; } /**
     * Upload all unsent events.
     */ uploadEvents ( ) { return AmplitudeReactNative . uploadEvents ( this . instanceName ) ; } returns getSessionId ( ) { return AmplitudeReactNative . getSessionId ( this . instanceName ) ; } param minTimeBetweenSessionsMillis setMinTimeBetweenSessionsMillis ( minTimeBetweenSessionsMillis ) { return AmplitudeReactNative . setMinTimeBetweenSessionsMillis ( this . instanceName , minTimeBetweenSessionsMillis ) ; } param serverZone param updateServerUrl setServerZone ( serverZone , updateServerUrl = true ) { return AmplitudeReactNative . setServerZone ( this . instanceName , serverZone , updateServerUrl ) ; } param eventUploadMaxBatchSize setEventUploadMaxBatchSize ( eventUploadMaxBatchSize ) { return AmplitudeReactNative . setEventUploadMaxBatchSize ( this . instanceName , eventUploadMaxBatchSize ) ; } param eventUploadPeriodMillis setEventUploadPeriodMillis ( eventUploadPeriodMillis ) { return AmplitudeReactNative . setEventUploadPeriodMillis ( this . instanceName , eventUploadPeriodMillis ) ; } param eventUploadThreshold setEventUploadThreshold ( eventUploadThreshold ) { return AmplitudeReactNative . setEventUploadThreshold ( this . instanceName , eventUploadThreshold ) ; } private _setLibraryName ( libraryName ) { return AmplitudeReactNative . setLibraryName ( this . instanceName , libraryName ) ; } private _setLibraryVersion ( libraryVersion ) { return AmplitudeReactNative . setLibraryVersion ( this . instanceName , libraryVersion ) ; } }