Firebase analytics problem in JS
Hello I am unable to send lo event in my html and js website.
My code
<html>
<head>
<title>Test</title>
</head>
<body>
<script type="module">
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.15.0/firebase-app.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.15.0/firebase-analytics.js";
const firebaseConfig = {
apiKey: "my data",
authDomain: "my data",
databaseURL: "my data",
projectId: "my data",
storageBucket: "my data",
messagingSenderId: "my data",
appId: "my data",
measurementId: "my data"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
analytics.logEvent('test_event', { name: 'hiii'});
</script>
</body>
</html>
Error
Uncaught TypeError: analytics.logEvent is not a function
at event.php:25:12
So now how can i solve it?
Maybe i am missing something..
2
Answers
You may check and initialize Firebase Analytics like this:
Since you are using the modular implementation, you should import
logEvent
from the analytics moduleand send the analytics instance as the first parameter LogEvent