capacitor-firebase-analytics
capacitor-firebase-analytics copied to clipboard
Importing the plugin
Hey, I have setup the plugin as you have mentioned in your documentation. The firebase dashboard says I am connected but the issue is how to log events and what is the import call for the Firebase analytics is that a module or service.
Can someone help?
`import { Injectable } from '@angular/core';
import { Platform } from '@ionic/angular';
import { Plugins, DeviceInfo } from '@capacitor/core';
import { CapacitorFirebaseAnalytics } from 'capacitor-firebase-analytics';
const { CapacitorFirebaseAnalytics } = Plugins;
@Injectable({ providedIn: 'root' }) export class AnalyticsService {
constructor( private platform: Platform ) { }
async logEvent(event: string, userInfo: firebase.User, deviceInfo: DeviceInfo) { try { console.log('Log Event Start'); console.log(event); console.log(userInfo); console.log(deviceInfo); await this.platform.ready(); if (this.platform.is('cordova')) { CapacitorFirebaseAnalytics.logEvent({ name: event, parameters: { Email: userInfo.email, Device: deviceInfo.model } }); console.log('Log Event End'); } } catch (error) { console.error(error); } }
}`
import { CapacitorFirebaseAnalytics } from 'capacitor-firebase-analytics'; const { CapacitorFirebaseAnalytics } = Plugins;
when I try and do this I get an error: Identifier 'CapacitorFirebaseAnalytics' has already been declared
Try modifying Plugin.swift in the node module folder for capacitor-firebase-analytics. The file is located in ios/plugin/plugin. This is a temporary fix.
var fbase: FirebaseApp? = nil;
public override func load() {
if (FirebaseApp.app() == nil) {
FirebaseApp.configure();
fbase = FirebaseApp.app()
}
}
Thanks - I've modified the Plugin.swift file. I'm using @ionic/vue and it still doesn't like the whole javascript destructuring part with the dual CapacitorFirebaseAnalytics names with the import