How do I setup Google Tag Manager or Google Analytics in Magento 2?

How do I setup Google Tag Manager or Google Analytics in Magento 2?

Step 1: Visit the Google Tag Manager website “https://tagmanager.google.com/”

Step 2: Sign up for a Google Account

Click Create Account on the top right corner and fill in the requirements.

Step 3: Afterward, enter all the necessary information

Set the account container by naming the Container and choosing the target platform. Please select Web if you want to gather data from a website.

Note: In order to delete a container, click on Admin -> Container Settings -> More menu (as three vertical dots) -> Settings -> Delete. You will have 30 days to change your mind and restore the container. After that time, Google will permanently delete it.

Step 4: Add the Google Tag Manager code to your website

After setting up and clicking on the Create button, a popup window will display the terms to use Google Tag Manager. Choose Yes to agree with Google’s conditions.

Then, a table will appear containing the codes of the container you’ve just created.

In this section, you’ll find two sets of code: Head and Body. Simply copy and paste these code sets and insert them into every website page. Place the first code set within the head section of your page, and insert the second one right after the opening body tag. Then, click OK to close the table.

Step 5: Get the Container ID and insert it into your Magento storeGet the Container ID

After closing the table, you should be back to the Workspace page. Click Admin on the section bar, the page will reload and show you the container ID next to it.

  • Insert Container ID into your Magento storeGo to Stores > Configuration > Mageplaza Extensions > Google Tag Manager.

In the Enable field, select Yes.

In the Google Tag ID field, paste the container ID you got on the Admin page before.

Remember to press the Save Config button.

If you want to learn more about adding Google Tag Manager to Magento 2, please read this article:

How to set up GTM (Google Tag Manager) in Magento 2 store- Mageplaza