Flutter web Firebase analytics TypeError: dart.global.firebase.analytics is not a function

Viewed 2057

I am trying to use firebase analytics in flutter web and getting the following error:

TypeError: dart.global.firebase.analytics is not a function
at Object.analytics$ [as analytics] (http://localhost:5000/packages/firebase/src/top_level.dart.lib.js:110:102)
at new firebase_analytics_web.FirebaseAnalyticsWeb.new (http://localhost:5000/packages/firebase_analytics_web/firebase_analytics_web.dart.lib.js:56:64)
at Function.registerWith 

index.html file script part is as following :

<body>
    <script src="https://www.gstatic.com/firebasejs/7.14.3/firebase-app.js"></script>
    <script src="https://www.gstatic.com/firebasejs/7.14.3/firebase-analytics.js"></script>
    <script src="https://www.gstatic.com/firebasejs/7.14.3/firebase-auth.js"></script>
    
    <script>
      var firebaseConfig = {
        apiKey: "*",
        authDomain: "*",
        databaseURL: "*",
        projectId: "*",
        storageBucket: "*",
        messagingSenderId: "*",
        appId: "*",
        measurementId: "*"
      };
    
      
      firebase.initializeApp(firebaseConfig);
      firebase.analytics();
    </script>
    <script src="main.dart.js" type="application/javascript"></script>

  </body>

pubspec :

firebase_analytics: ^5.0.16

flutter version is 1.20.0 beta

3 Answers

The problem was with my browser. I am using brave browser it was blocking google analytics script. that's why i was facing this error.

Update these two packages to the most recent version

firebase_core
firebase_analytics
Related