Skip to content

Instantly share code, notes, and snippets.

@wetzler
Last active September 4, 2015 22:48
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 wetzler/11158767 to your computer and use it in GitHub Desktop.
Save wetzler/11158767 to your computer and use it in GitHub Desktop.
Generate a Keen IO Funnel Chart for game levels or user training steps. Calls on the Keen IO API using the Keen IO JavaScript library.
var Keen=Keen||{configure:function(e){this._cf=e},addEvent:function(e,t,n,i){this._eq=this._eq||[],this._eq.push([e,t,n,i])},setGlobalProperties:function(e){this._gp=e},onChartsReady:function(e){this._ocrq=this._ocrq||[],this._ocrq.push(e)}};(function(){var e=document.createElement("script");e.type="text/javascript",e.async=!0,e.src=("https:"==document.location.protocol?"https://":"http://")+"dc8na2hxrj29i.cloudfront.net/code/keen-2.1.0.js";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)})();
Keen.configure({ // configure the Keen Client
projectId: projectId,
readKey: readKey
});
Keen.onChartsReady(function() {
var numLevels = 10
var funnelSteps = prepareFunnel(numLevels)
function prepareFunnel(numLevels) {
var steps = []
i=0
while (i < numsLevels) {
var step = new Keen.Step("level_start", {
name: "Level " + String(i + 1),
timeframe: "last_7_days",
filters: [{property_name: "level", operator: "eq", property_value: i + 1}]
});
steps[i] = step
i++;
}
return steps
}
var myFunnel = new Keen.Funnel(funnelSteps, {
actorProperty: "player_id"
});
//Create a Funnel Chart visualization for that funnel.
var myFunnelChart = new Keen.FunnelChart(myFunnel, {
height: chartHeight,
width: 600,
chartAreaWidth: chartAreaWidth,
chartAreaLeft: chartAreaLeft,
xAxisLabelAngle: xAxisLabelAngle,
title: "Levels Progression (last 7 days)"
});
myFunnelChart.draw(document.getElementById('chart6A'));
});
@jonathanmv
Copy link

Could you please help me out and share some instructions to use your gist please. I couldn't make it work. Thank you very much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment