Skip to content

Instantly share code, notes, and snippets.

@dustinlarimer
dustinlarimer / pie.js
Last active August 29, 2015 13:56
Pie Charts for Keen IO with NVD3.js
// Pie Charts for Keen IO with NVD3.js
// Load and configure the client
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.2-min.js";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)})();
Keen.configure({
projectId: 'your_project_id',
readKey: 'your_read_key'
});
// Query: count events, grouped by type/category
@dustinlarimer
dustinlarimer / README.md
Last active August 29, 2015 13:57
GeoCharts with Keen IO

GeoCharts with Keen IO

This recipe uses geographic properties generated by the ip_to_geo data enrichment addon.

If you would like to activate this addon for your project, just ask!

The team is available in HipChat, IRC, or at contact@keen.io.

@dustinlarimer
dustinlarimer / Git-Beacon.md
Last active August 29, 2015 13:57
Sample redirect badge and image beacon for tracking Github repo visits

Badge (redirect)

Example: DO NOT USE :)

[![RepoStats](https://api.keen.io/3.0/projects/<your_project_id>/events/visit?api_key=<your_write_key>&data=<base64_encoded_data>&redirect=http://img.shields.io/badge/Stats-Keen%20IO-blue.svg)](https://github.com/<your_repo_slug>)

Beacon (pixel)

<!DOCTYPE html>
<html>
<head>
<title>Gist for Keen IO JS Library</title>
<script src="http://d26b395fwzu5fz.cloudfront.net/3.0.0/keen.min.js"></script>
<script>
var client = new Keen({
projectId: "5368fa5436bf5a5623000000",
readKey: "3f324dcb5636316d6865ab0ebbbbc725224c7f8f3e8899c7733439965d6d4a2c7f13bf7765458790bd50ec76b4361687f51cf626314585dc246bb51aeb455c0a1dd6ce77a993d9c953c5fc554d1d3530ca5d17bdc6d1333ef3d8146a990c79435bb2c7d936f259a22647a75407921056"
@dustinlarimer
dustinlarimer / google-apps-script.js
Last active August 29, 2015 14:02
Set up an IFTTT Gmail recipe that appends messages to Google Spreadsheet. Next, paste this script into that spreadsheet's Script Editor, and set a new trigger to fire when the document is changed.
/*
Spreadsheet Rows:
-----------------------------
A: timestamp (not used here)
B: from
C: subject
D: label
E: attachment name
F: attachment url
*/
@dustinlarimer
dustinlarimer / keen-custom-funnels.js
Created August 7, 2014 21:18
Add percentage values to funnel steps
// var client = new Keen({...})
// var funnel = new Keen.Query("funnel", {...});
client.run(funnel, function(res){
var data = res;
var labelMap = {
// Keys = eventCollection for each step
// Values = what you want them to say instead..
// Percentage will be appended to values
"pageview" : "Visit",
@dustinlarimer
dustinlarimer / loader.js
Last active August 29, 2015 14:06
Refactored the keen-js async paste-in script, to make the namespace and version number more accessible :)
!function(i,o){i("Keen","/3.1.0/keen.min.js",o)}(function(a,b,c){var d,e,f;c["_"+a]={},c[a]=function(b){c["_"+a].clients=c["_"+a].clients||{},c["_"+a].clients[b.projectId]=this,this._config=b},c[a].ready=function(b){c["_"+a].ready=c["_"+a].ready||[],c["_"+a].ready.push(b)},d=["addEvent","setGlobalProperties","trackExternalLink","on"];for(var g=0;g<d.length;g++){var h=d[g],i=function(a){return function(){return this["_"+a]=this["_"+a]||[],this["_"+a].push(arguments),this}};c[a].prototype[h]=i(h)}e=document.createElement("script"),e.async=!0,e.src=b,f=document.getElementsByTagName("script")[0],f.parentNode.insertBefore(e,f)},this);
(function(i,o){i("Keen","/3.1.0/keen.min.js",o);}(function(t,h,x){
// t = context
// h = file
// x = context
// console.log(t,h,x===window);
var methods, script, tag;
// _Keen cache
@dustinlarimer
dustinlarimer / tracking-plugin.js
Last active August 29, 2015 14:10
Auto-tracker
function _go(f){/in/.test(document.readyState)?setTimeout('_go('+f+')',9):f()}
_go(function(){
var COOKIE_KEY = "COOKIE-ID",
COOKIE_EXP = undefined, // 1000*60*60*24*365,
IS_KNOWN = false;
var CurrentSession = {},
wpMeta = WP_META || {},
interval;
# POST many events
$ curl https://api.keen.io/3.0/projects/<PROJECT_ID>/events \
    -H 'Authorization: <WRITE_KEY>' \
    -H 'Content-Type: application/json' \
    -d '{
      "purchases": [
        {
          "item_id": "f9802334-23423",
          "customer": "janet.username@gmail.com",
@dustinlarimer
dustinlarimer / README.md
Last active October 8, 2015 16:45
API Read Key for NYTimes' data dump of Military Surplus Gear flowing to local police departments

Military Surplus Gear, published here

API credentials for read-access:

Project ID: 53f3eca97d8cb91b75000000

API Key (read-only): df6ff0ff414bc286b91e2661db4c691c45b6aea8d2c8cf2393169e9b9ef36a3d77e59c57b540febc8f328bf1f605782d9035c4a7072dc86c4f96ddbcce7dfe0b088ae51dd2ea36ad022290d1f3580e2d1ea202845ae7f79e7db6634ee627a26197dadf7eb2e5a46b16f04a4cae55955e

Sample dashboard here, JS source here