在 chrome 扩展程序中使用 Firebase Analytics

kev*_*iac 5 google-chrome-extension firebase firebase-analytics

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

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

注意: - 我已经从我的 firebase 设置面板激活了 Analytics 集成 - 我已经将配置对象添加到我的 firebase init 中,并使用文档中提到的正确测量 ID。- 我已经导入了 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

Run Code Online (Sandbox Code Playgroud)

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

Run Code Online (Sandbox Code Playgroud)

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

有谁能够帮助我?

非常感谢和快乐编码。

小智 6

Chrome 扩展程序目前不支持 Firebase Analytics。将来检查firebase_environments_sdk文档,以防有任何更改。