We do have an available Google Analytics plugin. It comes free with X theme. On the latest version of the plugin, we don't need to add the entire script. We just need the GOOGLE ANALYTICS ID and it will do the same job.
In case you insist adding codes, please check this thread as guide. Note that we don't necessarily need to add it directly on the header.php. The goal is to add the code on the headers of the site.
Hope this helps.