Skip to content

Instantly share code, notes, and snippets.

@dustinlarimer
Created August 7, 2014 21:18
Show Gist options
  • Save dustinlarimer/45387577d05a05203838 to your computer and use it in GitHub Desktop.
Save dustinlarimer/45387577d05a05203838 to your computer and use it in GitHub Desktop.
Add percentage values to funnel steps
// var client = new Keen({...})
// var funnel = new Keen.Query("funnel", {...});
client.run(funnel, function(res){
var data = res;
var labelMap = {
// Keys = eventCollection for each step
// Values = what you want them to say instead..
// Percentage will be appended to values
"pageview" : "Visit",
"viewed_twentyfive" : "Viewed 1/4",
"viewed_fifty" : "Viewed 1/2",
"viewed_seventyfive" : "Viewed 3/4",
"viewed_all" : "Viewed All"
};
Keen.utils.each(res.result, function(step, index){
var original = res.steps[index].event_collection;
var initial = res.result[0];
var diff = parseInt(res.result[index]) / parseInt(initial) * 100;
// Append percentage value to label map
labelMap[original] += " (" + diff.toFixed(0) + "%)";
});
// Log these out for debugging
console.log(data, labelMap);
// pass data object into a new visualization (must define lib/type)
new Keen.Visualization(data, document.getElementById("funnel"), {
library: "google",
chartType: "barchart",
labelMapping: labelMap
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment