The easiest guide on how to analytics code in WordPress. I literally had to do research and test it out on my website before writing a blog post/article about it.
As for the plugin version I had to look for and use a lite, easy and simple to use whereas the option where you add them in the PHP is also included where it is not really recommended by WordPress but there are people who prefer it
ADD GOOGLE ANALYTICS CODE TO WORDPRESS WITH PLUGIN
FIRST, log in to your analytics account
Click on the Admin ( gear icon or symbol ) > Under property click tracking info > tracking code.
Copy the Global site tag to add or paste on your site
SECOND, Go to your WordPress blog and click o plugins
THIRD, When it expands click on the add new option
FOURTH, Search for insert headers and footers in the rectangular box next to the keyword.
Install and activate the plugin
FIFTH, Click on Settings in your dashboard and after it expands choose insert headers and footers
LASTLY, Paste or add the code in the header section or box and click on the Save button
ADD GOOGLE ANALYTICS CODE TO WORDPRESS WITHOUT PLUGIN
FIRST, log in to your analytics
Click on the Admin ( Gear ) > Under property click tracking info > tracking code
Copy the Global site tag
SECOND, Go to your WordPress dashboard and click on Appearance
THIRD, It will expand with multiple options and choose theme editor
LASTLY, Under theme files click on theme header > Add or paste the code right above the <head> tag.
Click on the update file button