Run Function on Every State Change

I am integrating Mixpanel Analytics into my app and I want to track every page change and be able to submit some additional parameters.

I want to run something similar to this:
mixpanel.track("Page Change", {"state":$})
on every state change. What is the best way to do this?

The answer can be found here: