Reputation: 33
I have Javascript file that implements method to share website (event listener):
const shareBtn = document.getElementById('shareBtn');
shareBtn.addEventListener("click", () => {
if (navigator.share) {
navigator
.share({
title: "",
text: "",
url: ""
})
.then()
.catch();
} else {}
});
I added Firebase analytics in another file (code from Firebase). How do I log event to log share event in Firebase? How do I import Firebase analytics in Javascript? How to log events for different methods?
I merged two files in this:
var firebaseConfig = {// };
firebase.initializeApp(firebaseConfig);
const analytics = firebase.analytics();
const shareBtn = document.getElementById('shareBtn');
shareBtn.addEventListener("click", () => {
if (navigator.share) {
navigator
.share({
title: "",
text: "",
url: ""
})
.then()
.catch();
analytics.logEvent('clicked_share');
} else {
}
});
But I don't want to have all my click methods in firebase.js file.
Upvotes: 2
Views: 2717
Reputation: 3800
This documentation shows you how to add Google Analytics for Firebase to your web app and begin logging events. You can also watch this tutorial if you prefer watching videos, rather than reading documentations.
To validate your implementation, you can enable the debug mode in your browser, then install the Google Analytics Debugger Chrome extension. Once installed, enable the extension and refresh the page. From that point on, the extension will log events in your app in debug mode. You can view events logged in the DebugView in the Firebase console.
Upvotes: 2