capacitor-firebase-analytics icon indicating copy to clipboard operation
capacitor-firebase-analytics copied to clipboard

Importing the plugin

Open LakshanKarunathilake opened this issue 5 years ago • 4 comments

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?

LakshanKarunathilake avatar May 10 '19 08:05 LakshanKarunathilake

`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); } }

}`

ryan29871 avatar Jun 06 '19 20:06 ryan29871

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

jordanmarshall12 avatar Jul 20 '19 15:07 jordanmarshall12

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()
    }
}

ryan29871 avatar Jul 20 '19 16:07 ryan29871

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

jordanmarshall12 avatar Jul 21 '19 16:07 jordanmarshall12