GithubHelp home page GithubHelp logo

yelled3 / ahoy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ankane/ahoy

0.0 2.0 0.0 531 KB

Simple, powerful visit tracking for Rails

Home Page: http://ankane.github.io/ahoy/

License: MIT License

ahoy's Introduction

Ahoy

🔥 Simple, powerful visit tracking for Rails

Visits are stored in your database so you can easily combine them with other data.

You get:

  • traffic source - referrer, referring domain, landing page, search keyword
  • location - country, region, and city
  • technology - browser, OS, and device type
  • utm parameters - source, medium, term, content, campaign

See which campaigns generate the most revenue effortlessly.

Order.joins(:visit).group("utm_campaign").sum(:revenue)

How It Works

When someone visits your website, Ahoy creates a visit with lots of useful information.

Use the current_visit method to access it.

Explore your visits with queries like:

Visit.group(:search_keyword).count
Visit.group(:country).count
Visit.group(:referring_domain).count

Chartkick and Groupdate make it super easy to visualize the data.

<%= line_chart Visit.group_by_day(:created_at).count %>

The Power

This information is great on its own, but super powerful when combined with other models.

Let’s associate orders with visits.

class Order < ActiveRecord::Base
  visitable
end

When a visitor places an order, the visit_id column is automatically set.

🎉 Magic!

See where orders are coming from with simple joins:

Order.joins(:visit).group("referring_domain").count
Order.joins(:visit).group("city").count
Order.joins(:visit).group("device_type").count

Users

Ahoy automatically attaches the current_user to the current_visit.

With Devise, it will attach the user even if he / she signs in after the visit starts.

With other authentication frameworks, add this to the end of your sign in method:

if current_visit
  current_visit.user ||= current_user
  current_visit.save!
end

To see the visits for a given user, create an association:

class User < ActiveRecord::Base
  has_many :visits
end

And use:

user = User.first
user.visits

UTM Parameters

Use UTM parameters to track campaigns. This is great for emails and social media. Just add them to your links and Ahoy will pick them up.

http://datakick.org/?utm_medium=email&utm_campaign=newsletter&utm_source=newsletter-2014-03

or

http://datakick.org/?utm_medium=twitter&utm_campaign=social&utm_source=tweet123

Location

Ahoy uses Geocoder for IP-based geocoding.

More

  • Excludes bots
  • Degrades gracefully when cookies are disabled

Installation

Add this line to your application’s Gemfile:

gem 'ahoy_matey'

And run the generator. This creates a model to store visits.

rails generate ahoy:install
rake db:migrate

Lastly, include the javascript file in app/assets/javascripts/application.js after jQuery.

//= require jquery
//= require ahoy

We recommend using traditional analytics services like Google Analytics as well.

TODO

  • simple dashboard
  • hook to store additional fields
  • turn off modules

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

ahoy's People

Contributors

ankane avatar

Watchers

 avatar  avatar

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.