Please make the following change:
{literal}
<!-- Google tag (gtag.js) -->
... all the javascript code ...
</script>
{/literal}
That is, surround the supplied code with Smarty's "Take this literally!" command.
Otherwise, Smarty will try to interpret anything between braces as commands for itself.