To add Google Analytics code in theme there are special options and their editing is available on theme settings page in admin panel of site.
header.php
or footer.php
.Go to menu Appearance → Customize and select tab Custom codes
Google Analytics is recommended to add as close as possible to top of page, i.e. in site header. To do this, add code received from Google in first text box Scripts in header. Consequently, if you add these scripts in boxScripts in site footer, they will appear in site footer before closing tag </body>.
Field Custom styles will help you to style site with CSS code. It is important to remember that these styles will be added directly to page code, site header, for this reason they will have higher priority than styles which are defined in style.css. For example, if it is defined in style.css:
body{ background-color:#ffffff; }
and in field Custom styles you add:
body{ background-color:#000000; }
then the latest style will be applied and page background will be black.
After changing text boxes in section Custom codes, click on Save & publish. That’s all, added scripts or styles will appear on your site.