Skip to content

Instantly share code, notes, and snippets.

View ttrefren's full-sized avatar

Tim Trefren ttrefren

  • Oakland, CA
View GitHub Profile
function onYouTubePlayerReady(playerId) {
ytplayer = document.getElementById("myytplayer");
ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
}
function onytplayerStateChange(newState) {
ytplayer = document.getElementById("myytplayer");
var props = {};
props['duration'] = ytplayer.getDuration();
on run argv
tell application "iTerm"
activate
global hostname
set hostname to "dev"
if length of argv is 1 then
set hostname to item 1 of argv
end if
set term to (make new terminal)
tell term
// Plain Javascript - only works for a single item per page
window.onload = function() {
mpmetrics.track("Page view", { 'page': document.location });
}
// Or in jQuery (much nicer)
$(document).ready(function() {
mpmetrics.track("Page view", { 'page': document.location });
});
...
<!-- The rest of your HTML code here -->
<input type="button" onclick="mpmetrics.track('play-song', {'genre':'rap', 'artist':'eminem'});">
<script type="text/javascript" src="http://api.mixpanel.com/site_media/js/api/mpmetrics.js"></script>
<script type="text/javascript">
try { mpmetrics.init("YOUR_TOKEN");} catch(err) {}
</script>
...
...
<!-- The rest of your HTML code here -->
<input type="button" onclick="mpmetrics.track('game-start', {'level':'castle', 'char':'knight'})">
your_function = function(url, data) {
mpmetrics.track('battle', {'spell':'fireball', 'damage':'237'});
if (url) {
some = more_random_js;
} else {
even += "more";
}
...
# This isn't perfect for high traffic sites, if you need something more production ready
# please tell us or stay tuned as we will open it up shortly.
import subprocess
import base64
import simplejson
def track(event, properties=None):
"""
A simple function for asynchronously logging to the mixpanel.com API.
require 'rubygems'
require 'base64'
require 'json'
require 'active_support'
# Adapted from the Python code here: http://mixpanel.com/api/docs/code/
class MixPanel
# A simple function for asynchronously logging to the mixpanel.com API.
# This function requires `curl`.
<script type="text/javascript" src="http://mixpanel.com/site_media/js/api/mpmetrics.js"></script>
<script type="text/javascript">
try {
mpmetrics.init("YOUR_TOKEN");
mpmetrics.register({"user type": "noob", "gender": "male"});
} catch(err) {}
</script>