add analytics tracking event for sdk/ndk downloads

Change-Id: Icb04694ef9498ae684350ad4a971fb23d0301605
diff --git a/tools/droiddoc/templates-sdk/sdkpage.cs b/tools/droiddoc/templates-sdk/sdkpage.cs
index c0f3be7..8de6668 100644
--- a/tools/droiddoc/templates-sdk/sdkpage.cs
+++ b/tools/droiddoc/templates-sdk/sdkpage.cs
@@ -87,7 +87,8 @@
   <tr>
     <td>Windows</td>
     <td>
-  <a href="http://dl.google.com/android/ndk/<?cs var:ndk.win_download ?>"><?cs var:ndk.win_download ?></a>
+  <a onClick="_gaq.push(['_trackEvent', 'Tools', 'Download NDK', 'Link <' + <?cs var:ndk.win_download ?> + '>']);"
+     href="http://dl.google.com/android/ndk/<?cs var:ndk.win_download ?>"><?cs var:ndk.win_download ?></a>
     </td>
     <td><?cs var:ndk.win_bytes ?> bytes</td>
     <td><?cs var:ndk.win_checksum ?></td>
@@ -95,7 +96,8 @@
   <tr class="alt-color">
     <td>Mac OS X (intel)</td>
     <td>
-  <a href="http://dl.google.com/android/ndk/<?cs var:ndk.mac_download ?>"><?cs var:ndk.mac_download ?></a>
+  <a onClick="_gaq.push(['_trackEvent', 'Tools', 'Download NDK', 'Link <' + <?cs var:ndk.mac_download ?> + '>']);"
+     href="http://dl.google.com/android/ndk/<?cs var:ndk.mac_download ?>"><?cs var:ndk.mac_download ?></a>
     </td>
     <td><?cs var:ndk.mac_bytes ?> bytes</td>
     <td><?cs var:ndk.mac_checksum ?></td>
@@ -103,7 +105,8 @@
   <tr>
     <td>Linux 32/64-bit (x86)</td>
     <td>
-  <a href="http://dl.google.com/android/ndk/<?cs var:ndk.linux_download ?>"><?cs var:ndk.linux_download ?></a>
+  <a onClick="_gaq.push(['_trackEvent', 'Tools', 'Download NDK', 'Link <' + <?cs var:ndk.linux_download ?> + '>']);"
+     href="http://dl.google.com/android/ndk/<?cs var:ndk.linux_download ?>"><?cs var:ndk.linux_download ?></a>
     </td>
     <td><?cs var:ndk.linux_bytes ?> bytes</td>
     <td><?cs var:ndk.linux_checksum ?></td>
@@ -147,7 +150,7 @@
   <tr>
     <td rowspan="2">Windows</td>
     <td>
-  <a onclick="onDownload(this)" href="http://dl.google.com/android/<?cs var:sdk.win_download
+  <a onclick="onDownload(this,false)" href="http://dl.google.com/android/<?cs var:sdk.win_download
 ?>"><?cs var:sdk.win_download ?></a>
     </td>
     <td><?cs var:sdk.win_bytes ?> bytes</td>
@@ -156,7 +159,7 @@
   <tr>
     <!-- blank TD from Windows rowspan -->
     <td>
-  <a onclick="onDownload(this)" id="win-sdk" href="http://dl.google.com/android/<?cs
+  <a onclick="onDownload(this,false)" id="win-sdk" href="http://dl.google.com/android/<?cs
 var:sdk.win_installer
 ?>"><?cs var:sdk.win_installer ?></a> (Recommended)
     </td>
@@ -166,7 +169,7 @@
   <tr class="alt-color">
     <td>Mac OS X (intel)</td>
     <td>
-  <a onclick="onDownload(this)" id="mac-sdk" href="http://dl.google.com/android/<?cs
+  <a onclick="onDownload(this,false)" id="mac-sdk" href="http://dl.google.com/android/<?cs
 var:sdk.mac_download
 ?>"><?cs var:sdk.mac_download ?></a>
     </td>
@@ -176,7 +179,7 @@
   <tr>
     <td>Linux (i386)</td>
     <td>
-  <a onclick="onDownload(this)" id="linux-sdk" href="http://dl.google.com/android/<?cs
+  <a onclick="onDownload(this,false)" id="linux-sdk" href="http://dl.google.com/android/<?cs
 var:sdk.linux_download
 ?>"><?cs var:sdk.linux_download ?></a>
     </td>
@@ -187,12 +190,18 @@
   
   
 <script>
-  function onDownload(link) {
+  function onDownload(link,fromButton) {
     $("#filename").text($(link).html());
     $("#next-steps").fadeIn('slow');
     $("#intro").fadeOut('slow');
     $('.pax').slideUp();
     $('.reqs').slideUp();
+    // Deliver Analytics event
+    if (fromButton) {
+      _gaq.push(['_trackEvent', 'Tools', 'Download SDK', 'Button <' + text($(link).html()) + '>']);
+    } else {
+      _gaq.push(['_trackEvent', 'Tools', 'Download SDK', 'Link <' + text($(link).html()) + '>']);
+    }
   }
   
   
@@ -213,7 +222,7 @@
     $('#not-supported').hide();
     $('#download-button').show();
     $('#download-button').text("Download the SDK for " + os);
-    $('#download-button').click(function() {onDownload($link.get());}).attr('href', $link.attr('href'));
+    $('#download-button').click(function() {onDownload($link.get());}).attr('href', $link.attr('href'),true);
   } else {
     $('.pax').show();
   }