
火场分析
@capacitor-community/firebase-analytics
本地电容社区插件 火场分析。 。 。 .
QQ 更新到QQv8. 0.0QQ时突破更改
✏️✏️ 这个插件现在只支持 Capacitor 8 。 对于7、6、5和4号电容器,请使用以下所列版本
插件版本
| 电容版本 | 插件版本 |
|---|---|
| 8.x 电话 | 8.x 电话 |
| 7.x 电话 | 7.x 电话 |
| 6.x (单位:千美元) | 6.x (单位:千美元) |
| 5.x 电话 | 第5.0.1条 |
| 4.x (中文(简体) ) | 1.0.1 (中文(简体) ) |
安装
使用 npm :
npm install @capacitor-community/firebase-analytics@latest
使用线条 :
yarn add @capacitor-community/firebase-analytics@latest
同步本地文件 :
# Update the native plugins and dependencies referenced in package.json
npx cap sync
说明: 在iOS上,CocoaPods和Swift包管理器都得到了支持.
npx cap sync配置您的应用程序使用的任意一个 .
说明: 您可能还需要运行 文件 > 与 Gradle 文件同步工程 以便Android Studio识别导入.
配置
此插件不需要配置 .
实例
点击这里 对于如何执行此插件的示例.
您也可以克隆仓库 :
git clone https://github.com/jcesarmobile/capacitor-firebase-analytics-example
支持的方法
| 名称 | 机器人 | iOS系统 | 网页 |
|---|---|---|---|
| 设置用户 | ✅ | ✅ | ✅ |
| 产品 | ✅ | ✅ | ✅ |
| 获取 AppInstanceId | ✅ | ✅ | ❌ |
| 设置ScreenName | ✅ | ✅ | ❌ |
| 重设 | ✅ | ✅ | ❌ |
| 日志事件 | ✅ | ✅ | ✅ |
| 集成已启用 | ✅ | ✅ | ✅ |
| 时长 | ✅ | ✅ | ✅ |
| 启用 | ✅ | ✅ | ✅ |
| 禁用 | ✅ | ✅ | ✅ |
使用量
import { FirebaseAnalytics } from "@capacitor-community/firebase-analytics";
/**
* Platform: Web
* Configure and initialize the firebase app.
* @param options - firebase web app configuration options
* */
FirebaseAnalytics.initializeFirebase({
apiKey: "...",
authDomain: "...",
databaseURL: "...",
projectId: "...",
storageBucket: "...",
messagingSenderId: "...",
appId: "...",
measurementId: "...",
});
/**
* Platform: Web/Android/iOS
* Sets the user ID property.
* @param userId - unique identifier of a user
* @returns void
* https://firebase.google.com/docs/analytics/userid
*/
FirebaseAnalytics.setUserId({
userId: "john_doe_123",
});
/**
* Platform: Web/Android/iOS
* Sets a user property to a given value.
* @param options - property name and value to set
* @returns void
* https://firebase.google.com/docs/analytics/user-properties
*/
FirebaseAnalytics.setUserProperty({
name: "favorite_food",
value: "pizza",
});
/**
* Platform: Android/iOS
* Retrieves the app instance id from the service.
* @param none
* @returns instanceId - individual instance id value
* https://firebase.google.com/docs/analytics/user-properties
*/
FirebaseAnalytics.getAppInstanceId();
/**
* Platform: Android/iOS
* Sets the current screen name, which specifies the current visual context in your app.
* @param screenName - name of the current screen to track
* nameOverride - name of the screen class to override
* @returns instanceId - individual instance id value
* https://firebase.google.com/docs/analytics/screenviews
*/
FirebaseAnalytics.setScreenName({
screenName: "login",
nameOverride: "LoginScreen",
});
/**
* Platform: Web/Android/iOS
* Clears all analytics data for this app from the device and resets the app instance id.
* @param none
* @returns void
*/
FirebaseAnalytics.reset();
/**
* Platform: Web/Android/iOS
* Logs an app event.
* @param name - name of the event to log
* params - key/value pairs of properties (25 maximum per event)
* @returns void
*/
FirebaseAnalytics.logEvent({
name: "select_content",
params: {
content_type: "image",
content_id: "P12453",
items: [{ name: "Kittens" }],
},
});
/**
* Platform: Web/Android/iOS
* Sets whether analytics collection is enabled for this app on this device.
* @param name - enabled - boolean true/false
* @returns void
*/
FirebaseAnalytics.setCollectionEnabled({
enabled: false,
});
/**
* Platform: Web/Android/iOS
* Deprecated - use setCollectionEnabled() instead
* Enable analytics collection for this app on this device.
* @param none
* @returns void
*/
FirebaseAnalytics.enable();
/**
* Platform: Web/Android/iOS
* Deprecated - use setCollectionEnabled() instead
* Disable analytics collection for this app on this device.
* @param none
* @returns void
*/
FirebaseAnalytics.disable();
/**
* Platform: Web/Android/iOS
* Sets the duration of inactivity that terminates the current session.
* @param duration - duration in seconds (default - 18000)
* @returns void
*/
FirebaseAnalytics.setSessionTimeoutDuration({
duration: 10000,
});
设置
导航您在 Firebase 上的应用程序的工程设置页面 .
iOS系统
下载 GoogleService-Info.plist 文档。 在 Xcode 中右键单击名为“ App” 的黄色文件夹,并选择 Add files to "App"。 。 。 .
提示:如果拖放文件到此位置, Xcode 可能找不到它 .
机器人
下载 google-services.json 存档并复制到 android/app/ 您的电容器项目目录 .
变量
此插件将使用以下工程变量( 在您的应用程序中定义) variables.gradle 文件名 :
$firebaseAnalyticsVersion版本com.google.firebase:firebase-analytics(默认 :21.2.2(中文(简体) )
iOS 设置
ionic start my-cap-app --capacitorcd my-cap-appnpm install --save @capacitor-community/firebase-analyticsmkdir www && touch www/index.htmlsudo gem install cocoapods(只有一次,而且只针对以可可Pods为基础的应用)npx cap add iosnpx cap sync ios(每次你跑动)npm install(中文(简体) )npx cap open ios- 在 xcode( 一般标签) 签名您的应用程序
- 添加
GoogleService-Info.plist到 xcode 中的应用程序文件夹
启用调试视图
- 在 Xcode 中,选择产品 > 方案 > 编辑方案
- 从左菜单中选择运行
- 选择参数标签
- 在发射时通过的论点部分,添加
-FIRAnalyticsDebugEnabled
提示:每次您更改本地代码时, 您可能需要清理缓存( Product > Clean building文件夹) , 然后再次运行应用程序 .
机器人设置
ionic start my-cap-app --capacitorcd my-cap-appnpm install --save @capacitor-community/firebase-analyticsmkdir www && touch www/index.htmlnpx cap add androidnpx cap sync android(每次你跑动)npm install(中文(简体) )npx cap open android- 添加
google-services.json给您的android/app文件夹
现在你该走了 尝试使用 ionic cap run android --livereload --address=0.0.0.0。 。 。 .
提示:每次您更改本地代码, 您可能需要清理缓存( Build > Clean Project QQ Build > Rebuilt Project) , 然后再次运行应用程序 .
更新
对于已有的项目, 您可以使用此单项命令升级所有与电容器相关的软件包( 包括此插件)
npx npm-upgrade '*capacitor*' && npm install
移徙
如果你以前使用过 capacitor-analytics npm 软件包
-
更新国家防范机制一揽子计划:
npm uninstall --save capacitor-analytics npm install --save-prod @capacitor-community/firebase-analytics@latest -
更新Android的插件初始化 主要活动. java
删除旧插件导入 :
-import io.stewan.capacitor.analytics.AnalyticsPlugin;更新
init()调用以删除旧插件导入 。 你也许可以把全部都删除init()如果里面没有别的东西就打电话.// Initializes the Bridge this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{ // Additional plugins you've installed go here // Ex: add(TotallyAwesomePlugin.class); - add(AnalyticsPlugin.class); }}); -
公共 API 更改 :
instance()已更名为getAppInstanceId()setScreen()已更名为setScreenName()setUserID()已更名为setUserId()setUserProp()已更名为setUserProperty()enable()已经贬值,有利于setCollectionEnabled()disable()已经贬值,有利于setCollectionEnabled()
进一步信息
贡献者
感谢这些伟大的人emoji 密钥:
克里斯·阿伯内特 🚧 |
普里扬克帕特尔 💻 |
炖肉 💻 |
卡尔姆吉特·辛格 ⚠️ 🐛 |
米歇尔·罗卡 🐛 |
马提亚斯 👀 |
托比语Name 💻 |
尼古拉斯·诺里斯 🐛 |
加布里埃尔斯卡瓦略 🐛 💻 |
普克尼语name 🐛 💻 📖 |
维基百科 🐛 |
卢克西 ⚠️ 🐛 |
阴道 💻 |
卢克西 💻 |
本项目遵循 全部贡献者 规格。 任何捐款都欢迎!