Google Analytics (Inject GTM script) in Perspective

We want to set up Google Analytics for our Perspective application to track the app usage, time spent by the user, clicks, etc.

Is anyone here able to successfully add the GTM (Google Tag Manager) script to the head and body section of the Perspective page? It comes down to 'is there an easy way to inject a custom javascript to the head and body section?'

If you have developed a different solution to track your application usage, can you please share how you approached that solution?

I am sure one possible option is to add logic to every startup/shutdown event script to log information to the database and then report out of that data, are there other options?