Skip to content

Latest commit

 

History

History

analytics

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Deriv Analytics Library

A Flutter analytics library that integrates multiple analytics services including Datadog, Firebase, and RudderStack.

Table of Contents

  1. Installation
  2. Quick Start
  3. Configuration
  4. Logging Events
  5. User Identification
  6. Tracking Screens

Installation

To install the package, add the following to your pubspec.yaml:

dependencies:
  analytics:
       git:
         url: https://github.com/deriv-com/flutter-deriv-packages.git
         path: packages/analytics
         ref: <master/dev>

Run flutter packages get to fetch the package.

Quick Start

Initialize the analytics services you want to use in your main.dart:

final datadog = DerivDatadog();
final firebase = DerivFirebaseAnalytics();
final rudderstack = DerivRudderstack();

void main() {

    WidgetsFlutterBinding.ensureInitialized();

    DerivDatadogConfiguration configuration = DerivDatadogConfiguration(
      applicationId: 'DATADOG_APPLICATION_ID',
      clientToken: 'DATADOG_CLIENT_TOKEN',
      env: 'DATADOG_ENVIRONMENT',
      serviceName: 'DATADOG_SERVICE_NAME',
      trackingConsent: TrackingConsent.granted,
    );

  DerivDatadog().setup(configuration);

  DerivRudderstack().setup(RudderstackConfiguration(
      dataPlaneUrl: 'RUDDERSTACK_DATA_PLANE_URL',
      writeKey: 'RUDDERSTACK_WRITE_KEY',
      debugEnabled: true,
    ));

    DerivFirebaseAnalytics(FirebaseAnalytics.instanceFor(app: await Firebase.initializeApp())).setup(
      FirebaseConfiguration(
        isAnalyticsCollectionEnabled: true,
      ),
    );
    
  runApp(MyApp());
}

Configuration

Datadog

await datadog.setup(DerivDatadogConfiguration(
  clientToken: 'your_client_token',
  applicationId: 'your_application_id',
  env: 'production',
  trackingConsent: TrackingConsent.granted,
));

Firebase

await firebase.setup(FirebaseConfiguration(
  isAnalyticsCollectionEnabled: true,
));

RudderStack

await rudderstack.setup(RudderstackConfiguration(
  dataPlaneUrl: 'your_data_plane_url',
  writeKey: 'your_write_key',
));

Logging Events

You can log events as follows:

datadog.logEvent('button_click', {'label': 'cta_button'});
firebase.logEvent('button_click', {'label': 'cta_button'});
rudderstack.track('button_click');

User Identification

To identify a user:

datadog.setUserInfo(id: '123', email: 'email@example.com');
firebase.setUserId(id: '123');
rudderstack.identify(userId: '123');

Tracking Screens

datadog.screen(screenName: 'Home');
firebase.setCurrentScreen(screenName: 'Home');
rudderstack.screen(screenName: 'Home');