To add Google Analytics code to your WordPress website you could edit the theme header.php file and copy and paste it into there but it will get deleted when your theme requires updating. A simpler method and one that prevents you having to reenter the code on a theme update is to install a plugin that allows you to add code to the header.php or footer.php files which is included when a page loads.
One plugin which is easy to use and allows you to do this is the “Insert Headers and Footers” plugin. Once installed you will find a link to it in the WordPress Dashboard under “Settings”. Click on that and you will be presented with one text box for entering code into the header and one text box for entering code into the footer. Simply copy and paste as much code as you wish and click save. Easy.