kevinpiac
kevinpiac

Reputation: 73

Using Firebase Analytics inside a chrome extension

I'm using Firebase Firestore and Firebase Auth to manage data and users in a chrome extension Background page. This works well.

However, I'm trying to use Firebase Analytics on the same background page to log some events and this definitely does not work (even after waiting a few days).

Note: - I've activated the Analytics Integration from my firebase setting pannel - I've added the config object to my firebase init with the right measurementId as mentionned in the doc. - I've imported the firebase/analytics SDK - if I console.log firebase.analytics().logEvent, the function exists. However, if I do something like: firebase.analytics().logEvent("blabla"), the event never appears on my dashboard.

Here are some parts of my background.js file:

import firebase from 'firebase/app';
import "firebase/analytics";
import "firebase/auth";
import "firebase/firestore";

// Your web app's Firebase configuration
var firebaseConfig = {
  apiKey: "AIzaSyAl-5jiGpv_FzYK38mWTZZkspJ1u2UV3bk",
  authDomain: "email-tracker-backend.firebaseapp.com",
  databaseURL: "https://email-tracker-backend.firebaseio.com",
  projectId: "email-tracker-backend",
  storageBucket: "email-tracker-backend.appspot.com",
  messagingSenderId: "83977792643",
  appId: "1:83977792643:web:4aea8f58ecf668e4193fb6",
  measurementId: "G-DL96DBFLB0"
};

  // Initialize Firebase
const app = firebase.initializeApp(firebaseConfig);

const analytics = firebase.analytics();

const firestore = app.firestore();

......

console.log("before log") // print out correctly
analytics.logEvent('something'); // this event never appears
console.log(analytics.logEvent); // print out the function correctly

In my manifest.js file, I've added the following content security policies and I've no error related to that in my background.js logs.

content_security_policy: "script-src 'self' 'unsafe-eval' https://cdn.firebase.com https://*.firebaseio.com https://tagmanager.google.com/ https://www.googletagmanager.com/; object-src 'self'; script-src-elem 'self' 'unsafe-eval' https://apis.google.com https://tagmanager.google.com/ https://www.googletagmanager.com/;",

I'm not even sure if it's possible to use firebase analytics in a chrome extension.

Can anybody help me?

Thanks a lot and happy coding.

Upvotes: 7

Views: 2092

Answers (1)

lemonshark12
lemonshark12

Reputation: 134

Firebase Analytics is not supported in Chrome Extensions at this time. Check firebase_environments_sdk doc in future in case there are any changes.

Upvotes: 7

Related Questions