Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(657)

Side by Side Diff: packages/usage/readme.md

Issue 2989763002: Update charted to 0.4.8 and roll (Closed)
Patch Set: Removed Cutch from list of reviewers Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « packages/usage/pubspec.yaml ('k') | packages/usage/test/all.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # usage 1 # usage
2 2
3 `usage` is a wrapper around Google Analytics for both command-line apps and web 3 `usage` is a wrapper around Google Analytics for command-line, web, and Flutter apps.
4 apps.
5 4
5 [![pub package](https://img.shields.io/pub/v/usage.svg)](https://pub.dartlang.or g/packages/usage)
6 [![Build Status](https://travis-ci.org/dart-lang/usage.svg)](https://travis-ci.o rg/dart-lang/usage) 6 [![Build Status](https://travis-ci.org/dart-lang/usage.svg)](https://travis-ci.o rg/dart-lang/usage)
7 [![Coverage Status](https://img.shields.io/coveralls/dart-lang/usage.svg)](https ://coveralls.io/r/dart-lang/usage?branch=master) 7 [![Coverage Status](https://img.shields.io/coveralls/dart-lang/usage.svg)](https ://coveralls.io/r/dart-lang/usage?branch=master)
8 8
9 ## For web apps 9 ## For web apps
10 10
11 To use this library as a web app, import the `usage_html.dart` library and 11 To use this library as a web app, import the `usage_html.dart` library and
12 instantiate the `AnalyticsHtml` class. 12 instantiate the `AnalyticsHtml` class.
13 13
14 When you are creating a new property at [google analytics](https://www.google.co m/analytics/)
15 make sure to select the **mobile app** option, not the website option.
16
17 ## For Flutter apps
18
19 Flutter applications can use the `AnalyticsIO` version of this library. They wil l need
20 to specify the documents directory in the constructor in order to tell the libra ry where
21 to save the analytics preferences:
22
23 ```dart
24 import 'package:flutter/services.dart';
25 import 'package:usage/usage_io.dart';
26
27 void main() {
28 final String UA = ...;
29
30 Analytics ga = new AnalyticsIO(UA, 'ga_test', '3.0',
31 documentsDirectory: PathProvider.getApplicationDocumentsDirectory());
32 ...
33 }
34 ```
35
14 ## For command-line apps 36 ## For command-line apps
15 37
16 To use this library as a command-line app, import the `usage_io.dart` library 38 To use this library as a command-line app, import the `usage_io.dart` library
17 and instantiate the `AnalyticsIO` class. 39 and instantiate the `AnalyticsIO` class.
18 40
19 Note, for CLI apps, the usage library will send analytics pings asynchronously. 41 Note, for CLI apps, the usage library will send analytics pings asynchronously.
20 This is useful it that it doesn't block the app generally. It does have one 42 This is useful it that it doesn't block the app generally. It does have one
21 side-effect, in that outstanding asynchronous requests will block termination 43 side-effect, in that outstanding asynchronous requests will block termination
22 of the VM until that request finishes. So, for short-lived CLI tools, pinging 44 of the VM until that request finishes. So, for short-lived CLI tools, pinging
23 Google Analytics can cause the tool to pause for several seconds before it 45 Google Analytics can cause the tool to pause for several seconds before it
24 terminates. This is often undesired - gathering analytics information shouldn't 46 terminates. This is often undesired - gathering analytics information shouldn't
25 negatively effect the tool's UX. 47 negatively effect the tool's UX.
26 48
27 One solution to this is to use the `waitForLastPing({Duration timeout})` method 49 One solution to this is to use the `waitForLastPing({Duration timeout})` method
28 on the analytics object. This will wait until all outstanding analytics requests 50 on the analytics object. This will wait until all outstanding analytics requests
29 have completed, or until the specified duration has elapsed. So, CLI apps can do 51 have completed, or until the specified duration has elapsed. So, CLI apps can do
30 something like: 52 something like:
31 53
32 ```dart 54 ```dart
33 analytics.waitForLastPing(timeout: new Duration(milliseconds: 500)).then((_) { 55 await analytics.waitForLastPing(timeout: new Duration(milliseconds: 200));
34 exit(0); 56 analytics.close();
35 }); 57 ```
58
59 or:
60
61 ```dart
62 await analytics.waitForLastPing(timeout: new Duration(milliseconds: 200));
63 exit(0);
36 ``` 64 ```
37 65
38 ## Using the API 66 ## Using the API
39 67
40 Import the package (in this example we use the `dart:io` version): 68 Import the package (in this example we use the `dart:io` version):
41 69
42 ```dart 70 ```dart
43 import 'package:usage/usage_io.dart'; 71 import 'package:usage/usage_io.dart';
44 ``` 72 ```
45 73
46 And call some analytics code: 74 And call some analytics code:
47 75
48 ```dart 76 ```dart
49 final String UA = ...; 77 final String UA = ...;
50 78
51 Analytics ga = new AnalyticsIO(UA, 'ga_test', '1.0'); 79 Analytics ga = new AnalyticsIO(UA, 'ga_test', '3.0');
52 ga.optIn = true; 80 ga.optIn = true;
53 81
54 ga.sendScreenView('home'); 82 ga.sendScreenView('home');
55 ga.sendException('foo exception'); 83 ga.sendException('foo exception');
56 84
57 ga.sendScreenView('files'); 85 ga.sendScreenView('files');
58 ga.sendTiming('writeTime', 100); 86 ga.sendTiming('writeTime', 100);
59 ga.sendTiming('readTime', 20); 87 ga.sendTiming('readTime', 20);
60 ``` 88 ```
61 89
62 ## When do we send analytics data? 90 ## When do we send analytics data?
63 91
64 We use an opt-in method for sending analytics information. There are essentially 92 You can use this library in an opt-in manner or an opt-out one. It defaults to
65 three states for when we send information: 93 opt-out - data will be sent to Google Analytics unless the user explicitly
94 opts-out. The mode can be adjusted by changing the value of the
95 `Analytics.analyticsOpt` field.
66 96
67 *Sending screen views* If the user has not opted in, the library will only send 97 *Opt-out* In opt-out mode, if the user does not explicitly opt-out of collecting
68 information about screen views. This allows tools to do things like version 98 analytics (`Analytics.enabled = false`), the usage library will send usage data.
69 checks, but does not send any additional information.
70 99
71 *Opt-in* If the user opts-in to analytics collection the library sends all 100 *Opt-in* In opt-in mode, no data will be sent until the user explicitly opt-in
72 requested analytics info. This includes screen views, events, timing 101 to collection (`Analytics.enabled = true`). This includes screen views, events,
73 information, and exceptions. 102 timing information, and exceptions.
74
75 *Opt-ing out* In order to not send analytics information, either do not call the
76 analytics methods, or create and use the `AnalyticsMock` class. This provides
77 an instance you can use in place of a real analytics object but each analytics
78 method is a no-op.
79 103
80 ## Other info 104 ## Other info
81 105
82 For both classes, you need to provide a Google Analytics tracking ID, the 106 For both classes, you need to provide a Google Analytics tracking ID, the
83 application name, and the application version. 107 application name, and the application version.
84 108
85 Your application should provide an opt-in option for the user. If they opt-in, 109 Your application should provide an opt-in option for the user. If they opt-in,
86 set the `optIn` field to `true`. This setting will persist across sessions 110 set the `optIn` field to `true`. This setting will persist across sessions
87 automatically. 111 automatically.
88 112
89 *Note:* This library is intended for use with the Google Analytics application / 113 *Note:* This library is intended for use with the Google Analytics application /
90 mobile app style tracking IDs (as opposed to the web site style tracking IDs). 114 mobile app style tracking IDs (as opposed to the web site style tracking IDs).
91 115
92 For more information, please see the Google Analytics Measurement Protocol 116 For more information, please see the Google Analytics Measurement Protocol
93 [Policy](https://developers.google.com/analytics/devguides/collection/protocol/p olicy). 117 [Policy](https://developers.google.com/analytics/devguides/collection/protocol/p olicy).
94 118
119 ## Contributing
120
121 Tests can be run using `pub run test`.
122
95 ## Issues and bugs 123 ## Issues and bugs
96 124
97 Please file reports on the 125 Please file reports on the
98 [GitHub Issue Tracker](https://github.com/dart-lang/usage/issues). 126 [GitHub Issue Tracker](https://github.com/dart-lang/usage/issues).
99 127
100 ## License 128 ## License
101 129
102 You can view our license 130 You can view our license
103 [here](https://github.com/dart-lang/usage/blob/master/LICENSE). 131 [here](https://github.com/dart-lang/usage/blob/master/LICENSE).
OLDNEW
« no previous file with comments | « packages/usage/pubspec.yaml ('k') | packages/usage/test/all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698