Capacitor Appmetrica plugin
Currently only works on ios, but android support will be coming soon
Available methods:
- logEvent
- setUserProfileID
- reportUserProfile
- getDeviceID
Usage example:
- Add in
capacitor.config.json
{
"plugins": {
"Appmetrica": {
"apiKey": "Your API key"
}
}
- In your module (e.g.
app.module.ts
)
...
import { Appmetrica } from 'capacitor-appmetrica'
@NgModule({
...
providers: [
...
Appmetrica,
],
})
export class AppModule {}
- In your component or service (e.g.
analytics.service.ts
)
...
import { Appmetrica, UserProfile, ProfileAttribute } from 'capacitor-appmetrica'
@Injectable()
export class AnalyticsService {
constructor(private appmetrica: Appmetrica) {}
async logEvent(name: string, params?: Object) {
await this.appmetrica.logEvent(name, params)
}
async setUserProfileID(id: string) {
return this.appmetrica.setUserProfileID(id)
}
async reportUserProfile() {
const userProfile = new UserProfile()
userProfile.applyFromArray([
ProfileAttribute.Name().withValue('Ivan'),
ProfileAttribute.BirthDate().withBirthDate(new Date()),
ProfileAttribute.CustomString('born_in').withValueIfUndefined('Moscow'),
])
await this.appmetrica.reportUserProfile(userProfile)
}
async getDeviceID(): string {
return this.appmetrica.getDeviceID()
}
}