Installations
npm install @capacitor-community/firebase-analytics
Developer
capacitor-community
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
Yes
Node Version
20.12.2
NPM Version
10.6.0
Statistics
162 Stars
189 Commits
64 Forks
17 Watching
7 Branches
34 Contributors
Updated on 09 Oct 2024
Languages
Java (39.88%)
TypeScript (31.95%)
Swift (19.63%)
Objective-C (3.7%)
Ruby (3.39%)
JavaScript (1.45%)
Total Downloads
Cumulative downloads
Total Downloads
2,408,547
Last day
5.3%
3,039
Compared to previous day
Last week
4.5%
14,794
Compared to previous week
Last month
6%
61,186
Compared to previous month
Last year
-4.7%
773,622
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
1
Firebase Analytics
@capacitor-community/firebase-analytics
Capacitor community plugin for native Firebase Analytics.
❗❗ Breaking changes when updating to ✏️v6.0.0✏️❗❗
✏️✏️ This plugin now supports Capacitor 6 only. For Capacitor 5 and 4 please use version listed below ✏️✏️
Plugin versions
Capacitor version | Plugin version |
---|---|
6.x | 6.x |
5.x | 5.0.1 |
4.x | 1.0.1 |
Maintainers
Maintainer | GitHub | Social |
---|---|---|
mesur.io | mesur-io | @mesur_io |
Installation
Using npm:
1npm install @capacitor-community/firebase-analytics@latest
Using yarn:
1yarn add @capacitor-community/firebase-analytics@latest
Sync native files:
1# Update the native plugins and dependencies referenced in package.json 2npx cap sync
Note: You may also need to run File > Sync Project with Gradle Files in order for Android Studio to recognize the import.
Configuration
No configuration is required for this plugin.
Examples
Click here for an example on how to implement this plugin.
You can also clone the repository:
1git clone https://github.com/jcesarmobile/capacitor-firebase-analytics-example
Supported methods
Name | Android | iOS | Web |
---|---|---|---|
setUserId | ✅ | ✅ | ✅ |
setUserProperty | ✅ | ✅ | ✅ |
getAppInstanceId | ✅ | ✅ | ❌ |
setScreenName | ✅ | ✅ | ❌ |
reset | ✅ | ✅ | ❌ |
logEvent | ✅ | ✅ | ✅ |
setCollectionEnabled | ✅ | ✅ | ✅ |
setSessionTimeoutDuration | ✅ | ✅ | ✅ |
enable | ✅ | ✅ | ✅ |
disable | ✅ | ✅ | ✅ |
Usage
1import { FirebaseAnalytics } from "@capacitor-community/firebase-analytics"; 2 3/** 4 * Platform: Web 5 * Configure and initialize the firebase app. 6 * @param options - firebase web app configuration options 7 * */ 8FirebaseAnalytics.initializeFirebase({ 9 apiKey: "...", 10 authDomain: "...", 11 databaseURL: "...", 12 projectId: "...", 13 storageBucket: "...", 14 messagingSenderId: "...", 15 appId: "...", 16 measurementId: "...", 17}); 18 19/** 20 * Platform: Web/Android/iOS 21 * Sets the user ID property. 22 * @param userId - unique identifier of a user 23 * @returns void 24 * https://firebase.google.com/docs/analytics/userid 25 */ 26FirebaseAnalytics.setUserId({ 27 userId: "john_doe_123", 28}); 29 30/** 31 * Platform: Web/Android/iOS 32 * Sets a user property to a given value. 33 * @param options - property name and value to set 34 * @returns void 35 * https://firebase.google.com/docs/analytics/user-properties 36 */ 37FirebaseAnalytics.setUserProperty({ 38 name: "favorite_food", 39 value: "pizza", 40}); 41 42/** 43 * Platform: Android/iOS 44 * Retrieves the app instance id from the service. 45 * @param none 46 * @returns instanceId - individual instance id value 47 * https://firebase.google.com/docs/analytics/user-properties 48 */ 49FirebaseAnalytics.getAppInstanceId(); 50 51/** 52 * Platform: Android/iOS 53 * Sets the current screen name, which specifies the current visual context in your app. 54 * @param screenName - name of the current screen to track 55 * nameOverride - name of the screen class to override 56 * @returns instanceId - individual instance id value 57 * https://firebase.google.com/docs/analytics/screenviews 58 */ 59FirebaseAnalytics.setScreenName({ 60 screenName: "login", 61 nameOverride: "LoginScreen", 62}); 63 64/** 65 * Platform: Web/Android/iOS 66 * Clears all analytics data for this app from the device and resets the app instance id. 67 * @param none 68 * @returns void 69 */ 70FirebaseAnalytics.reset(); 71 72/** 73 * Platform: Web/Android/iOS 74 * Logs an app event. 75 * @param name - name of the event to log 76 * params - key/value pairs of properties (25 maximum per event) 77 * @returns void 78 */ 79FirebaseAnalytics.logEvent({ 80 name: "select_content", 81 params: { 82 content_type: "image", 83 content_id: "P12453", 84 items: [{ name: "Kittens" }], 85 }, 86}); 87 88/** 89 * Platform: Web/Android/iOS 90 * Sets whether analytics collection is enabled for this app on this device. 91 * @param name - enabled - boolean true/false 92 * @returns void 93 */ 94FirebaseAnalytics.setCollectionEnabled({ 95 enabled: false, 96}); 97 98/** 99 * Platform: Web/Android/iOS 100 * Deprecated - use setCollectionEnabled() instead 101 * Enable analytics collection for this app on this device. 102 * @param none 103 * @returns void 104 */ 105FirebaseAnalytics.enable(); 106 107/** 108 * Platform: Web/Android/iOS 109 * Deprecated - use setCollectionEnabled() instead 110 * Disable analytics collection for this app on this device. 111 * @param none 112 * @returns void 113 */ 114FirebaseAnalytics.disable(); 115 116/** 117 * Platform: Web/Android/iOS 118 * Sets the duration of inactivity that terminates the current session. 119 * @param duration - duration in seconds (default - 18000) 120 * @returns void 121 */ 122FirebaseAnalytics.setSessionTimeoutDuration({ 123 duration: 10000, 124});
Setup
Navigate to the project settings page for your app on Firebase.
iOS
Download the GoogleService-Info.plist
file. In Xcode right-click on the yellow folder named "App" and select the Add files to "App"
.
Tip: if you drag and drop your file to this location, Xcode may not be able to find it.
Android
Download the google-services.json
file and copy it to android/app/
directory of your capacitor project.
Variables
This plugin will use the following project variables (defined in your app’s variables.gradle
file):
$firebaseAnalyticsVersion
version ofcom.google.firebase:firebase-analytics
(default:21.2.2
)
iOS setup
ionic start my-cap-app --capacitor
cd my-cap-app
npm install --save @capacitor-community/firebase-analytics
mkdir www && touch www/index.html
sudo gem install cocoapods
(only once)npx cap add ios
npx cap sync ios
(every time you runnpm install
)npx cap open ios
- sign your app at xcode (general tab)
- add
GoogleService-Info.plist
to the app folder in xcode
Enable debug view
- In Xcode, select Product > Scheme > Edit scheme
- Select Run from the left menu
- Select the Arguments tab
- In the Arguments Passed On Launch section, add
-FIRAnalyticsDebugEnabled
Tip: every time you change a native code you may need to clean up the cache (Product > Clean build folder) and then run the app again.
Android setup
ionic start my-cap-app --capacitor
cd my-cap-app
npm install --save @capacitor-community/firebase-analytics
mkdir www && touch www/index.html
npx cap add android
npx cap sync android
(every time you runnpm install
)npx cap open android
- add
google-services.json
to yourandroid/app
folder
Now you should be set to go. Try to run your client using ionic cap run android --livereload --address=0.0.0.0
.
Tip: every time you change a native code you may need to clean up the cache (Build > Clean Project | Build > Rebuild Project) and then run the app again.
Updating
For existing projects you can upgrade all capacitor related packages (including this plugin) with this single command
npx npm-upgrade '*capacitor*' && npm install
Migration
If you were previously using the capacitor-analytics
package from npm
-
Update NPM package:
1npm uninstall --save capacitor-analytics 2npm install --save-prod @capacitor-community/firebase-analytics@latest
-
Update the plugin initialization in Android's MainActivity.java
Remove the old plugin import:
1-import io.stewan.capacitor.analytics.AnalyticsPlugin;
Update the
init()
call to remove the old plugin import. You may be able to remove the entireinit()
call if there is nothing else in there.1// Initializes the Bridge 2this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{ 3 // Additional plugins you've installed go here 4 // Ex: add(TotallyAwesomePlugin.class); 5- add(AnalyticsPlugin.class); 6}});
-
Public API changes:
instance()
has been renamed togetAppInstanceId()
setScreen()
has been renamed tosetScreenName()
setUserID()
has been renamed tosetUserId()
setUserProp()
has been renamed tosetUserProperty()
enable()
has been deprecated in favor ofsetCollectionEnabled()
disable()
has been deprecated in favor ofsetCollectionEnabled()
Further info
Contributors ✨
Thanks goes to these wonderful people (emoji key):
Chris Abernethy 🚧 | Priyank Patel 💻 | stewwan 💻 | Karmjit Singh ⚠️ 🐛 | Michel Roca 🐛 | Matthias 👀 | Tobi 💻 |
Nicholas Norris 🐛 | gabrielscarvalho 🐛 💻 | ptmkenny 🐛 💻 📖 | vkyeswa 🐛 | losciur ⚠️ 🐛 | wyattades 💻 | losciur 💻 |
This project follows the all-contributors specification. Contributions of any kind welcome!
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
binaries present in source code
Details
- Warn: binary detected: android/gradle/wrapper/gradle-wrapper.jar:1
Reason
5 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/capacitor-community/firebase-analytics/test.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/capacitor-community/firebase-analytics/test.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:39: update your workflow using https://app.stepsecurity.io/secureworkflow/capacitor-community/firebase-analytics/test.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:41: update your workflow using https://app.stepsecurity.io/secureworkflow/capacitor-community/firebase-analytics/test.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:45: update your workflow using https://app.stepsecurity.io/secureworkflow/capacitor-community/firebase-analytics/test.yml/master?enable=pin
- Info: 0 out of 5 GitHub-owned GitHubAction dependencies pinned
- Info: 2 out of 2 npmCommand dependencies pinned
Reason
Found 4/29 approved changesets -- score normalized to 1
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/test.yml:1
- Info: no jobLevel write permissions found
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 20 are checked with a SAST tool
Score
3.1
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to @capacitor-community/firebase-analytics
@capacitor-firebase/analytics
Capacitor plugin for Firebase Analytics.
@firebase/analytics
A analytics package for new firebase packages
@firebase/analytics-compat
This is the compatibility layer for the Firebase Analytics component of the Firebase JS SDK.
@firebase/analytics-types
@firebase/analytics Types