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


Fix get_the_terms Not Returning Data After Using pre_get_posts on Tax Archive Pages

When you use the pre_get_posts action in WordPress, you’re modifying the main query before it&...

Fix SEO Issues: Add Trailing Slash to Category URLs Easily

To fix SEO issues by consistently adding a trailing slash to your category URLs in WordPress, the ea...

Step-by-Step Guide to Define HTML Structure in WordPress Menus

WordPress menu customization allows you to create professional, functional navigation systems. This ...

Data Validation Issues using `dangerouslySetInnerHTML` into Gutenberg Blocks

Using dangerouslySetInnerHTML in React, and by extension in Gutenberg blocks, is a powerful tool but...

Recent Posts