If you are looking for something fully automatic and comprehensive, check out arbtt.
The daemon simply collects and stores snapshots of your state of desktop (all and current focused programs, window title text, current inactive time etc) at configurable interval.
And then there is a separate "front-end" component, with which you can define with logic which program belongs to which category, which keyword should be tagged with what, how much of inactivity is too much etc. And you can generate a report between any interval of time etc. It doesn't come with pretty dashboard or UI, but if you can script a little, this is gold.
You may want to take inspiration from arbtt. E.g. arbtt looks up not only window name but also title, which is nice because lot of programs allow users to customise what additional information goes in title. And then arbtt has a config file DSL (with conditionals, regex etc) which allows users to tag/categorise each data point automatically, armed with said language features.