
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
@capacitor-community/firebase-analytics
Advanced tools
A native plugin for firebase analytics.
@capacitor-community/firebase-analytics
Capacitor community plugin for native Firebase Analytics.
Maintainer | GitHub | Social |
---|---|---|
Priyank Patel | priyankpat | @priyankpat_ |
Stewan Silva | stewwan | @StewanSilva |
Maintenance Status: Looking for maintainers!
Using npm:
npm install @capacitor-community/firebase-analytics
Using yarn:
yarn add @capacitor-community/firebase-analytics
Sync native files:
npx cap sync
On iOS, no further steps are needed.
On Android, register the plugin in your main activity:
import com.getcapacitor.community.firebaseanalytics.FirebaseAnalytics;
public class MainActivity extends BridgeActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Initializes the Bridge
this.init(
savedInstanceState,
new ArrayList<Class<? extends Plugin>>() {
{
// Additional plugins you've installed go here
// Ex: add(TotallyAwesomePlugin.class);
add(FirebaseAnalytics.class);
}
}
);
}
}
No configuration is required for this plugin.
Click here for an example on how to implement this plugin.
You can also clone the repository:
git clone https://github.com/priyankpat/capacitor-plugins-example
git checkout -b firebase-analytics
Name | Android | iOS | Web |
---|---|---|---|
setUserId | ✅ | ✅ | ✅ |
setUserProperty | ✅ | ✅ | ✅ |
getAppInstanceId | ✅ | ✅ | ❌ |
setScreenName | ✅ | ✅ | ❌ |
reset | ✅ | ✅ | ✅ |
logEvent | ✅ | ✅ | ✅ |
setCollectionEnabled | ✅ | ✅ | ✅ |
setSessionTimeoutDuration | ✅ | ✅ | ✅ |
enable | ✅ | ✅ | ❌ |
disable | ✅ | ✅ | ❌ |
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 userId - unique identifier of a user
* @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,
});
Navigate to the project settings page for your app on Firebase.
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.
Download the google-services.json
file and copy it to android/app/
directory of your capacitor project.
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 run npm install
)npx cap open ios
GoogleService-Info.plist
to the app folder in xcode-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.
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 run npm install
)npx cap open android
google-services.json
to your android/app
folder[extra step]
in android case we need to tell Capacitor to initialise the plugin:on your
MainActivity.java
file addimport com.getcapacitor.community.firebaseanalytics.FirebaseAnalytics;
and then inside the init callbackadd(AnalyticsPlugin.class);
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.
For existing projects you can upgrade all capacitor related packages (including this plugin) with this single command
npx npm-upgrade '*capacitor*' && npm install
If you were previously using the capacitor-analytics
package from npm
capacitor-analytics
to @capacitor-community/firebase-analytics
io.stewan.capacitor.analytics.AnalyticsPlugin;
to com.getcapacitor.community.firebaseanalytics.FirebaseAnalytics;
instance()
is now getAppInstanceId()
setScreen()
is now setScreenName()
setUserID()
is now setUserId()
setUserProp()
us now setUserProperty()
FAQs
A native plugin for firebase analytics.
The npm package @capacitor-community/firebase-analytics receives a total of 11,092 weekly downloads. As such, @capacitor-community/firebase-analytics popularity was classified as popular.
We found that @capacitor-community/firebase-analytics demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 42 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.