There's a subset of Google Analytics js library called ga-lite that you can cache however you want.
The library uses Google Analytics' public REST API to send the user tracking data to Google. You can read more from the blog post about ga-lite.
Disclaimer: I am the author of this library. I struggled with this specific problem and the best result I found was to implement this solution.