Where to add Google tag manager code in WordPress?

Where to Add Google Tag Manager (GTM) Code in WordPress

Google Tag Manager (GTM) is a powerful tool that allows you to manage and deploy tracking and marketing pixels, such as Google Analytics and Google Ads, across your website or application without editing the code directly. However, not all websites require tracking pixels, and that’s where WordPress comes in. In this article, we’ll explore where to add Google Tag Manager code in WordPress, highlighting some key points to keep in mind.

Why Add GTM Code to WordPress?

Before we dive into the locations where to add GTM code in WordPress, let’s discuss the benefits of using GTM. By adding code to WordPress, you can:

  • Track and analyze website performance: GTM allows you to track interactions on your website, such as form submissions, click-throughs, and conversions.
  • Improve user experience: By injecting GTM code into your website, you can optimize the user experience, increasing the chances of visitors converting into customers.
  • Enhance digital marketing capabilities: GTM enables you to track and measure the effectiveness of your digital marketing campaigns, providing valuable insights for data-driven decision-making.

Locations to Add Google Tag Manager Code in WordPress

Here are some common locations where to add Google Tag Manager code in WordPress:

1. Headers

What: Adding code to the section of your website’s HTML file.

Where: Add the following code in the section of your WordPress site’s HTML file:

<script>
(function(i,s,o,g,r,a,m){i['Google'])('script', 'https://www.googletagmanager.com/gtag/js?id=' + m + '_i/', 'script', ' async defer');</script>
<script src="https://www.googletagmanager.com/gtag/js?id=" + m + "_i"></script>
</script>
<script>
(function(i,s,o,g,r,a,m){i['Google'])('script', 'https://www.googletagmanager.com/gtag/js?id=' + m + '_g/', 'script', ' async defer');</script>
<script src="https://www.googletagmanager.com/gtag/js?id=" + m + "_g"></script>
</script>

2. Footer

What: Adding code to the

section of your website’s HTML file.

Where: Add the following code in the

section of your WordPress site’s HTML file:

<script>
(function(i,s,o,g,r,a,m){i['Google'])('script', 'https://www.googletagmanager.com/gtag/js?id=' + m + '_i/', 'script', ' async defer');</script>
<script src="https://www.googletagmanager.com/gtag/js?id=" + m + "_i"></script>
</script>
<script>
(function(i,s,o,g,r,a,m){i['Google'])('script', 'https://www.googletagmanager.com/gtag/js?id=' + m + '_g/', 'script', ' async defer');</script>
<script src="https://www.googletagmanager.com/gtag/js?id=" + m + "_g"></script>
</script>

3. Single Page Applications (SPAs)

What: Adding code to individual pages of a single page application (e.g. React or Angular).

Where: Add the following code in the individual pages of your WordPress site’s HTML file, using the _body tag:

<script>
(function(i,s,o,g,r,a,m){i['Google'])('script', 'https://www.googletagmanager.com/gtag/js?id=' + m + '_i/', 'script', ' async defer');</script>
<script src="https://www.googletagmanager.com/gtag/js?id=" + m + "_i"></script>
</script>
<script>
(function(i,s,o,g,r,a,m){i['Google'])('script', 'https://www.googletagmanager.com/gtag/js?id=' + m + '_g/', 'script', ' async defer');</script>
<script src="https://www.googletagmanager.com/gtag/js?id=" + m + "_g"></script>
</script>

4. Tags and Filters

What: Adding code to the <head> section of your WordPress page templates (e.g. page.php or single.php).

Where: Add the following code in the <head> section of your WordPress page template file:

<script>
(function(i,s,o,g,r,a,m){i['Google'])('script', 'https://www.googletagmanager.com/gtag/js?id=' + m + '_i/', 'script', ' async defer');</script>
<script src="https://www.googletagmanager.com/gtag/js?id=" + m + "_i"></script>
</script>
<script>
(function(i,s,o,g,r,a,m){i['Google'])('script', 'https://www.googletagmanager.com/gtag/js?id=' + m + '_g/', 'script', ' async defer');</script>
<script src="https://www.googletagmanager.com/gtag/js?id=" + m + "_g"></script>
</script>

5. Custom Codes

What: Adding custom code to your WordPress site’s HTML file.

Where: Add the following code in the <head> section of your WordPress site’s HTML file:

<script>
(function(i,s,o,g,r,a,m){i['Google'])('script', 'https://www.googletagmanager.com/gtag/js?id=' + m + '_i/', 'script', ' async defer');</script>
<script src="https://www.googletagmanager.com/gtag/js?id=" + m + "_i"></script>
</script>
<script>
(function(i,s,o,g,r,a,m){i['Google'])('script', 'https://www.googletagmanager.com/gtag/js?id=' + m + '_g/', 'script', ' async defer');</script>
<script src="https://www.googletagmanager.com/gtag/js?id=" + m + "_g"></script>
</script>

Important Points to Keep in Mind

  • Make sure to include the GTM header in your WordPress site’s HTML file.
  • Do not duplicate GTM code across multiple sites or templates.
  • Use the correct GTM version for your WordPress site.
  • Test your code to ensure it is working correctly.

Conclusion

Adding Google Tag Manager code to your WordPress site can be a powerful way to track and analyze website performance, enhance user experience, and improve digital marketing capabilities. By following the locations and steps outlined in this article, you can ensure that your GTM code is properly implemented and working correctly. Remember to test your code and keep it up-to-date to ensure the best possible performance.

Unlock the Future: Watch Our Essential Tech Videos!


Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top