How to track the changes of an order status programmatically?

You should learn about events: