在 chrome 扩展中使用 Firebase Analytics

Using Firebase Analytics inside a chrome extension

我正在使用 Firebase Firestore 和 Firebase Auth 在 chrome 扩展后台页面中管理数据和用户。这很好用。

但是,我正在尝试在同一后台页面上使用 Firebase Analytics 来记录一些事件,这绝对行不通(即使等了几天)。

注意: - 我已经从我的 firebase 设置面板激活了分析集成 - 我已将配置对象添加到我的 firebase init 中,并使用文档中提到的正确 measurementId。 - 我导入了 firebase/analytics SDK - 如果我 console.log firebase.analytics().logEvent,函数存在。但是,如果我执行以下操作:firebase.analytics().logEvent("blabla"),该事件永远不会出现在我的仪表板上。

这是我的 background.js 文件的一些部分:

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

在我的 manifest.js 文件中,我添加了以下内容安全策略,并且在我的 background.js 日志中没有与此相关的错误。

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/;",

我什至不确定是否可以在 chrome 扩展中使用 firebase 分析。

有人能帮帮我吗?

非常感谢,编码愉快。

Chrome 扩展目前不支持 Firebase Analytics。以后检查 firebase_environments_sdk 文档以防有任何更改。