Skip to content

Instantly share code, notes, and snippets.

View wetzler's full-sized avatar

Michelle Wetzler wetzler

  • Bay Area, California
View GitHub Profile
@wetzler
wetzler / gist:e9f0bdf8271a60f5e8dd
Created April 7, 2015 17:08
Count event totals for all of your Keen collections
require 'dotenv'
require 'keen'
# Don't forget to specify your Keen Master Key, Ready Key, and Project ID in your environment variables!
# Reference: https://github.com/keenlabs/keen-gem
Dotenv.load
# allow timeframe to be specified via the command line
# usage: ruby collection_counts.rb previous_7_days
@wetzler
wetzler / gist:11158767
Last active September 4, 2015 22:48
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)
@wetzler
wetzler / gist:8986385
Created February 13, 2014 23:44
Pseudocode for making a cumulative line chart with Keen IO series data. Use this to make a running total of users, for example. The gist assumes that the timeframe being queried includes all of the data.
Keen.onChartsReady(function() {
var series = new Keen.Series("registrations", {
analysisType: "count",
timeframe: "last_30_weeks",
interval: "weekly"
});
series.getResponse(function(response){
keenData = response.result;
@wetzler
wetzler / gist:4f70beaed4010173810f
Created July 15, 2014 20:13
Recipe for Keen IO line chart with cumulative data (V2 Of Keen JS library)
-------------------------------
Line Chart with Cumulative Data
-------------------------------
This is an example for how you can create a line chart with data that is shown cumulatively.
.. note::
This example is current for our JS SDK v2.1.2 only. It does not apply to v3+
.. code-block:: javascript
@wetzler
wetzler / gist:4478332
Last active December 10, 2015 18:58
Kickfolio's (minified) code to embed Keen IO charts in their user dashboards. They have 3 line charts (last 7 days, last 24 hours, and last 4 weeks) which show the number of user "connect" sessions for a given app (identified by the filter app.PublicKey). For more context, see this blog post: http://blog.keen.io/post/39950174904/kickfolio-uses-k…
Keen.configure(window.ENV.keenProjectId,window.ENV.keenApiKey),
Keen.onChartsReady(function(){
var e=new Keen.Series("connect",{
analysisType:"count",
timeframe:"last_7_days",
interval:"daily"
}),
t=new Keen.Series("connect",{
@wetzler
wetzler / gist:5210061
Last active December 15, 2015 05:38
This script creates a retention funnel query in Keen IO and outputs both the funnel query name and the results of the query.
require 'rubygems'
require 'net/http'
require 'net/https'
require 'uri'
require 'json'
require 'date'
require 'active_support/all' #for datetime calculation e.g. weeks.ago.at_beginning_of_week
# Keen Project Info
$projectID = "your project ID"
@wetzler
wetzler / gist:6816497
Last active December 24, 2015 14:59
Here's how you can get query results for two Keen IO series, in parallel, and then combine them in one multiline chart.I really want to rewrite this to run N queries at a time, but this works for now.
Keen.configure({
projectId: id,
readKey: key
});
// Timeframe parameters for queries
var timeframe = "last_14_days"
var interval = "daily"
Keen.onChartsReady(function(){
@wetzler
wetzler / gist:7541840
Created November 19, 2013 07:56
This script runs a group_by query and outputs the results to a CSV
require 'rubygems'
require 'net/http'
require 'net/https'
require 'keen'
require 'uri'
require 'json'
require 'date'
# This script runs a group_by query and outputs the results to a CSV
#================================oOo===================================
Keen.ready(function(){
signup_flow = new Keen.Query("funnel", {
timeframe: {
start: "2015-07-01T07:00:00.000Z" // analyze events after this date
},
steps: [
{
event_collection: "view_page",
actor_property: "visitor_id",
filters: [
trial_step_complete_tutorial = {
"trial" : {
"name" : "AppSpandexTrial",
"day_in_trial": 2,
"trial_total_duration_in_days": 14,
"category":"product_trial_type_A"
},
"user" : {
"visitor_id": "029309n90nf0w9f3n4qf2nf",
"email": "michelle@keen.io",