Google Tag Manager (GTM) simplifies managing and deploying marketing tags and tracking scripts without extensive coding. This guide explains how to install GTM on Magento 2, also known as Adobe Commerce.
Prerequisites
Before you begin, ensure you have:
- Access to your Google Tag Manager account.
- Admin access to your Magento 2 / Adobe Commerce store.
Step 1: Set Up Google Tag Manager
Create a GTM Account
- Go to Google Tag Manager.
- Sign in with your Google account.
- Click Create Account.
- Enter your account name, container name (usually your website's URL), and select Web as the target platform.
- Click Create, review the GTM Terms of Service, and click Yes to agree.
Obtain the GTM Container Code
- After setup, you'll receive two snippets of code: a Head code and a Body code.
- Copy these codes for integration with Magento.
Step 2: Install GTM in Magento 2 / Adobe Commerce
You can install GTM manually or use a third-party extension. Below are both methods:
Method 1: Manual Installation
Access Your Magento Admin Panel
- Log in to your Magento admin panel.
Add GTM Code to Your Theme
- Navigate to Content > Design > Configuration.
- Select your theme and click Edit.
Add the GTM Head Code
- In the HTML Head section, find the Scripts and Style Sheets box.
- Paste the GTM Head code snippet here.
Add the GTM Body Code
- Scroll to the Other Settings section and expand it.
- In the Footer tab, paste the GTM Body code snippet in the Miscellaneous HTML box.
Save the Changes
- Click Save Configuration to apply the changes.
Flush the Cache
- Go to System > Cache Management.
- Click Flush Magento Cache to ensure changes take effect.
Method 2: Using a Third-Party Extension
Choose a GTM Extension
- Visit the Magento Marketplace.
- Search for “Google Tag Manager” extensions.
Install the Extension
- Follow the developer’s instructions for installation.
- Typically, this involves downloading the extension, uploading it to your Magento root directory, and running specific commands to enable it.
Configure the Extension
- After installation, go to Stores > Configuration in your Magento admin.
- Locate the GTM extension settings under Sales or General.
- Enter your GTM container ID (GTM-XXXXXX) and save the configuration.
Step 3: Verify the Installation
Check the Source Code
- Visit your store’s homepage.
- Right-click and select View Page Source.
- Ensure the GTM code snippets are in the
<head>
and<body>
sections of the HTML.
Use the GTM Debug Tool
- In Google Tag Manager, click Preview in the workspace.
- Enter your store’s URL to start debugging.
- Verify GTM captures data and that tags are firing as expected.
Google Tag Assistant
- Install the Google Tag Assistant Chrome extension.
- Visit your store and activate the extension to check for GTM installation errors or warnings.
Conclusion
Integrating Google Tag Manager with Magento 2 / Adobe Commerce enhances your ability to manage tracking scripts and marketing tags effectively. Test thoroughly after installation to confirm that all tags and tracking functionalities are working as intended.
Refer to Google Tag Manager’s official documentation and Magento’s user guide for additional support.