Navigation Menu

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: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: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: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: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: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: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:15204426171990e5ceb3
Last active August 29, 2015 14:10
Keen IO Query Example: Users who did X action C times from D1 to D2, with filters
# Scenario:
We want all users who did event X,
where event X had property Y and Z with values A and B,
where event X happened C times within the dates D1 and D2.
# Solution:
You can arrive at the final result using this query:
var users_who_did_x = new Keen.Query("count", {
@wetzler
wetzler / gist:bf72167d348be7304e97
Created December 8, 2014 03:56
How to use multiple counts to achieve an OR filter on arrayed values in Keen IO (even though we don't recommend arrays if possible!)
// example event model
// User_Created_Event = {
// "full_name": "Macy Bode",
// "communities": [6,7,8],
// "email": "dev@dev.com"
// },
// Find the number of users in Community 6 or 7
@wetzler
wetzler / gist:40459f02ab3da0cdfe22
Last active August 29, 2015 14:11
AdTech Funnel Example - Click and Purchase Conversion, Attribution Analysis
Funnels are a way to do mass lookups of users to see which ones who did X also did Y.
Funnels are Keen IO queries formatted like this:
https://api.keen.io/3.0/projects/<project_id>/queries/funnel?api_key=<read_key>&steps=<[step1, step2, step3...]>
Each 'step' is an action performed by the actor.
Say you want to know if a thousands of users who made a purchase had previously clicked on something on your site.
As an alternative checking if each user did an action, we can lookup a huge group at once using Funnels.
Below is a funnel example that can be done as long as the following are true:
@wetzler
wetzler / gist:29e830f83d3b4caa83f4
Last active August 29, 2015 14:16
Keen IO OR Funnel Logic
Say you want to know, of all of the users who signed up, how many CREATED a post _OR_ RESPONDED to a post?
There is no built-in "OR" functionality in Keen IO funnels, but there is a way to use a little bit of logic to get the same result.
This imaginary funnel's steps might look like this:
"steps":[
{
"event_collection":"signed_up",
"actor_property":"user.id"
},