1. Dec 14th, 2009

    Vanity 1.2: Database metrics

    The killer new feature of Vanity 1.2 are database metrics. You’ve already got the data, so let’s show it in the dashboard.

    Here’s a metric for signups (activation), based on the number of Account records created on each day:

    metric "Signup (Activation)" do
      description "Measures how many people signed up for our awesome service."
      model Account
    end

    No need to call track! on this metric, and it comes with historical data (assuming you already have accounts in your database).

    Some metrics measure values, not occurrences. This example measures user satisfaction by calculating average rating:

    metric "Satisfaction Survey" do
      description "Measures how many people signed up for our awesome service."
      model Survey, :average=>:rating
    end

    Other aggregates you can use are :minimum:maximum and :sum.

    If you’re only measuring some metrics, use conditions:

    metric "Signups to Unlimited" do
      description "Signups to our All You Can Eat and Burp Unlimited plan."
      model Account, :conditions=>{ :plan_type=>'unlimited' }
    end

    Even better, named scopes:

    metric "Signups to Unlimited" do
      description "Signups to our All You Can Eat and Burp Unlimited plan."
      model Account.unlimited
    end

    Or just roll your own:

    metric "Signups (Unlimited)" do
      description "Signups to our All You Can Eat and Burp Unlimited plan (including upgrades)."
      Account.after_save do |account|
        track! if account.plan_type_changed? && account.plan_type == 'unlimited'
      end
    end

    Get it now, and get measuring.

    Your comment, here ⇓