Skip to content
This repository has been archived by the owner on Sep 7, 2022. It is now read-only.

Can't get Analytics to work #312

Open
jlubeck opened this issue Apr 3, 2020 · 1 comment
Open

Can't get Analytics to work #312

jlubeck opened this issue Apr 3, 2020 · 1 comment

Comments

@jlubeck
Copy link

jlubeck commented Apr 3, 2020

I added this to my index.html

  <script src="https://www.gstatic.com/firebasejs/7.13.1/firebase-app.js"></script>
  <script src="https://www.gstatic.com/firebasejs/7.13.1/firebase-analytics.js"></script>
  <script>
  // Your web app's Firebase configuration
  var firebaseConfig = {
    apiKey: "XXX",
    authDomain: "XXX.firebaseapp.com",
    databaseURL: "https://XXX.firebaseio.com",
    projectId: "XXX",
    storageBucket: "XXX.appspot.com",
    messagingSenderId: "XXX",
    appId: "XXX",
    measurementId: "G-XXX"
  };
  // Initialize Firebase
  firebase.initializeApp(firebaseConfig);
  firebase.analytics();
  </script>

I then create a class like this one:

import 'package:firebase/firebase.dart' as FB;
import 'dart:js' as js;

class Firebase {
  static void sendPageView(String screenName) {
    print('try to send page');
    final FB.Analytics analytics =
        js.context.hasProperty('firebase') ? FB.analytics() : null;
    if (analytics != null) {
      analytics.setCurrentScreen(screenName);
      print(screenName);
    }
  }
}

When I then run the web app, I see in the console both the 'try to send page' and the screenName at the end. But on my Firebase console I'm not seeing any screen views coming in.

Also on the Chrome console, i only see an initial page_view event going out (I believe it's the automatic page view that gets sent when initializing analytics) but no more events after that one, even though I still see the logs showing the new screen names.

Is there something else that needs to be done?

Thank you!

@steebchen
Copy link

I can confirm this is still an issue today for flutter web. It seems it just forwards the setScreenName to JS, so I couldn't figure out why this does not work yet :/

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants