Hi, when you add your html or css codes to theme files your changes get lost if your theme gets update. To avoid this i suggest you to use this ready to use plugin.
With this plugin you can add html / Css /Js codes to your header or footer of wordpress site.
When you install and activate this plugin you will see new setting page undeer settings menu.
When you click “Edit Footer and Header” page you will see secreen like this:
You just need to do is paste your analytics code to “Header Codes” section and then click “Save” button.
Dont forget to clear cache if you use cache plugins.