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


CSS in WordPress: Single Stylesheet vs. Page-Specific Files – What’s Best?

WordPress developers often face the dilemma of choosing between a single consolidated CSS file or mu...

How to Retrieve and Expose Gutenberg & Theme-Generated CSS in WordPress

If you want to extract the CSS generated by Gutenberg and your WordPress theme, you can do so using ...

How to List Posts on a Page Using ACF Field Values in Shortcodes?

Here’s how you can list posts on a page using ACF field values within a shortcode. This soluti...

Fail2Ban plugin on DigitalOcean

Fail2Ban is an excellent security tool for any Linux server, and DigitalOcean Droplets are no except...

Recent Posts