add google analytics to flutter_tools (#3523)

* add google analytics

* send in the run target type

* track device type targets

* use the real GA code

* review comments

* rev to usage 2.0

* rev to 2.2.0 of usage; add tests

* review comments
diff --git a/packages/flutter_tools/lib/src/runner/version.dart b/packages/flutter_tools/lib/src/runner/version.dart
index eb0a53b..dba2f7e 100644
--- a/packages/flutter_tools/lib/src/runner/version.dart
+++ b/packages/flutter_tools/lib/src/runner/version.dart
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
+import 'dart:io';
+
 import '../artifacts.dart';
 import '../base/process.dart';
 
@@ -54,4 +56,21 @@
   static FlutterVersion getVersion([String flutterRoot]) {
     return new FlutterVersion(flutterRoot != null ? flutterRoot : ArtifactStore.flutterRoot);
   }
+
+  static String getVersionString() {
+    final String cwd = ArtifactStore.flutterRoot;
+
+    String commit = _runSync('git', <String>['rev-parse', 'HEAD'], cwd);
+    if (commit.length > 8)
+      commit = commit.substring(0, 8);
+
+    String branch = _runSync('git', <String>['rev-parse', '--abbrev-ref', 'HEAD'], cwd);
+
+    return '$commit/$branch';
+  }
+}
+
+String _runSync(String executable, List<String> arguments, String cwd) {
+  ProcessResult results = Process.runSync(executable, arguments, workingDirectory: cwd);
+  return results.exitCode == 0 ? results.stdout.trim() : '';
 }