Skip to content

Instantly share code, notes, and snippets.

@timmyc
Created September 13, 2012 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timmyc/3715575 to your computer and use it in GitHub Desktop.
Save timmyc/3715575 to your computer and use it in GitHub Desktop.
Highcharts + Clicky Mashup
$("#clicky-chart").click(function(){
var sd = '<%= @sd.to_date %>';
var ed = '<%= @ed.to_date %>';
$(this).hide();
$.getJSON('http://api.getclicky.com/api/stats/4?site_id=<%= @store.clicky %>&sitekey=<%= @store.clicky_key %>&type=traffic-sources&date=' + sd + ',' + ed + '&output=json&json_callback=?',function(data){
var sources = data[0].dates[0].items;
var series_data = [];
for(var i=0; i<sources.length; i++){
var source = sources[i];
series_data.push({
name: source.title,
revenue: source.revenue,
conversions: source.conversions,
y: isNaN(parseInt(source.revenue)) ? 0 : parseInt(source.revenue),
conversion_percent: source.conversion_percent,
clicky: source,
events: {
click: function(){
window.open(this.clicky.stats_url + '&goal=Purchase');
}
}
})
}
var chart = new Highcharts.Chart({
chart: {
renderTo: 'chart',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'Conversion Sources'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
formatter: function() {
if(this.point.config.revenue){
return '<b>'+ this.point.name +'</b>: ' + this.point.config.conversions + ' conversions - $'+ this.point.config.revenue;
}else{
return '<b>' + this.point.name +'</b>: $0';
}
}
}
}
},
series: [{
type: 'pie',
name: 'Conversion Sources',
tooltip: { enabled: false },
data: series_data
}]
});
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment