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:58effe995e42e6c31888
Created July 21, 2014 23:23
Example of sending an event
<!DOCTYPE html>
<html lang='en'>
<head>
<title>Send Event Test</title>
<script type="text/javascript">
!function(a,b){if(void 0===b[a]){b["_"+a]={},b[a]=function(c){b["_"+a].clients=b["_"+a].clients||{},b["_"+a].clients[c.projectId]=this,this._config=c},b[a].ready=function(c){b["_"+a].ready=b["_"+a].ready||[],b["_"+a].ready.push(c)};for(var c=["addEvent","setGlobalProperties","trackExternalLink","on"],d=0;d<c.length;d++){var e=c[d],f=function(a){return function(){return this["_"+a]=this["_"+a]||[],this["_"+a].push(arguments),this}};b[a].prototype[e]=f(e)}var g=document.createElement("script");g.type="text/javascript",g.async=!0,g.src="https://d26b395fwzu5fz.cloudfront.net/3.0.4/keen.min.js";var h=document.getElementsByTagName("script")[0];h.parentNode.insertBefore(g,h)}}("Keen",this);
</script>
<script>
var logger = new Keen({
@wetzler
wetzler / gist:2ef7d45072cf4d92c16f
Last active August 29, 2015 14:04
Pull and sort of bunch of session events from Keen IO
require 'rubygems'
require 'net/http' # This is probably not needed, did not validate which things are truly required...
require 'net/https'
require 'keen'
require 'json'
require 'date'
require 'time'
require 'set'
NUM_LATEST_SESSIONS = 1000
@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:cf03b70696136f874643
Last active August 29, 2015 14:03
put all queries under one function
<!DOCTYPE html>
<html lang='en'>
<head>
<title>Retention</title>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.js'></script>
<script src="https://d26b395fwzu5fz.cloudfront.net/latest/keen.min.js"></script>
<script>
// This brings in the Keen javascript library
!function(a,b){if(void 0===b[a]){b["_"+a]={},b[a]=function(c){b["_"+a].clients=b["_"+a].clients||{},b["_"+a].clients[c.projectId]=this,this._config=c},b[a].ready=function(c){b["_"+a].ready=b["_"+a].ready||[],b["_"+a].ready.push(c)};for(var c=["addEvent","setGlobalProperties","trackExternalLink","on"],d=0;d<c.length;d++){var e=c[d],f=function(a){return function(){return this["_"+a]=this["_"+a]||[],this["_"+a].push(arguments),this}};b[a].prototype[e]=f(e)}var g=document.createElement("script");g.type="text/javascript",g.async=!0,g.src="https://d26b395fwzu5fz.cloudfront.net/3.0.4/keen.min.js";var h=document.getElementsByTagName("script")[0];h.parentNode.insertBefore(g,h)}}("Keen",this);
@wetzler
wetzler / gist:bf6b24018a7d4b1b7190
Created July 10, 2014 02:23
Keen IO retention script using V3 of the JavaScript library
<script src="https://d26b395fwzu5fz.cloudfront.net/latest/keen.min.js"></script>
<script>
var projectId = "proj";
var readKey = "key";
var client = new Keen({
projectId: projectId,
readKey: readKey
});
@wetzler
wetzler / gist:4befe1a8afdaa2429702
Last active August 29, 2015 14:02
Mashup two Keen IO queries using Keen IO JS library v3
Keen.ready(function(){
// ----------------------------------------
// Total Session Count
// How it works:
// Given a timeframe, calculate the number of unique session IDs found in the collection "screen_view"
// We use the "screen_view" collection because we know there is at least 1 screenview for every session.
// ----------------------------------------
var sessions_count = new Keen.Query("count_unique", {
eventCollection: "screen_view",
@wetzler
wetzler / gist:df3537e0fb63602be996
Last active August 29, 2015 14:02
Pushpop script to check for 1) New users and 2) Newly active users sending data for the first time in 7 days
#!/usr/bin/env ruby
TEMPLATES_DIRECTORY = File.expand_path('../templates', __FILE__)
require 'date'
require 'pushpop'
require 'active_support/all' #for datetime calculation e.g. weeks.ago.at_beginning_of_week
job do
@wetzler
wetzler / gist:f1dc8fe3cf0270fc9d34
Created May 27, 2014 23:35
This gist uses Keen IO conversion funnels to generate a line chart showing conversion over time. In this example we'll chart the number of video viewing sessions that make it past the 25%, 50%, 75%, and 100% mark in the video. The end result is a multiline chart with one line for each view marker (25%, 50%, 75%, 100%). This chart helps you answe…
Keen.onChartsReady(function(){
var dataPointsInChart = 7 // Number of days in your line chart
calculateConversionTrend(dataPointsInChart, "conversionLineChart")
function calculateConversionTrend(dataPointsInChart, div) {
var dataForLineChart = []
var i = 0
while (i < dataPointsInChart) {
@wetzler
wetzler / gist:19465e0e283e0f25d605
Created May 27, 2014 21:53
This gist uses Keen IO conversion funnels to generate a line chart showing conversion over time. In this example we'll chart the number of video viewing sessions that make it past the 50% mark in the video.
Keen.onChartsReady(function() {
var dataPointsInChart = 7 // Number of days in your line chart
calculateConversionTrend(dataPointsInChart, "conversionLineChart")
function calculateConversionTrend(dataPointsInChart, div) {
var dataForLineChart = []
var i = 0
while (i < dataPointsInChart) {
@wetzler
wetzler / gist:11160518
Created April 21, 2014 23:50
Most basic ever gaming dashboard template!
<!DOCTYPE html>
<html lang='en'>
<head>
<script>
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-min.js";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)})();
// Configure the Keen Client
Keen.configure({
projectId: "<your project ID>",
readKey: "<your read key>"