{"action":"created","comment":{"url":"https://api.github.com/repos/flutter/flutter/pulls/comments/60973006","id":60973006,"diff_hunk":"@@ -0,0 +1,86 @@\n+// Copyright 2016 The Chromium Authors. All rights reserved.\n+// Use of this source code is governed by a BSD-style license that can be\n+// found in the LICENSE file.\n+\n+import 'dart:async';\n+\n+import 'package:usage/usage_io.dart';\n+\n+import 'base/context.dart';\n+import 'globals.dart';\n+import 'runner/version.dart';\n+\n+// TODO(devoncarew): We'll need to do some work on the user agent in order to\n+// correctly track usage by operating system (dart-lang/usage/issues/70).\n+\n+// TODO(devoncarew): We'll want to find a way to send (sanitized) command parameters.\n+\n+const String _kFlutterUA = 'UA-67589403-5';\n+\n+const Duration _kMaxExitDelayDuration = const Duration(milliseconds: 250);\n+\n+class Usage {\n+  /// Returns [Usage] active in the current app context.\n+  static Usage get instance => context[Usage] ?? (context[Usage] = new Usage());\n+\n+  Usage() {\n+    _ga = new AnalyticsIO(_kFlutterUA, 'flutter', FlutterVersion.getVersionString());\n+\n+    // Check if this is the first run. If so, enable analytics. We show opt-out\n+    // methods (flutter config) the first time the tool is run.\n+    if (!_ga.hasSetOptIn) {\n+      _isFirstRun = true;\n+      _ga.optIn = true;\n+    }\n+  }\n+\n+  bool _isFirstRun = false;\n+\n+  bool get isFirstRun => _isFirstRun;\n+\n+  Analytics _ga;\n+\n+  /// Enable or disable reporting analytics.\n+  set enable(bool value) {\n+    _ga.optIn = value;\n+  }\n+\n+  void sendCommand(String command) {\n+    printTrace('usage: $command');\n+    _ga.sendScreenView(command);\n+  }\n+\n+  void sendEvent(String category, String parameter) {\n+    printTrace('usage: $category:$parameter');\n+    _ga.sendEvent(category, parameter);\n+  }\n+\n+  UsageTimer startTimer(String event) {\n+    return new UsageTimer._(event, _ga.startTimer(event));\n+  }\n+\n+  void sendException(dynamic exception, StackTrace trace) {\n+    String message = '${exception.runtimeType}; ${sanitizeStacktrace(trace)}';\n+    printTrace('usage: $message');\n+    _ga.sendException(message);\n+  }\n+\n+  Future<Null> waitForLastPing() {","path":"packages/flutter_tools/lib/src/usage.dart","position":68,"original_position":68,"commit_id":"bc71c4d2384c32f4fddbd3b6820a82752e221da1","original_commit_id":"bc71c4d2384c32f4fddbd3b6820a82752e221da1","user":{"login":"Hixie","id":551196,"avatar_url":"https://avatars.githubusercontent.com/u/551196?v=3","gravatar_id":"","url":"https://api.github.com/users/Hixie","html_url":"https://github.com/Hixie","followers_url":"https://api.github.com/users/Hixie/followers","following_url":"https://api.github.com/users/Hixie/following{/other_user}","gists_url":"https://api.github.com/users/Hixie/gists{/gist_id}","starred_url":"https://api.github.com/users/Hixie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Hixie/subscriptions","organizations_url":"https://api.github.com/users/Hixie/orgs","repos_url":"https://api.github.com/users/Hixie/repos","events_url":"https://api.github.com/users/Hixie/events{/privacy}","received_events_url":"https://api.github.com/users/Hixie/received_events","type":"User","site_admin":false},"body":"this name is confusing. I know it's just the same as the underlying API's, but I think we should name it something clearer.","created_at":"2016-04-25T19:27:29Z","updated_at":"2016-04-25T19:27:29Z","html_url":"https://github.com/flutter/flutter/pull/3523#discussion_r60973006","pull_request_url":"https://api.github.com/repos/flutter/flutter/pulls/3523","_links":{"self":{"href":"https://api.github.com/repos/flutter/flutter/pulls/comments/60973006"},"html":{"href":"https://github.com/flutter/flutter/pull/3523#discussion_r60973006"},"pull_request":{"href":"https://api.github.com/repos/flutter/flutter/pulls/3523"}}},"pull_request":{"url":"https://api.github.com/repos/flutter/flutter/pulls/3523","id":67755910,"html_url":"https://github.com/flutter/flutter/pull/3523","diff_url":"https://github.com/flutter/flutter/pull/3523.diff","patch_url":"https://github.com/flutter/flutter/pull/3523.patch","issue_url":"https://api.github.com/repos/flutter/flutter/issues/3523","number":3523,"state":"open","locked":false,"title":"add google analytics to flutter_tools","user":{"login":"devoncarew","id":1269969,"avatar_url":"https://avatars.githubusercontent.com/u/1269969?v=3","gravatar_id":"","url":"https://api.github.com/users/devoncarew","html_url":"https://github.com/devoncarew","followers_url":"https://api.github.com/users/devoncarew/followers","following_url":"https://api.github.com/users/devoncarew/following{/other_user}","gists_url":"https://api.github.com/users/devoncarew/gists{/gist_id}","starred_url":"https://api.github.com/users/devoncarew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/devoncarew/subscriptions","organizations_url":"https://api.github.com/users/devoncarew/orgs","repos_url":"https://api.github.com/users/devoncarew/repos","events_url":"https://api.github.com/users/devoncarew/events{/privacy}","received_events_url":"https://api.github.com/users/devoncarew/received_events","type":"User","site_admin":false},"body":"This adds support for sending anonymous usage data for flutter_tools to google analytics. It:\r\n\r\n- prints a message on first run, telling the user how to disable the analytics, and displaying the privacy policy\r\n- adds a new `flutter config` command, where analytics can be enabled and disabled\r\n- sends command usage, command timing, and crash data\r\n\r\nWe'll want to iterate on it to properly track the host OS and command parameters.\r\n\r\nfix #1065","created_at":"2016-04-25T17:18:13Z","updated_at":"2016-04-25T19:27:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"59ed75ffd506e26e1c154ddf85af33260cff7ca0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/flutter/flutter/pulls/3523/commits","review_comments_url":"https://api.github.com/repos/flutter/flutter/pulls/3523/comments","review_comment_url":"https://api.github.com/repos/flutter/flutter/pulls/comments{/number}","comments_url":"https://api.github.com/repos/flutter/flutter/issues/3523/comments","statuses_url":"https://api.github.com/repos/flutter/flutter/statuses/bc71c4d2384c32f4fddbd3b6820a82752e221da1","head":{"label":"devoncarew:add_analytics","ref":"add_analytics","sha":"bc71c4d2384c32f4fddbd3b6820a82752e221da1","user":{"login":"devoncarew","id":1269969,"avatar_url":"https://avatars.githubusercontent.com/u/1269969?v=3","gravatar_id":"","url":"https://api.github.com/users/devoncarew","html_url":"https://github.com/devoncarew","followers_url":"https://api.github.com/users/devoncarew/followers","following_url":"https://api.github.com/users/devoncarew/following{/other_user}","gists_url":"https://api.github.com/users/devoncarew/gists{/gist_id}","starred_url":"https://api.github.com/users/devoncarew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/devoncarew/subscriptions","organizations_url":"https://api.github.com/users/devoncarew/orgs","repos_url":"https://api.github.com/users/devoncarew/repos","events_url":"https://api.github.com/users/devoncarew/events{/privacy}","received_events_url":"https://api.github.com/users/devoncarew/received_events","type":"User","site_admin":false},"repo":{"id":45596312,"name":"flutter","full_name":"devoncarew/flutter","owner":{"login":"devoncarew","id":1269969,"avatar_url":"https://avatars.githubusercontent.com/u/1269969?v=3","gravatar_id":"","url":"https://api.github.com/users/devoncarew","html_url":"https://github.com/devoncarew","followers_url":"https://api.github.com/users/devoncarew/followers","following_url":"https://api.github.com/users/devoncarew/following{/other_user}","gists_url":"https://api.github.com/users/devoncarew/gists{/gist_id}","starred_url":"https://api.github.com/users/devoncarew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/devoncarew/subscriptions","organizations_url":"https://api.github.com/users/devoncarew/orgs","repos_url":"https://api.github.com/users/devoncarew/repos","events_url":"https://api.github.com/users/devoncarew/events{/privacy}","received_events_url":"https://api.github.com/users/devoncarew/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/devoncarew/flutter","description":"The Flutter framework","fork":true,"url":"https://api.github.com/repos/devoncarew/flutter","forks_url":"https://api.github.com/repos/devoncarew/flutter/forks","keys_url":"https://api.github.com/repos/devoncarew/flutter/keys{/key_id}","collaborators_url":"https://api.github.com/repos/devoncarew/flutter/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/devoncarew/flutter/teams","hooks_url":"https://api.github.com/repos/devoncarew/flutter/hooks","issue_events_url":"https://api.github.com/repos/devoncarew/flutter/issues/events{/number}","events_url":"https://api.github.com/repos/devoncarew/flutter/events","assignees_url":"https://api.github.com/repos/devoncarew/flutter/assignees{/user}","branches_url":"https://api.github.com/repos/devoncarew/flutter/branches{/branch}","tags_url":"https://api.github.com/repos/devoncarew/flutter/tags","blobs_url":"https://api.github.com/repos/devoncarew/flutter/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/devoncarew/flutter/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/devoncarew/flutter/git/refs{/sha}","trees_url":"https://api.github.com/repos/devoncarew/flutter/git/trees{/sha}","statuses_url":"https://api.github.com/repos/devoncarew/flutter/statuses/{sha}","languages_url":"https://api.github.com/repos/devoncarew/flutter/languages","stargazers_url":"https://api.github.com/repos/devoncarew/flutter/stargazers","contributors_url":"https://api.github.com/repos/devoncarew/flutter/contributors","subscribers_url":"https://api.github.com/repos/devoncarew/flutter/subscribers","subscription_url":"https://api.github.com/repos/devoncarew/flutter/subscription","commits_url":"https://api.github.com/repos/devoncarew/flutter/commits{/sha}","git_commits_url":"https://api.github.com/repos/devoncarew/flutter/git/commits{/sha}","comments_url":"https://api.github.com/repos/devoncarew/flutter/comments{/number}","issue_comment_url":"https://api.github.com/repos/devoncarew/flutter/issues/comments{/number}","contents_url":"https://api.github.com/repos/devoncarew/flutter/contents/{+path}","compare_url":"https://api.github.com/repos/devoncarew/flutter/compare/{base}...{head}","merges_url":"https://api.github.com/repos/devoncarew/flutter/merges","archive_url":"https://api.github.com/repos/devoncarew/flutter/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/devoncarew/flutter/downloads","issues_url":"https://api.github.com/repos/devoncarew/flutter/issues{/number}","pulls_url":"https://api.github.com/repos/devoncarew/flutter/pulls{/number}","milestones_url":"https://api.github.com/repos/devoncarew/flutter/milestones{/number}","notifications_url":"https://api.github.com/repos/devoncarew/flutter/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/devoncarew/flutter/labels{/name}","releases_url":"https://api.github.com/repos/devoncarew/flutter/releases{/id}","deployments_url":"https://api.github.com/repos/devoncarew/flutter/deployments","created_at":"2015-11-05T07:56:06Z","updated_at":"2016-04-09T14:03:56Z","pushed_at":"2016-04-25T16:37:02Z","git_url":"git://github.com/devoncarew/flutter.git","ssh_url":"git@github.com:devoncarew/flutter.git","clone_url":"https://github.com/devoncarew/flutter.git","svn_url":"https://github.com/devoncarew/flutter","homepage":"http://flutter.io","size":16421,"stargazers_count":0,"watchers_count":0,"language":"Dart","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"flutter:master","ref":"master","sha":"86723ab99ee296bc7aef987220f6adbf78f15ae7","user":{"login":"flutter","id":14101776,"avatar_url":"https://avatars.githubusercontent.com/u/14101776?v=3","gravatar_id":"","url":"https://api.github.com/users/flutter","html_url":"https://github.com/flutter","followers_url":"https://api.github.com/users/flutter/followers","following_url":"https://api.github.com/users/flutter/following{/other_user}","gists_url":"https://api.github.com/users/flutter/gists{/gist_id}","starred_url":"https://api.github.com/users/flutter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flutter/subscriptions","organizations_url":"https://api.github.com/users/flutter/orgs","repos_url":"https://api.github.com/users/flutter/repos","events_url":"https://api.github.com/users/flutter/events{/privacy}","received_events_url":"https://api.github.com/users/flutter/received_events","type":"Organization","site_admin":false},"repo":{"id":31792824,"name":"flutter","full_name":"flutter/flutter","owner":{"login":"flutter","id":14101776,"avatar_url":"https://avatars.githubusercontent.com/u/14101776?v=3","gravatar_id":"","url":"https://api.github.com/users/flutter","html_url":"https://github.com/flutter","followers_url":"https://api.github.com/users/flutter/followers","following_url":"https://api.github.com/users/flutter/following{/other_user}","gists_url":"https://api.github.com/users/flutter/gists{/gist_id}","starred_url":"https://api.github.com/users/flutter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flutter/subscriptions","organizations_url":"https://api.github.com/users/flutter/orgs","repos_url":"https://api.github.com/users/flutter/repos","events_url":"https://api.github.com/users/flutter/events{/privacy}","received_events_url":"https://api.github.com/users/flutter/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/flutter/flutter","description":"Framework for building high-performance, high-fidelity iOS and Android apps","fork":false,"url":"https://api.github.com/repos/flutter/flutter","forks_url":"https://api.github.com/repos/flutter/flutter/forks","keys_url":"https://api.github.com/repos/flutter/flutter/keys{/key_id}","collaborators_url":"https://api.github.com/repos/flutter/flutter/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/flutter/flutter/teams","hooks_url":"https://api.github.com/repos/flutter/flutter/hooks","issue_events_url":"https://api.github.com/repos/flutter/flutter/issues/events{/number}","events_url":"https://api.github.com/repos/flutter/flutter/events","assignees_url":"https://api.github.com/repos/flutter/flutter/assignees{/user}","branches_url":"https://api.github.com/repos/flutter/flutter/branches{/branch}","tags_url":"https://api.github.com/repos/flutter/flutter/tags","blobs_url":"https://api.github.com/repos/flutter/flutter/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/flutter/flutter/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/flutter/flutter/git/refs{/sha}","trees_url":"https://api.github.com/repos/flutter/flutter/git/trees{/sha}","statuses_url":"https://api.github.com/repos/flutter/flutter/statuses/{sha}","languages_url":"https://api.github.com/repos/flutter/flutter/languages","stargazers_url":"https://api.github.com/repos/flutter/flutter/stargazers","contributors_url":"https://api.github.com/repos/flutter/flutter/contributors","subscribers_url":"https://api.github.com/repos/flutter/flutter/subscribers","subscription_url":"https://api.github.com/repos/flutter/flutter/subscription","commits_url":"https://api.github.com/repos/flutter/flutter/commits{/sha}","git_commits_url":"https://api.github.com/repos/flutter/flutter/git/commits{/sha}","comments_url":"https://api.github.com/repos/flutter/flutter/comments{/number}","issue_comment_url":"https://api.github.com/repos/flutter/flutter/issues/comments{/number}","contents_url":"https://api.github.com/repos/flutter/flutter/contents/{+path}","compare_url":"https://api.github.com/repos/flutter/flutter/compare/{base}...{head}","merges_url":"https://api.github.com/repos/flutter/flutter/merges","archive_url":"https://api.github.com/repos/flutter/flutter/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/flutter/flutter/downloads","issues_url":"https://api.github.com/repos/flutter/flutter/issues{/number}","pulls_url":"https://api.github.com/repos/flutter/flutter/pulls{/number}","milestones_url":"https://api.github.com/repos/flutter/flutter/milestones{/number}","notifications_url":"https://api.github.com/repos/flutter/flutter/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/flutter/flutter/labels{/name}","releases_url":"https://api.github.com/repos/flutter/flutter/releases{/id}","deployments_url":"https://api.github.com/repos/flutter/flutter/deployments","created_at":"2015-03-06T22:54:58Z","updated_at":"2016-04-25T18:11:52Z","pushed_at":"2016-04-25T18:46:29Z","git_url":"git://github.com/flutter/flutter.git","ssh_url":"git@github.com:flutter/flutter.git","clone_url":"https://github.com/flutter/flutter.git","svn_url":"https://github.com/flutter/flutter","homepage":"http://flutter.io","size":110077,"stargazers_count":2755,"watchers_count":2755,"language":"Dart","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":278,"mirror_url":null,"open_issues_count":852,"forks":278,"open_issues":852,"watchers":2755,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/flutter/flutter/pulls/3523"},"html":{"href":"https://github.com/flutter/flutter/pull/3523"},"issue":{"href":"https://api.github.com/repos/flutter/flutter/issues/3523"},"comments":{"href":"https://api.github.com/repos/flutter/flutter/issues/3523/comments"},"review_comments":{"href":"https://api.github.com/repos/flutter/flutter/pulls/3523/comments"},"review_comment":{"href":"https://api.github.com/repos/flutter/flutter/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/flutter/flutter/pulls/3523/commits"},"statuses":{"href":"https://api.github.com/repos/flutter/flutter/statuses/bc71c4d2384c32f4fddbd3b6820a82752e221da1"}}}}