Skip to content

ActiveRecord group for feature usage

Posted on:February 2, 2024

Recently I had a question:

How much is this feature even getting used?

The easiest way to answer this would be to get a Product Owner to tell me how much our clients use it. However, this particular feature was quite old——older, in fact, than any of the Product Owners. So I would need a different approach to approximate feature usage.

I stumbled upon a rather interesting way of approximating feature usage. By using the created_at timestamp that ActiveRecord applies by default (using t.timestamps in your Rails migration), you can get an idea of what the distribution is of created rows in your table.

So for example, by using this:

YourModelName.group("TO_CHAR(created_at, 'YYYY-MM')").count

You’ll get an output something like this:

...
"2015-12"=>100,
"2016-01"=>90,
"2016-02"=>110,
...

Which you can then visualize however you’d like.

In my particular case, interestingly enough, usage was actually slowly increasing over time. This flew in the face of my hypothesis which was that no one at all was using the feature. The last few months showed the largest growth of new records created ever.

Of course, this doesn’t give the full picture. It’s possible there are some other systems interacting with this feature in a way that increases record creation without actually meaning people are using it.

But it did answer my original question: this feature was not dead in a meaningful way that would allow me to rip it out.


Thanks for reading! If you enjoyed this, you may also enjoy following me on twitter!