| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /// A simple command-line app to hand-test the usage library. | 5 /** |
| 6 * A simple command-line app to hand-test the usage library. |
| 7 */ |
| 6 library usage_ga; | 8 library usage_ga; |
| 7 | 9 |
| 8 import 'package:usage/usage_io.dart'; | 10 import 'package:usage/usage_io.dart'; |
| 9 | 11 |
| 10 main(List args) async { | 12 void main(List args) { |
| 11 final String DEFAULT_UA = 'UA-55029513-1'; | 13 final String DEFAULT_UA = 'UA-55029513-1'; |
| 12 | 14 |
| 13 if (args.isEmpty) { | 15 if (args.isEmpty) { |
| 14 print('usage: dart ga <GA tracking ID>'); | 16 print('usage: dart ga <GA tracking ID>'); |
| 15 print('pinging default UA value (${DEFAULT_UA})'); | 17 print('pinging default UA value (${DEFAULT_UA})'); |
| 16 } else { | 18 } else { |
| 17 print('pinging ${args.first}'); | 19 print('pinging ${args.first}'); |
| 18 } | 20 } |
| 19 | 21 |
| 20 String ua = args.isEmpty ? DEFAULT_UA : args.first; | 22 String ua = args.isEmpty ? DEFAULT_UA : args.first; |
| 21 | 23 |
| 22 Analytics ga = new AnalyticsIO(ua, 'ga_test', '3.0'); | 24 Analytics ga = new AnalyticsIO(ua, 'ga_test', '1.0'); |
| 25 ga.optIn = true; |
| 23 | 26 |
| 24 await ga.sendScreenView('home'); | 27 ga.sendScreenView('home').then((_) { |
| 25 await ga.sendScreenView('files'); | 28 return ga.sendScreenView('files'); |
| 26 await ga | 29 }).then((_) { |
| 27 .sendException('foo error:\n${sanitizeStacktrace(StackTrace.current)}'); | 30 return ga.sendException('foo exception, line 123:56'); |
| 28 await ga.sendTiming('writeDuration', 123); | 31 }).then((_) { |
| 29 await ga.sendEvent('create', 'consoleapp', label: 'Console App'); | 32 return ga.sendTiming('writeDuration', 123); |
| 30 print('pinged ${ua}'); | 33 }).then((_) { |
| 31 | 34 return ga.sendEvent('create', 'consoleapp', label: 'Console App'); |
| 32 await ga.waitForLastPing(); | 35 }).then((_) { |
| 33 | 36 print('pinged ${ua}'); |
| 34 ga.close(); | 37 }); |
| 35 } | 38 } |
| OLD | NEW |