1

I've updated my project with @capacitor-community/firebase-analytics@5.0.1 and I am having some issues with a few of the methods.

I created a service for tracking the analytics that looks like this:

 analyticsEnabled:boolean = true;

    constructor() { 
        this.init();
    }

    init() {
        if (Capacitor.getPlatform() === 'web') {
            FirebaseAnalytics.initializeFirebase(environment.firebase);
        }
        FirebaseAnalytics.setCollectionEnabled({
            enabled: environment.production
        });
    }

    setUser(userId:string) {
        FirebaseAnalytics.setUserId({
            userId: userId,
        });
    }
    
    setProperty(name:string,value:string) {
        FirebaseAnalytics.setUserProperty({
            name: name,
            value: value,
        });
    }
    
    logEvent(name:string,params:object) {
        FirebaseAnalytics.logEvent({
            name: name,
            params: params
        });
    }
    
    setScreenName(screenName:string) {
        FirebaseAnalytics.setScreenName({
            screenName: screenName,
            nameOverride: screenName
        });
    }
    
    toggleAnalytics() {
        this.analyticsEnabled = !this.analyticsEnabled;
        FirebaseAnalytics.setCollectionEnabled({
            enabled: this.analyticsEnabled,
        });
    }

In my app, I try and setScreenName, but no data ever appears in my Google Analytics or Firebase Analytics reports for the screen name value.

In my various views, I manually set the screen name like:

ionViewDidEnter() {
        this.analytics.setScreenName('Home');
    }

I see these appear in my XCode console:

⚡️  To Native ->  FirebaseAnalytics setUserId 36273285
⚡️  To Native ->  FirebaseAnalytics setScreenName 36273286
⚡️  To Native ->  FirebaseAnalytics setScreenName 36273288
⚡️  To Native ->  FirebaseAnalytics setScreenName 36273289

Any ideas why no data is appearing in my reports?

zeropsi
  • 682
  • 9
  • 24

2 Answers2

1

Maybe this answer will help you https://stackoverflow.com/a/63170187/9566462

It says that:

This is the code to rewrite the deprecated method:

Replace this line:

Analytics.setScreenName(screenName, screenClass: nil)

With this line:

Analytics.logEvent(AnalyticsEventScreenView, parameters: [AnalyticsParameterScreenName: screenName])
Ivan Ivanyuk
  • 318
  • 2
  • 11
1

Since you said that you see those messages in your xCode console I'm assuming you may be in a test environment.

FirebaseAnalytics.setCollectionEnabled({
  enabled: environment.production
});

This chunk of code is preventing data to be collected unless you're in a production environment, you may try commenting it temporarily to test it out.