Gear change recording
No such product exists for mechanical groupsets yet. As for Di2, you just need the little Bluetooth transmitter to communicate with your head unit. This will record the number of shifts, as well as the gear that you're using at any time. 

I've included a screenshot of the Wahoo Elemnt app to show how this data is displayed. To set this up, you need to program your cassette and chainring ratios into the head-unit, because your Di2 isn't able to tell the number of teeth, only which cog it's on.