jylamont
2/14/2013 - 1:05 AM

Track the same event for multiple company employees with Vero

Track the same event for multiple company employees with Vero

# More info for on the Ruby gem can be found here: https://github.com/getvero/vero

# /app/controllers/subscriptions_controller.rb
class SubscriptionsController < ApplicationController
  def upgrade
    company = Company.find(params[:id])
    company.upgrade!(params[:plan_id])
  end
end

# /app/models/company.rb
class Company < ActiveRecord::Base
  has_many :users

  # Method that handles upgrading a company plan.
  def upgrade!(plan)
    self.plan = plan
    self.save!

    # Trigger "Upgrade plan" event for each company employee
    self.users.each do |user|
      user.track!("Upgrade plan")
    end
  end
end

# /app/models/user.rb
class User < ActiveRecord::Base
  include Vero::Trackable
  trackable :email

  belongs_to :company
end