Commits

Josh VanderLinden committed 5f1c813

Started working on the graphing/analytics request. GC #16

Comments (0)

Files changed (6)

 # -*- coding: utf-8 -*-
 
 from setuptools import setup, find_packages
-import sys, os
 import tracking
 
+requires = ['django>=1.1.0', 'pyofc2']
+
 setup(
     name='django-tracking',
     version=tracking.get_version(),
     url='http://bitbucket.org/codekoala/django-tracking',
     license='MIT',
     package_dir={'tracking': 'tracking'},
+    install_requires=requires,
     include_package_data=True,
     packages=find_packages(),
     classifiers=[

tracking/__init__.py

 import listeners
 
-VERSION = (0, 3, 7)
+VERSION = (0, 4, 0)
 
 def get_version():
     "Returns the version as a human-format string."

tracking/media/tracking/swf/swfobject_2_2.zip

Binary file added.

tracking/templates/admin/tracking/analytics_home.html

+{% extends 'admin/base_site.html' %}
+{% load i18n %}
+
+{% block title %}{% trans "Analytics Home" %}{% endblock %}
+
+{% block extrahead %}{{ block.super }}
+<script type="text/javascript" src="{{ MEDIA_URL }}swf/swfobject.js"></script>
+<script type="text/javascript">
+swfobject.embedSWF(
+    "{{ MEDIA_URL }}swf/open-flash-chart.swf", "views_chart",
+    "820", "400", "9.0.0", "/static/expressInstall.swf",
+    {"data-file":"{% url tracking-analytics-views %}"}
+);
+
+swfobject.embedSWF(
+    "{{ MEDIA_URL }}swf/open-flash-chart.swf", "visitors_chart",
+    "820", "400", "9.0.0", "{{ MEDIA_URL }}swf/expressInstall.swf",
+    {"data-file":"{% url tracking-analytics-visitors %}"}
+);
+</script>
+{% endblock %}
+
+{% block content %}
+<table id="django-tracking-analytics">
+    <tr>
+        <th>{% trans "Page Views" %}</th>
+        <th>{% trans "Visitors" %}</th>
+    </tr>
+    <tr>
+        <td class="chart" id="views_chart">{{ views_chart.render }}</td>
+        <td class="chart" id="visitors_chart">{{ visitors_chart.render }}</td>
+    </tr>
+</table>
+{% endblock %}
 urlpatterns = patterns('',
     url(r'^refresh/$', views.update_active_users, name='tracking-refresh-active-users'),
     url(r'^refresh/json/$', views.get_active_users, name='tracking-get-active-users'),
+
+    # django-tracking analytics
+    url(r'^analytics/views/$', views._page_views, name='tracking-analytics-views'),
+    url(r'^analytics/visitors/$', views._page_visitors, name='tracking-analytics-visitors'),
+    url(r'^analytics/$', views.analytics_home, name='tracking-analytics-home'),
 )
 
 if getattr(settings, 'TRACKING_USE_GEOIP', False):

tracking/views.py

 from django.http import Http404, HttpResponse
 from django.shortcuts import render_to_response
 from django.template import RequestContext, Context, loader
+from django.utils.translation import ugettext_lazy as _
 from django.utils.simplejson import JSONEncoder
-from django.utils.translation import ungettext
+from django.utils.translation import ungettext_lazy, ugettext_lazy as _
 from django.views.decorators.cache import never_cache
+import pyofc2
+
 from tracking.models import Visitor
 from tracking.utils import u_clean as uc
 
                               {'GOOGLE_MAPS_KEY': GOOGLE_MAPS_KEY,
                                'template': extends_template},
                               context_instance=RequestContext(request))
+
+###
+# ANALYTICS
+###
+def analytics_home(request):
+    """Presents the user with some options for viewing analytics information"""
+
+    """
+    graph breaking down daily/weekly/monthly visits.
+    visits over time in a day
+    average peak times
+    top referrers graph (top X number of referrers)
+    download tracking
+    """
+
+    context = RequestContext(request, {
+    })
+
+    return render_to_response('admin/tracking/analytics_home.html', context)
+
+def _page_views(request):
+    """Returns information about page views"""
+
+    chart = pyofc2.open_flash_chart()
+    chart.title = pyofc2.title(text=_('Page Views'))
+
+    return HttpResponse(content=chart.render(), mimetype='text/json')
+
+def _page_visitors(request):
+    """Returns information about visitors"""
+
+    chart = pyofc2.open_flash_chart()
+    chart.title = pyofc2.title(text=_('Visitors'))
+
+    return HttpResponse(content=chart.render(), mimetype='text/json')