浏览代码

HUE-1190 [core] Usage statistics

Added inline popover for the wizard checkbox
Configured Google Analytics
Romain Rigaux 12 年之前
父节点
当前提交
a9a6f78368

+ 25 - 0
apps/about/src/about/templates/admin_wizard.mako

@@ -120,6 +120,23 @@ ${ commonheader(_('Quick Start'), "quick_start", user, "100px") | n,unicode }
 	      <a  href="${ url('useradmin.views.list_users') }" target="_blank">${ _('User Admin') } <img src="/useradmin/static/art/icon_useradmin_24.png"></a>
         </div>
       </div>
+      
+      <br/>
+      
+      <div class="widget-box">
+        <div class="widget-title">
+          <span class="icon">
+            <i class="icon-th-list"></i>
+          </span>
+          <h5>${ _('Anonymous usage analytics') }</h5>
+        </div>
+        <div class="widget-content" style="padding-left: 14px">
+          <label class="checkbox">
+          <input id="analyticsBtn" type="checkbox" name="analytics" style="margin-right: 10px" title="${ ('Check to enable usage analytics') }">
+              ${ ('Help improve Hue with anonymous usage analytics.') } <a href="javascript:void(0)" style="display: inline" data-trigger="hover" data-toggle="popover" data-placement="right" rel="popover" title="${_('How does it work?') }" data-content="${ ('We are using Google Analytics to track how many times an application or specific section of an application is used, nothing more.') }" ><i class="icon-question-sign"></i></a>
+            </label>
+        </div>
+      </div>      
     </div>
 
     <div id="step4" class="stepDetails hide">
@@ -162,6 +179,8 @@ ${ commonheader(_('Quick Start'), "quick_start", user, "100px") | n,unicode }
 <script type="text/javascript" charset="utf-8">
 $(document).ready(function(){
 
+  $("[rel='popover']").popover();
+
   $(".installBtn").click(function() {
     var button = $(this);
     $(button).button('loading');
@@ -226,6 +245,12 @@ $(document).ready(function(){
       routie("step" + nextStep);
     }
   });
+  
+  $("#analyticsBtn").click(function () {
+    $.post("${ url('about:collect_usage') }", function(data) {
+      $.jHueNotify.info(data);
+    });    
+  });
 });
 </script>
 % endif

+ 2 - 0
apps/about/src/about/urls.py

@@ -20,4 +20,6 @@ from django.conf.urls.defaults import patterns, url
 urlpatterns = patterns('about.views',
   url(r'^$', 'admin_wizard', name='index'),
   url(r'^admin_wizard$', 'admin_wizard', name='admin_wizard'),
+  
+  url(r'^collect_usage$', 'collect_usage', name='collect_usage'),
 )

+ 21 - 0
apps/about/src/about/views.py

@@ -15,9 +15,17 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+try:
+  import json
+except ImportError:
+  import simplejson as json
+
 from django.conf import settings
+from django.http import HttpResponse
+from django.utils.translation import ugettext as _
 
 from desktop.lib.django_util import render
+from desktop.models import Settings
 from desktop.views import check_config
 from desktop import appmanager
 
@@ -33,3 +41,16 @@ def admin_wizard(request):
       'app_names': app_names,
   })
 
+
+def collect_usage(request):
+  response = {'status': -1, 'data': ''}
+
+  if request.method == 'POST':
+    settings, created = Settings.objects.get_or_create(id=1)
+    settings.usage_collection = request.POST.get('analytics')
+    settings.save()
+    response['status'] = 0
+  else:
+    response['data'] = _('POST request required.')
+      
+  return HttpResponse(json.dumps(response), mimetype="application/json")

+ 6 - 3
desktop/core/src/desktop/models.py

@@ -14,14 +14,17 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-"""
-Extra models related to Desktop users.
-"""
+
 from django.db import models
 from django.contrib.auth import models as auth_models
 
+
 class UserPreferences(models.Model):
   """Holds arbitrary key/value strings."""
   user = models.ForeignKey(auth_models.User)
   key = models.CharField(max_length=20)
   value = models.TextField(max_length=4096)
+
+
+class Settings(models.Model):
+  usage_collection = models.BooleanField(db_index=True, default=True)

+ 37 - 0
desktop/core/src/desktop/templates/common_footer.html

@@ -96,6 +96,43 @@ limitations under the License.
       function resetPrimaryButtonsStatus() {
         $(".btn-primary:not(.disable-feedback), .btn-danger:not(.disable-feedback)").button("reset");
       }
+
+      {% if display_analytics %}
+
+      var _gaq = _gaq || [];
+      _gaq.push(['_setAccount', 'UA-37637545-1']);
+
+      var _pathName = location.pathname;
+      if (_pathName.indexOf("oozie") > -1){
+        if (_pathName.indexOf("list_oozie_") > -1 || _pathName == "/oozie/"){
+          _pathName = "oozie/dashboard";
+        }
+        else {
+          if (_pathName.indexOf("workflow") > -1){
+            _pathName = "oozie/workflows";
+          }
+          else if (_pathName.indexOf("coordinator") > -1){
+            _pathName = "oozie/coordinators";
+          }
+          else {
+            _pathName = "oozie/bundles";
+          }
+        }
+      }
+      else {
+        _pathName = _pathName.substr(1).split("/")[0];
+      }
+
+      _gaq.push(['_trackPageview', '/remote/{{ version }}/' + _pathName]);
+
+      (function() {
+        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+      })();
+
+      {% endif %}
+
     </script>
 
 	</body>

+ 6 - 1
desktop/core/src/desktop/views.py

@@ -23,6 +23,7 @@ import time
 import traceback
 import zipfile
 
+from django.conf import settings
 from django.shortcuts import render_to_response
 from django.http import HttpResponse
 from django.core.urlresolvers import reverse
@@ -315,7 +316,11 @@ def commonfooter(messages=None):
   """
   if messages is None:
     messages = {}
-  return render_to_string("common_footer.html", {'messages': messages})
+  return render_to_string("common_footer.html", {
+    'messages': messages,
+    'version': settings.HUE_DESKTOP_VERSION,
+    'display_analytics': True
+  })
 
 
 # If the app's conf.py has a config_validator() method, call it.