[ckan-dev] internal tracking

Toby Dacre toby.okfn at gmail.com
Fri Jul 13 11:24:15 UTC 2012


These are some rough notes prior to fuller docs


to enable the internal analytics

we need the following config in our .ini file

ckan.tracking_enabled = true


we need the following code in layout_base.html  (is in master) but needs
adding to customised template if used
** I should move this into a snippet - I'll do this today

<py:if test="h.asbool(config.get('ckan.tracking_enabled', 'false'))">
  <script type="text/javascript">
         $(function (){
                 // Tracking
				 var url = location.pathname;
				 // remove any site root from url
				 url = url.substring(CKAN.SITE_URL.length, url.length);
				 // trim any trailing /
				 url = url.replace(/\/*$/, '');
				 $.ajax({url : CKAN.SITE_URL_NO_LOCALE + '/_tracking',
						 type : 'POST',
						 data : {url:url, type:'page'},
						 timeout : 300 });
                 $('a.resource-url-analytics').click(function (e){
                         var url = $(e.target).closest('a').attr('href');
						 $.ajax({url : CKAN.SITE_URL_NO_LOCALE + '/_tracking',
							     data : {url:url, type:'resource'},
								 type : 'POST',
								 complete : function () {location.href = url;},
								 timeout : 30});
                         e.preventDefault();
                         });
                 });
  </script>
  </py:if>


updating the stats
we need a cron job that runs the updates - this will initially try updating
any tracking data - after that it will just update for the last few days

paster tracking -c development.ini
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20120713/14de2d9e/attachment.html>


More information about the ckan-dev mailing list