flutter_analytics 0.3.4+1

Flutter Analytics #

A barebones Analytics SDK to collect anonymous metadata from flutter apps.

Installation #

Add dependency to pubspec.yaml:

dependencies:
  ...
  flutter_analytics: ^0.3.4+1

Run in your terminal:

flutter packages get

Usage #

import 'package:flutter_analytics/flutter_analytics.dart' show Analytics;

// initial setup to run once on application lifecycle, no need to be awaited
Analytics.setup(
  configUrl: 'https://remote.config',
  destinations: ['https://remote.server'],
  onFlush: (batch) => batch.forEach(print),
  orgId: '775b5322-287b-4ca7-a750-86e5e848d226',
);

// uniquely identify group of users
Analytics.group('someGroupId', { 'numTrait': 7, 'txtTrait': 'tGroup' });

// uniquely identify current user and its traits
Analytics.identify('anUserId', { 'numTrait': 5, 'txtTrait': 'uUser' });

// identify current screen being viewed
Analytics.screen('My Screen', { 'numProp': -1, 'txtProp': 'pScreen'});

// track discrete events
Analytics.track('Any Event', { 'numProp': 3, 'txtProp': 'pTrack'});

// manually force the SDK to dispatch locally buffered events
Analytics.flush();

Example #

cd ~/flutter_analytics/example
flutter packages get
open -a simulator
flutter run

Integration tests #

cd ~/flutter_analytics/test
flutter packages get
flutter drive --target=lib/main.dart

Documentation #

cd ~/flutter_analytics
rm -rf doc
dartdoc
serve doc/api
open 'localhost:5000'

License #

MIT

v0.3.4+1 - 2019-09-17

  • Minor maintenance

v0.3.4 - 2019-09-16

  • Updated dependencies

v0.3.3 - 2019-06-17

  • Improved documentation

v0.3.2 - 2019-06-17

  • Improved example

v0.3.1 - 2019-06-17

  • First public release

example/lib/main.dart

// ignore_for_file: unawaited_futures, public_member_api_docs

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_analytics/flutter_analytics.dart';

Future<void> example() async {
  // initial setup to run once on application lifecycle, no need to be awaited
  Analytics.setup(
    configUrl: await configUrl(),
    onFlush: (batch) => batch.forEach(print),
    orgId: '775b5322-287b-4ca7-a750-86e5e848d226',
  );

  // uniquely identify group of users
  Analytics.group('someGroupId', {'numTrait': 7, 'txtTrait': 'tGroup'});

  // uniquely identify current user and its traits
  Analytics.identify('anUserId', {'numTrait': 5, 'txtTrait': 'uUser'});

  // identify current screen being viewed
  Analytics.screen('My Screen', {'numProp': -1, 'txtProp': 'pScreen'});

  // track discrete events
  Analytics.track('Any Event', {'numProp': 3, 'txtProp': 'pTrack'});

  // manually force the SDK to dispatch locally buffered events
  Analytics.flush();
}

Future<String> runExample() async {
  try {
    await example();

    return 'Everything fine, see console!';
  } catch (e, s) {
    debugPrint('$e\n$s');

    return 'Something went wrong, see console!';
  }
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
      future: runExample(),
      builder: (context, snapshot) {
        return MaterialApp(
          home: Scaffold(
            body: Center(
              child: Text(snapshot.data.toString() ?? 'hold on'),
            ),
          ),
        );
      }, // builder
    );
  } // build
}

Future<String> configUrl() => rootBundle.loadString('.config_url');

void main() => runApp(MyApp());

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_analytics: ^0.3.4+1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_analytics/flutter_analytics.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
24
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
62
Learn more about scoring.

We analyzed this package on Sep 20, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.2

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.0-dev.0.5 <3.0.0
connectivity ^0.4.4 0.4.4
device_info ^0.4.0+2 0.4.0+2
devicelocale ^0.2.0 0.2.0
flutter 0.0.0
flutter_persistent_queue ^3.0.0+1 3.0.0+1
flutter_udid ^1.0.0 1.0.0
http ^0.12.0+2 0.12.0+2
localstorage ^2.0.0 2.0.0
package_info ^0.4.0+6 0.4.0+6
uuid ^2.0.2 2.0.2
Transitive dependencies
async 2.3.0
charcode 1.1.2
collection 1.14.11 1.14.12
convert 2.1.1
crypto 2.1.3
http_parser 3.1.3
meta 1.1.7
path 1.6.4
path_provider 1.3.0
pedantic 1.8.0+1
platform 2.2.1
sky_engine 0.0.99
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_driver
test any