12% off of LTD using this coupon: TWELVEPERCENTOFF. Promo ends on 2 Dec midnight UTC.
Published on Aug 17, 2018

How to add Google Tag Manager code in Oxygen

Sridhar Katakam

Updated on May 16, 2019

Looking to add Google Tag Manager code in your Oxygen-powered WordPress site?

Just add the following Snippet after installing and activating Code Snippets plugin:

add_action( 'wp_head', 'sk_google_tag_manager1', 1 );
/**
 * Adds Google Tag Manager code in <head> below the <title>.
 */
function sk_google_tag_manager1() { ?>

    <!-- Google Tag Manager -->
    <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
    new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
    j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
    'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
    })(window,document,'script','dataLayer','GTM-XXXXXX');</script>
    <!-- End Google Tag Manager -->

<?php }

add_action( 'ct_before_builder', 'sk_google_tag_manager2' );
/**
 * Adds Google Tag Manager code immediately after the opening <body> tag.
 */
function sk_google_tag_manager2() { ?>

    <!-- Google Tag Manager (noscript) -->
    <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXX"
    height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
    <!-- End Google Tag Manager (noscript) -->

<?php }

Replace the code inside the above functions with the snippets provided by Google in the Tag Manager interface or replace GTM-XXXXXX with your container ID.

Set the snippet to load on the frontend.

Reference: wp-content/plugins/oxygen/component-framework/oxygen-main-template.php.

tagschevron-leftchevron-rightchainangle-rightangle-upangle-downfolder-omagnifiercrossmenuchevron-downarrow-right