Project

trackme

0.0
No commit activity in last 3 years
No release in over 3 years
Simple user activity tracking
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
>= 0
 Project Readme

TrackMe

Simple user activity tracking for Ruby and Rails developers

Usage

TrackMe is based on the idea that an actor performs an event.

To setup your event class add the following: include TrackMe::Event

To setup your actor class add the following: include TrackMe::Actor

By default, TrackMe looks for an event class called 'Event'. If you would like to change this then set the following: self.event_klass = CLASS

Once setup, you can track a users activity in the following way: current_user.track_me(category: 'View')

Details

TrackMe events have the following options:

  • :actor (required) - The object that did the event
  • :category (required)- The event category, such as 'Message'
  • :label (option)- The label of the event category, such as 'New'
  • :value (option)- The value of the event category label, such as 'Hello Bob!'

TrackMe requires the following fields to save events:

  • actor_id - Integer
  • category - String
  • label - String
  • value - String

Rails Example

First, add the TrackMe gem to your Gemfile:

gem 'trackme'

Next, you need to setup a model to be the actor, this is most likely going to be your User model.

class User
  include TrackMe::Actor

  # … existing model code
end

Then you need to setup a model to save the events, in most cases you will need to create a new model with the fields actor, category, label, value.

In a Rails app backed by Postgress you would set this up with by running the following on the command line:

rails g model event actor_id:integer category:text label:text value:text -t nil

rake db:migrate

And add the following to your Event model:

class Event
  include TrackMe::Event

  # … existing model code
end

Let's say you have a Messages controller and you want to track when a user sends a message, you would add the following code to your create action:

class MessagesController
  # … existing controller code

  def create
    # … existing code
    @sender = User.find(params[:sender_id])
    @sender.track_me(category: 'Message', label: 'New', value: @message.body)
  end

  # … more controller code
end

That's it! Now you are able to track users activity.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request