Amplitude plugin for capacitor
npm install capacitor-amplitudeCurrently only works on ios, but android support will be coming soon
- getInstance(instanceName: string): Amplitude - Retrieve an instance of the Amplitude class.
- init(apiKey: string): Promise - Initialize the Amplitude instance with a given API key.
- logEvent(eventType: string, eventProperties?: Record - Log an event with the given type and optional properties.
- enableCoppaControl(): Promise - Enable COPPA (Children's Online Privacy Protection Act) restrictions.
- disableCoppaControl(): Promise - Disable COPPA restrictions.
- regenerateDeviceId(): Promise - Generate a new DeviceId.
- setDeviceId(deviceId: string): Promise - Manually set the DeviceId.
- getDeviceId(): Promise - Retrieve the current DeviceId.
- useAdvertisingIdForDeviceId(): Promise - Use the Advertising ID for the DeviceId.
- setOptOut(optOut: boolean): Promise - Enable or disable tracking opt-out.
- trackingSessionEvents(trackingSessionEvents: boolean): Promise - Enable or disable the automatic logging of session start and end events.
- setUserId(userId: string | null): Promise - Set the UserId.
- setServerUrl(serverUrl: string): Promise - Set the server URL for event uploads.
- setUseDynamicConfig(useDynamicConfig: boolean): Promise - Enable or disable dynamic server URL configuration.
- logRevenue(userProperties: {...}): Promise - Log revenue data with provided properties.
- identify(identifyInstance: Identify): Promise - Send user property operations to the Amplitude servers.
- setGroup(groupType: string, groupName: string | string[]): Promise - Add a user to a group or groups.
- groupIdentify(groupType: string, groupName: string | string[], identifyInstance: Identify): Promise - Update properties of particular groups.
- setUserProperties(userProperties: Record - Set properties that are tracked at the user level.
- clearUserProperties(): Promise - Clear all properties that are tracked at the user level.
- uploadEvents(): Promise - Upload all unsent events to the server.
- getSessionId(): Promise - Retrieve the current session ID.
- setMinTimeBetweenSessionsMillis(minTimeBetweenSessionsMillis: number): Promise - Set the minimum time between sessions.
- setServerZone(serverZone: string, updateServerUrl: boolean = true): Promise - Set the server zone and optionally update the server URL.
- setEventUploadMaxBatchSize(eventUploadMaxBatchSize: number): Promise - Set the maximum number of events sent per upload request.
- setEventUploadPeriodMillis(eventUploadPeriodMillis: number): Promise - Sets the period in milliseconds for batch uploading unsent events.
- setEventUploadThreshold(eventUploadThreshold: number): Promise - Sets the threshold number of unsent events that will trigger a batch upload.
- setPlan(plan: Plan): Promise - Sets the tracking plan information.
- setIngestionMetadata(ingestionMetadata: IngestionMetadata): Promise - Sets the ingestion metadata information.
1. In your module (e.g. app.module.ts)
``ts
...
import { Amplitude } from 'capacitor-amplitude'
@NgModule({
...
providers: [
...
{ provide: Amplitude, useFactory: () => Amplitude.getInstance() },
],
})
export class AppModule {}
`
2. In your component or service (e.g. analytics.service.ts)
`ts
...
import { Amplitude } from 'capacitor-amplitude'
@Injectable()
export class AnalyticsService {
constructor(private amplitude: Amplitude) {}
async init() {
await this.amplitude.init('AMPLITUDE_API_KEY')
}
async logEvent(name: string, params?: Object) {
await this.amplitude.logEvent(name, params)
}
async setUserId(id: string) {
return this.amplitude.setUserId(id)
}
async getDeviceID(): string {
return this.amplitude.getDeviceId()
}
async uploadEvents() {
return this.amplitude.uploadEvents()
}
}
``
- Added support for Capacitor 5
- Added full support for Capacitor 3 and removed compatibility with Capacitor 2