philmerrell / capacitor-firebase-analytics

Capacitor plugin that integrates Firebase Analytics for Android and iOS
17 stars 22 forks source link

Importing the plugin #3

Open LakshanKarunathilake opened 5 years ago

LakshanKarunathilake commented 5 years ago

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?

ryan29871 commented 5 years ago

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

}`

jordanmarshall12 commented 5 years ago

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

ryan29871 commented 5 years ago

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()
    }
}
jordanmarshall12 commented 5 years ago

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