The first step is made in your Google Tag Manager account
Log in to your Google Tag Manager account at https://tagmanager.google.com/#/home
Click the Cog shape to the top right of your relevant Tag Manager instance
Click Install Google Tag Manager
Copy the code in the top box using the copy icon on the right
The second step is made in your Magento 2 Admin
For Magento 2.0
For Magento 2.1 and later versions
Log into your Magento 2 admin
Navigate to Content -> Configuration
Click Edit on the store view you want to add the tag code to or select Global in order to add the code on every store view.
Find the HTML Head section and add the code copied from Tag Manager in the Scripts and Style Sheets field.
Once the changes have been performed press the Save Configuration button and flush Magento Cache.
How to check if GTM code is present on your website
The easiest way to verify that Google Tag Manager code is present on your website is to check the source code of your Magento 2 store frontend.
On the homepage of your website right click -> view page source and search for “Google Tag Manager.” If Google Tag Manager has been added successfully, you will see code similar to this: