Recipes
From CKAN
Contents |
Set your Google Analytics
Just add the google analytics tracking code to your templates using the ckan.template_footer_end config option:
ckan.template_footer_end = <script src='http://www.google-analytics.com/ga.js' type='text/javascript'></script> <script type="text/javascript"> try { var pageTracker = _gat._getTracker("XXXXX"); pageTracker._setDomainName(".ckan.net"); pageTracker._trackPageview(); } catch(err) {} </script> <script src="/scripts/package.js"></script>
You need to replace XXXX with your google analytics tracking code.
Tag Cloud
How to create a tag cloud (e.g. on the front page).
Using SOLR
NB: This only works when the search mechanism is SOLR. This is the default for CKAN 1.5+. Needs to be set-up for earlier CKANs.
- This example requires jquery.tagcloud.js but could easily be changed to any tagcloud js lib.
Config file
ckan.template_footer_end =
<script src="/scripts/jquery.tagcloud.js"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$.fn.tagcloud.defaults = {
size: {start: 10, end: 32, unit: "pt"},
color: {start: '#af8', end: '#f52'}
};
$("#tagcloud a").tagcloud();
})
</script>
<style type="text/css">
#tagcloud * {
display: inline-block;
vertical-align: middle;
line-height: 0.9;
}
#tagcloud a {
text-decoration: none;
}
#tagcloud a:hover {
text-decoration: underline;
}
#tagcloud {
margin: 25px auto;
text-align: center;
}
</style>
In the main content section of the page
<py:if test="len(c.facets.get('tags', {}))">
<h4>Top Tags</h4>
<div id="tagcloud">
<py:for each="tag_name, count in c.facets.get('tags', {}).items()">
<a rel="${count}" title="${count}" href="${h.url_for(controller='tag',
action='read', id=tag_name)}">${tag_name}</a>
</py:for>
</div>
<hr />
</py:if>
Install the script
Get jquery.tagcloud.js and put it in the ckan/public/scripts/ directory.
Using API call
There is another way of doing a tag cloud - we have an API call here: /api/tag_counts that provides the data. I'm sure someone here can provide the javascript to finish off this recipe.