Need help upgrading to Ionic Framework 4.0? Get assistance with our Enterprise Migration Services EXPLORE NOW

Analytics Firebase

Improve this doc

Google Analytics Firebase plugin for Ionic Native apps.

Repo: https://github.com/appfeel/analytics-google

Installation

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add cordova-plugin-analytics
    $ npm install --save @ionic-native/analytics-firebase@4
    
  2. Add this plugin to your app's module

Supported platforms

Usage

import { AnalyticsFirebase } from '@ionic-native/analytics-firebase';


constructor(private analyticsFirebase: AnalyticsFirebase) { }

// Track an event with default events and params
const eventParams = {};
eventParams[this.analyticsFirebase.DEFAULT_PARAMS.LEVEL] = 29;
this.analyticsFirebase.logEvent(this.analyticsFirebase.DEFAULT_EVENTS.LEVEL_UP, eventParams)
  .then(() => console.log('Event successfully tracked'))
  .catch(err => console.log('Error tracking event:', err));

// Track an event with custom events and params
const eventParams = {};
eventParams['my-prop'] = 29;
this.analyticsFirebase.logEvent('my-event', eventParams)
  .then(() => console.log('Event successfully tracked'))
  .catch(err => console.log('Error tracking event:', err));


// Reset analytics data
this.analyticsFirebase.resetAnalyticsData()
  .then(() => console.log('Analytics data have been reset'))
  .catch(err => console.log('Error resetting analytics data:', err));


// Track a screen view
this.analyticsFirebase.setCurrentScreen('Home')
  .then(() => console.log('View successfully tracked'))
  .catch(err => console.log('Error tracking view:', err));


// Set user id
this.analyticsFirebase.setUserId('USER-ID')
  .then(() => console.log('User id successfully set'))
  .catch(err => console.log('Error setting user id:', err));


// Set user property from default properties
this.analyticsFirebase.setUserProperty('KEY', 'VALUE')
  .then(() => console.log('User property successfully set'))
  .catch(err => console.log('Error setting user property:', err));

Instance Members

readonly

This enum represents AnalyticsFirebase default events. Use one of these default events or a custom event

API

Native

General