Capacitor Firebase Analytics Plugin
Capacitory community plugin for firebase analytics.
Maintainers
Mainteinance Status: Actively Maintained
Installation
To use npm
npm install @capacitor/firebase-analytics
To use yarn
yarn add @capacitor/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);
this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
add(FirebaseAnalytics.class);
}});
}
}
Configuration
No configuration required for this plugin.
Supported methods
Name | Android | iOS | Web |
---|
setUserId | ✅ | ✅ | ❌ |
setUserProperty | ✅ | ✅ | ❌ |
getAppInstanceId | ✅ | ✅ | ❌ |
setScreenName | ✅ | ✅ | ❌ |
reset | ✅ | ✅ | ❌ |
logEvent | ✅ | ✅ | ❌ |
Usage
import '@capacitor-community/http';
import { Plugins } from '@capacitor/core';
const { FirebaseAnalytics } = Plugins;
FirebaseAnalytics.setUserId({
userId: 'john_doe_123',
});
FirebaseAnalytics.setUserProperty({
name: 'favorite_food',
value: 'pizza',
});
FirebaseAnalytics.getAppInstanceId();
FirebaseAnalytics.setScreenName({
screenName: 'login',
nameOverride: 'LoginScreen',
});
FirebaseAnalytics.reset();
FirebaseAnalytics.logEvent({
name: 'select_content',
params: {
content_type: 'image',
content_id: 'P12453',
items: [{ name: 'Kittens' }]
},
});