Last active
September 4, 2015 22:48
-
-
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.
This file contains 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 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')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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