capacitor-community / firebase-analytics

Enable Firebase Analytics for Capacitor Apps
MIT License
162 stars 64 forks source link

Firebase CORS on website #54

Open exhaler opened 3 years ago

exhaler commented 3 years ago

Hello,

I'm using this plugin in my ionic capacitor/angular project, everything is setup properly, the firebase analytics is working on iOS and Android. However I keep getting CORS error in my website (screenshot below)

image

my code:

constructor(private appInsightsService: AppInsightsService, private fb: Facebook, private router: Router) {
    this.initFb();
    this.router.events.pipe(filter((e: RouterEvent) => e instanceof NavigationEnd)).subscribe((e: RouterEvent) => {
      this.setScreenName(e.url);
    });
  }

async initFb() {
    if (environment.production) {
      if ((await Device.getInfo()).platform == 'web') {
        FirebaseAnalytics.initializeFirebase(environment.firebaseConfig);
      }
    }
  }

logEvent(name: string) {
    FirebaseAnalytics.logEvent({
      name,
    });
  }

setScreenName(screenName) {
    if (environment.production) {
      FirebaseAnalytics.setScreenName({
        screenName,
      });
    }
  }

Any ideas what i'm missing?

piotr-cz commented 1 year ago

Apparently this has been fixed in firebasejs v9.8.2: https://github.com/firebase/firebase-js-sdk/issues/5020#issuecomment-1148546819

I guess updating the versions here would fix the problem: https://github.com/capacitor-community/firebase-analytics/blob/0e30af2cc8d290eb019162a02e41eb32f7d020f1/src/web.ts#L20-L29