How can I test google tag manager locally?

by harrison.goodwin , in category: SEO Tools , 8 months ago

How can I test google tag manager locally?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

by jacey.lubowitz , 8 months ago


To test Google Tag Manager (GTM) locally, you can follow the steps below:

  1. Set up a local development environment: You can use a local server software like XAMPP or MAMP to set up a local development environment on your computer.
  2. Create a local HTML file: Create a simple HTML file on your local server, which will serve as your test page. You can create a basic HTML file using any text editor, and save it with a .html extension.
  3. Generate a preview mode snippet in GTM: Login to your GTM account and navigate to the desired container. In the container panel, click on the "Preview" button at the top right corner. Then, copy the provided preview mode snippet.
  4. Add GTM snippet to your local HTML file: Open the local HTML file you created earlier and paste the GTM preview mode snippet just before the closing tag. Save the HTML file.
  5. Publish GTM container: In GTM, click on "Submit" at the top right corner to publish your container changes. This step is necessary to make sure the container is in the "Published" state.
  6. Start the local server: Start your local server (e.g., XAMPP or MAMP) to host your HTML file.
  7. Access your test page: Open a web browser and navigate to your local test page by entering the URL provided by your local server (e.g., http://localhost/testpage.html).
  8. Open GTM Preview mode: While on your local test page, open a new tab in the same browser and navigate to your GTM account. Click on the "Preview" button. This will enable GTM preview mode for the current browser session.
  9. Test GTM functionality: With the GTM preview mode open and your local test page visible, you can now test the functionality of your GTM setup. You can check tag firing, custom events, data layer interactions, and debug your GTM configuration.

Remember to remove the GTM preview mode snippet and republish your container before deploying any live changes.

Note: Testing GTM locally may have limitations, especially if you have integrations with external services or rely on real-time user data. It is advisable to thoroughly test GTM in the actual production environment as well.