Giter Site home page Giter Site logo

ankane / ahoy_v1 Goto Github PK

View Code? Open in Web Editor NEW
6.0 3.0 2.0 116 KB

A lightweight javascript library that tracks how visitors arrive at your website

Home Page: https://github.com/ankane/ahoy

License: MIT License

CoffeeScript 38.22% JavaScript 61.78%

ahoy_v1's Introduction

Ahoy!

Ahoy is a lightweight javascript library that tracks how visitors arrive at your website.

Like Google Analytics?

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.

How does it work?

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.

Rails

source = JSON.parse(cookies["ahoy"])

PHP

$source = json_decode($_COOKIES["ahoy"]);

Super simple! Ahoy works with any language or framework that can read cookies and parse JSON.

Install

  1. Download the latest version.
  1. 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>

Customize

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>

Contribute

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

ahoy_v1's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ahoy_v1's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.