Google Tag Manager is Breaking My Oxygen-Built Website (WordPress)

Fix: Google Tag Manager Breaking Oxygen-Built WordPress Website

If Google Tag Manager (GTM) is causing issues on your Oxygen-built website, here are common reasons and how to fix them.

Possible Causes & Fixes

1. Oxygen’s JavaScript Conflicts

Oxygen Builder loads scripts differently, which can conflict with GTM.

Fix: Load GTM asynchronously to prevent blocking Oxygen scripts.

Add this snippet to “Code Snippets” or functions.php:

function add_gtm_async() {
    ?>
    <script async src="https://www.googletagmanager.com/gtm.js?id=GTM-XXXXXX"></script>
    <?php
}
add_action('wp_head', 'add_gtm_async', 5);

Replace GTM-XXXXXX with your GTM ID.

2. GTM Container Placement Issues

If GTM was added via Oxygen’s settings, it might not execute properly.

Fix: Insert GTM manually using Oxygen’s “Code Block” feature.

  • Go to Oxygen > Templates.
  • Edit the Main Template.
  • Add a Code Block.
  • Paste your GTM <script> in the Head section.
  • Paste the <noscript> part in the Body section.

3. Page Loading or Layout Issues

GTM may interfere with Oxygen’s CSS or JavaScript.

Fix: Defer GTM’s execution so Oxygen loads first.

<script>
  window.addEventListener('load', function() {
      setTimeout(function() {
          var gtmScript = document.createElement('script');
          gtmScript.async = true;
          gtmScript.src = 'https://www.googletagmanager.com/gtm.js?id=GTM-XXXXXX';
          document.head.appendChild(gtmScript);
      }, 1500); // Delay by 1.5 seconds
  });
</script>

4. GTM Conflicting with Oxygen’s Optimizations

Oxygen’s caching or script minification may block GTM.

Fix: Exclude GTM from Oxygen’s optimizations.

  • Go to Oxygen > Settings > Bloat Eliminator.
  • Disable “Remove jQuery Migrate” (if enabled).
  • Exclude googletagmanager.com from minification or lazy loading.

5. Errors in Google Tag Manager Preview Mode

If GTM isn’t working correctly, check your browser console for:

  • CORS Policy Errors: GTM requests blocked due to security settings.
  • GTM Firing Too Soon: Events triggering before Oxygen loads.

Fix: Use GTM’s built-in “DOM Ready” trigger instead of “Page View.”

Final Checks

  • Clear Oxygen Cache (Oxygen > Settings > CSS Cache > Regenerate).
  • Use GTM Debug Mode to check for conflicts.
  • Disable other plugins (like security or cache plugins) to troubleshoot.

If your Oxygen site is still breaking, what specific issues are you facing—layout glitches, missing elements, or something else?

Related Posts


WP Pagination Not Working for Custom Query: Troubleshooting Tips

Ever struggled with WordPress pagination code? Fret not! We’ve got your back. In this post, we...

WordPress Redirect Issues Across Multiple Websites

Experiencing redirect loops or unwanted redirects on multiple WordPress sites? Here’s a guide to d...

Woocommerce single product page css broken

If your WooCommerce single product page’s CSS is broken, here are some steps to troubleshoot a...

WordPress CSS Issue Caused by User Agent Stylesheet

If your WordPress site’s CSS is being overridden by the user agent stylesheet, it can cause layout...