Skip to content

Commit

Permalink
Improve readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Caseley committed Aug 19, 2021
1 parent 9c3bb2e commit 020c1ef
Showing 1 changed file with 101 additions and 8 deletions.
109 changes: 101 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,104 @@ Analytics solution for using multiple vendors

## Getting Started

This project is a starting point for a Dart
[package](https://flutter.dev/developing-packages/),
a library module containing code that can be shared easily across
multiple Flutter or Dart projects.

For help getting started with Flutter, view our
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
Installation:

`flutter pub add analyticsx`

Usage:

* Initialise the library with one or more `AnalyticsVendor` objects
* Call `invokeAction` to pass an `AnalyticsAction` to all vendors

```dart
import 'package:analyticsx/actions/track_event.dart';
import 'package:analyticsx/analytics_x.dart';
import 'package:analyticsx/vendors/firebase.dart';
import 'package:flutter/material.dart';
void main() {
AnalyticsX().init([Firebase()]);
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
AnalyticsX().invokeAction(TrackEvent('test_event', {'test-param': 'yes'}));
return MaterialApp(
title: 'Analytics X Example'
);
}
}
```

## API

### AnalyticsX

#### init(\[...vendors\])

Before any analytics events can be emitted to vendors, vendors need to be registered with the AnalyticsX static
library via the `init` function. This in turn will call the `init()` method on the AnalyticsVendor (see below). This
method can
be called multiple times to register additional vendors (e.g. where different providers require initialising at
different points in the application's lifecycle), but are always cumulative. Passing the same vendor multiple times
will only ever `init()` the vendor once.

#### invokeAction(AnalyticsAction action, \[List\<String\>\] vendorIds)

Passes an analytics event to a vendor. Passes the action to the `handleAction` of each AnalyticsVendor.

Where `vendorIds` is specified, the event is emitted only to those vendors.

### AnalyticsVendor

An abstraction of the Analytics Vendor's SDK for AnalyticsX. The library comes with Firebase already implemented. An
additional implementation is shown in the example project.

#### init()

Any initialisation required by the vendor's SDK. Called once only, when this AnalyticsVendor object is passed to the
AnalyticsX `init` method.

#### handleAction(AnalyticsAction action)

Implementation of how to pass the action (of whatever type) into the Vendor SDK. It is expected for `AnalyticsVendor`
authors to write this method such that any `AnalyticsAction` can be passed and the method acts on only the actions
it understands.

Example:
```dart
void handleAction(AnalyticsAction action) {
if (action is TrackEvent) {
analytics.logEvent(name: action.eventName, parameters: action.parameters);
}
if (action is SetScreen) {
analytics.setCurrentScreen(screenName: action.screenName);
}
}
```

### AnalyticsAction

A representation of the analytics action (e.g. event, screen, count) required in order for the Vendor to record the
action taken. This is a plain Dart object containing properties (a PODO?), typically implemented with a constructor
that takes values for the properties, allowing the implementing application to quickly record an action.

Application example:
```dart
void doSomething() {
AnalyticsX().invokeAction(SimpleAnalyticsAction('test_event', {'test-param': 'yes'}));
}
```

## Contributions

Very welcome :)

### Dev Setup

* Check out code
* `flutter pub get`
* Write code

0 comments on commit 020c1ef

Please sign in to comment.