The easiest way to create stats is directly in your code. You just add a line of code with the new stat name. When StatHat receives the first data point, it will create the stat for you. We have libraries for a lot of languages to make it easy.

StatHat stats come in two flavors: counter and value. Counter stats are summed up over time. Value stats are averaged over time.

An example of a counter stat would be user created. Every time a user is created, you would send StatHat a count of 1. Then you could see how many users were created over the past hour, day, week, month, year.

An example value stat is sign in - age of user. Any time someone signs in, you would send StatHat their age. Looking at this stat would show you the average age of your active users and how it varies with time.

The code is a bit different depending on if the stat is a counter or value, so select the stat type for your stat first:

Select a language:

Install the gem:

gem install stathat

Copy and paste this code into your application:

StatHat::API.ez_post_count('user created', 'YOUR_EZKEY', 1)
StatHat::API.ez_post_value('sign in - age of user', 'YOUR_EZKEY', 27.0)

Download stathat.py and put it in your import path.

Include it in your code:

from stathat import StatHat

Copy and paste this code into your application:

stathat.ez_post_count('YOUR_EZKEY', 'user created', 1)
stathat.ez_post_value('YOUR_EZKEY', 'sign in - age of user', 27.0)

Download StatHat.h and StatHat.m from github and put them in your project. There are no other dependencies.

Include the header file in your code:

#import "StatHat.h"

Copy and paste this code into your application:

[StatHat postEZStat:@"user created" withCount:1.0 forUser:@"YOUR_EZKEY" delegate:self];
[StatHat postEZStat:@"sign in - age of user" withValue:27.0 forUser:@"YOUR_EZKEY" delegate:self];

Using the EZ API with HTML is discouraged as it would expose your key. For HTML, we recommend using the Classic API. You need to create each stat individually on this page.

Download stathat.php and put it in your import path.

Include it in your code:

<?php include 'stathat.php' ?>

Copy and paste this code into your application:

stathat_ez_count('YOUR_EZKEY', 'user created', 1);
stathat_ez_value('YOUR_EZKEY', 'sign in - age of user', 27.0)

Using the EZ API with JavaScript in the browser is discouraged as it would expose your key. For JavaScript, we recommend using the Classic API. You need to create each stat individually on this page.

Install the StatHat npm module:

$ npm install stathat

Include the module in your code:

var stathat = require('stathat');

Copy and paste this code into your application:

stathat.trackEZCount("YOUR_EZKEY", "user created", 1, function(status, json) {});
stathat.trackEZValue("YOUR_EZKEY", "sign in - age of user", 27.0, function(status, json) {});

Download StatHat.java and put it with your project's java files. Then put it in your code:

import StatHat;

Copy and paste this code into your application:

StatHat.ezPostCount("YOUR_EZKEY", "user created", 1.0);
StatHat.ezPostValue("YOUR_EZKEY", "sign in - age of user", 27.0);

Run this command on the command line or in a shell script:

$ curl -d "stat=user created&ezkey=YOUR_EZKEY&count=1" http://api.stathat.com/ez
$ curl -d "stat=sign in - age of user&ezkey=YOUR_EZKEY&value=27.0" http://api.stathat.com/ez

Run this command on the command line or in a shell script:

$ wget --post-data "stat=user created&ezkey=YOUR_EZKEY&count=1" http://api.stathat.com/ez
$ wget --post-data "stat=sign in - age of user&ezkey=YOUR_EZKEY&value=27.0" http://api.stathat.com/ez

Download stathat.lisp. You'll also need the Drakma common lisp http client library. Include both in your code.

Copy and paste this code into your application:

(stathat-ez-count "YOUR_EZKEY" "user created" 1)
(stathat-ez-value "YOUR_EZKEY" "sign in - age of user" 27.0)

Include StatHat.cs in your project. For ASP.NET websites: put StatHat.cs in the App_pre folder.

StatHat.Post.EzCounter("YOUR_EZKEY", "user created", 1)
StatHat.Post.EzValue("YOUR_EZKEY", "sign in - age of user", 27.0)

Download stathat.pl and include it in your script.

Copy and paste this code into your application:

stathat_ez_count("YOUR_EZKEY", "user created", 1);
stathat_ez_value("YOUR_EZKEY", "sign in - age of user", 27.0);

Download stathat.lua.

Include it in your Lua script:

local stathat = require("stathat")

Copy and paste this code into your application:

stathat.ez_count("YOUR_EZKEY", "user created", 1);
stathat.ez_value("YOUR_EZKEY", "sign in - age of user", 27.0);

Install the package:

$ go get github.com/stathat/go

Import it in your code:

import "github.com/stathat/go"

Copy and paste this code into your application:

stathat.PostEZCount("user created", "YOUR_EZKEY", 1)
stathat.PostEZValue("sign in - age of user", "YOUR_EZKEY", 27.0)

Download stathat.erl. Include it in your Erlang project.

Start it up once:

{ok, Pid} = stathat:start().

Copy and paste this code into your application:

stathat:ez_count("YOUR_EZKEY", "user created", 1).
stathat:ez_value("YOUR_EZKEY", "sign in - age of user", 27.0).

Change the stat name to whatever you want.

StatHat will create a new stat for you when it receives the first data point. You'll get an email when that happens.

The Help area of StatHat contains documents describing the API in detail, as well as more examples, FAQs, and details for each language StatHat supports.


© 2011-2017 Numerotron Inc