To add google analytics code in Magento2
Log in to Magento Backend
- On the Admin sidebar, go to Stores > Settings > Configuration.
- In the left panel, expand Sales and choose Google API.
- Expand
the Google Analytics section and do the following:- Set Enable to
Yes. - Enter your Google Analytics Account Number.
- If you want to conduct A/B testing and other performance tests on your content, set Content Experiments to
Yes.
- Set Enable to
- When complete, click Save Config.