Ahoy is a lightweight javascript library that tracks how visitors arrive at your website.
Similar, except you see how specific visitors arrived at your site. You can then measure how each visitor performs over time - not just the first visit - and compare traffic sources on:
- monthly revenue
- sign ups
- conversion rates
and any other metrics you desire.
Ahoy turns an ugly HTTP Referer
header like
http://www.google.com/url?sa=t&source=web&cd=2&ved=0CCsQFjAB&rct=j&q=parrots&ei=BE7HTZ-LE5PWtQPqkeHqAQ&usg=AFQj...
into a cookie named ahoy
that looks like
{
"site": "google.com",
"category": "search",
"info": "query > parrots",
"referrer": "http://www.google.com/url...",
"arrived_at": "Mon May 09 2011 19:08:45 GMT-0700 (PDT)"
}
When a visitor signs up, you can read the cookie, parse the JSON, and save the information to your database.
source = JSON.parse(cookies["ahoy"])
$source = json_decode($_COOKIES["ahoy"]);
Super simple! Ahoy works with any language or framework that can read cookies and parse JSON.
- Download the latest version.
- Add the following code right before the
</body>
tag.
<script type="text/javascript" src="ahoy-0.1.5.min.js"></script>
<script type="text/javascript">
ahoy.matey();
</script>
Ahoy was built to be highly customizable. Here are a few things you can do.
<script type="text/javascript">
// change the cookie name
ahoy.cookieName("trafficSource");
// fire callback when a visitor first arrives
ahoy.onArrival( function(source) {
console.log(source);
});
// add a custom host so traffic arriving from
// news.ycombinator.com appears as "hackernews"
ahoy.addHost("news.ycombinator.com", function() {
return {"site": "hackernews", "category": "news"};
});
// call this last
ahoy.matey();
</script>
Ahoy is written in CoffeeScript. Please report bugs on the GitHub issue tracker.
If you would like to contribute, first clone the repository.
git clone [email protected]:ankane/ahoy.git
cd ahoy
Build and test the library
cake build && cake spec