Created
August 7, 2014 21:18
-
-
Save dustinlarimer/45387577d05a05203838 to your computer and use it in GitHub Desktop.
Add percentage values to funnel steps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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