• Resolved speechfree

    (@speechfree)


    Hello,

    I am trying to implement Google Consent Mode with the option 4 in the following link:

    https://support.mooveagency.com/topic/ga-gtm-consent-settings/

    I use Snippets plugin and I added the following code.

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

    <!-- 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-123456789');</script>
    <!-- End Google Tag Manager -->

    <!-- Custom Script -->
    <script>
    // Define dataLayer and the gtag function.
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    // Set default consent to 'denied' as a placeholder
    // Determine actual values based on your own requirements
    gtag('consent', 'default', {
    'ad_storage': 'denied',
    'ad_user_data': 'denied',
    'ad_personalization': 'denied',
    'analytics_storage': 'denied'
    });
    </script>
    <!-- End Custom Script -->

    <?php }

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

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

    <?php }

    This adds the codes to the head section of the page. I also added the following code to the plugin’s 3rd party cookies head section.

    gtag('consent', 'default', {
    'ad_storage': 'granted',
    'ad_user_data': 'granted',
    'ad_personalization': 'granted',
    'analytics_storage': 'granted'
    });

    When I accept the cookies, the page refreshes but the code in the head does still show denied. What am I doing wrong?

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Google Consent Mode V2’ is closed to new replies.