commit | a6db7c2997ac47afe57174f62ae35959a5fbdef2 | [log] [tgz] |
---|---|---|
author | Devon Carew <devoncarew@google.com> | Wed Mar 30 00:16:38 2016 -0700 |
committer | Devon Carew <devoncarew@google.com> | Wed Mar 30 00:16:38 2016 -0700 |
tree | bb1a7df53c3c25d864dd8aafab5cc17b45795865 | |
parent | d45afe0eddbdd3c3763d2308ae2f3f4a097f709f [diff] | |
parent | 1e15afdf717f9aec600c07d48f2264a0e659f699 [diff] |
Merge pull request #68 from dart-lang/2.0.0 2.0.0
usage
is a wrapper around Google Analytics for both command-line, web, and Flutter apps.
In order to use this library, call the Analytics.create
static method. You'll get either the command-line, web, or Flutter implementation based on the current platform.
When you are creating a new property at google analytics make sure to select not the website option, but the mobile app option.
Note, for CLI apps, the usage library will send analytics pings asynchronously. This is useful it that it doesn‘t block the app generally. It does have one side-effect, in that outstanding asynchronous requests will block termination of the VM until that request finishes. So, for short-lived CLI tools, pinging Google Analytics can cause the tool to pause for several seconds before it terminates. This is often undesired - gathering analytics information shouldn’t negatively effect the tool's UX.
One solution to this is to use the waitForLastPing({Duration timeout})
method on the analytics object. This will wait until all outstanding analytics requests have completed, or until the specified duration has elapsed. So, CLI apps can do something like:
analytics.waitForLastPing(timeout: new Duration(milliseconds: 500)).then((_) { exit(0); });
Import the package:
import 'package:usage/usage.dart';
And call some analytics code:
final String UA = ...; Analytics ga = await Analytics.create(UA, 'ga_test', '1.0'); ga.optIn = true; ga.sendScreenView('home'); ga.sendException('foo exception'); ga.sendScreenView('files'); ga.sendTiming('writeTime', 100); ga.sendTiming('readTime', 20);
We use an opt-in method for sending analytics information. There are essentially three states for when we send information:
Sending screen views If the user has not opted in, the library will only send information about screen views. This allows tools to do things like version checks, but does not send any additional information.
Opt-in If the user opts-in to analytics collection the library sends all requested analytics info. This includes screen views, events, timing information, and exceptions.
Opt-ing out In order to not send analytics information, either do not call the analytics methods, or create and use the AnalyticsMock
class. This provides an instance you can use in place of a real analytics object but each analytics method is a no-op.
For both classes, you need to provide a Google Analytics tracking ID, the application name, and the application version.
Your application should provide an opt-in option for the user. If they opt-in, set the optIn
field to true
. This setting will persist across sessions automatically.
Note: This library is intended for use with the Google Analytics application / mobile app style tracking IDs (as opposed to the web site style tracking IDs).
For more information, please see the Google Analytics Measurement Protocol Policy.
Please file reports on the GitHub Issue Tracker.
You can view our license here.