As the best practice, Google Analytics tracking code should be added to your website on a general level, so you don’t need to re-enter the code when switching WordPress themes.
Add Google Analytics using plugin
You can use plugins for adding your Google Analytics code and the main idea was that this kind of things needs to be accessed via plugins.
- Google Analytics for WordPress by MonsterInsights – https://wordpress.org/plugins/google-analytics-for-wordpress/
- Google Analytics Dashboard for WP – https://wordpress.org/plugins/google-analytics-dashboard-for-wp/
- Google Analytics GA – https://wordpress.org/plugins/wd-google-analytics/
- Google Analytics WD – https://wordpress.org/plugins/wd-google-analytics/
You can choose any of these three plugins, its up to you and they should cover your needs more than enough.
If you already running website that is powered by some of the most popular SEO plugins like All In One SEO Pack or WP Meta SEO etc, check upon their option as they all offering the way to insert Google Analytics tracking code for easier visitors and performance tracking.