I realize this question is general, but I think people with a lot of experience in event tracking will have good insight.
I have a website where I want to track file downloads by user. Two methods come to mind:
1) Create a model called AssetDownload and populate that with the data.
2) Create a model called Event or Activity and have that be a general model for tracking events.
I see the following pros and cons:
Method 1:
- Pro - Better readability because model represents the event exactly
- Pro - Will not need to refactor out into separate events if events become too different
- Pro - Will not need to search event table on an extra parameter all the time ("event type")
- Con - Potentially lots of tables
- Con - Maybe not very DRY, although they could inherit from a general Event model that is not associated with a table, or I could implement an "acts as trackable" gem
Method 2:
- Pro - Only one table for everything
- Pro - DRY by default
- Con - Table will potentially become very wide with columns that are only useful for a small subset of events
- Con - May need to refactor out specific events in the future
I am tempted to go with method 1 because it's sort of a minimum viable product thought process. Just make what I need, I'll eventually add 5 models, 1 for each event type. If I add 20 models then I can refactor using a Single Table Inheritance scheme. But at least at that point, I will know what I am refactoring, whereas designing for the future involves some guesswork right now.
However, I am successfully using Method 2 on another website right now. Just want to see what other people are doing.
Update
I want to mention that the events I am logging will need to be accessed quite often. I will be providing a dashboard where users can view file downloads by user and by date. Please consider this if your answer involves using an Audit log model