I manage google analytics inside google tag manager and I don't have any separated script for google analytics in the head of my website.

I need to use ga() function like this:

<!-- Google Analytics -->
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

ga('create', 'UA-XXXXX-Y', 'auto');
<!-- End Google Analytics -->

See? It has created ga right after google analytics script. But as I said, I don't have any script for google analytics. I have just a script (which is located in the head of my website) from google tag manager:

new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
ga('create', 'UA-{$google_analytics_token}', 'auto');

The problem is, it throws:

Uncaught ReferenceError: ga is not defined

Any idea where should I place ga('create', 'UA-{$google_analytics_token}', 'auto'); exactly?

It should be noted, when I run ga('create', 'UA-{$google_analytics_token}', 'auto'); in the console of the browser, it will be created as well. Do I need a settimeout() ?