Title: GTM not working while adding code to 3rd party cookie section
Last modified: September 3, 2020

---

# GTM not working while adding code to 3rd party cookie section

 *  Resolved [nabaraj chapagain](https://wordpress.org/support/users/nabaraj-chapagain/)
 * (@nabaraj-chapagain)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/gtm-not-working-while-adding-code-to-3rd-party-cookie-section/)
 * The GTM wont fire any tags if we add the script in third party header section.
   If added directly to the header, which works perfectly!
 * The reason for this is not loading the script to the header once clicked ‘accept’.
   Its added dynamically so wont work at all.
 * How do we sort this issue.

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [Moove Agency](https://wordpress.org/support/users/mooveagency/)
 * (@mooveagency)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/gtm-not-working-while-adding-code-to-3rd-party-cookie-section/#post-13361392)
 * Hi [@nabaraj-chapagain](https://wordpress.org/support/users/nabaraj-chapagain/),
 * Thanks for using our plugins.
 * Could you please provide more details about the issue?
    What is the script you
   are using on your website (you can replace the ID’s with custom XYZ strings)?
   What is your website URL where we can check the issue?
 * You can check our related topics as well:
    [https://wordpress.org/support/topic/white-screen-during-navigation/](https://wordpress.org/support/topic/white-screen-during-navigation/)
   [https://support.mooveagency.com/topic/website-re-loads-after-a-few-seconds-once/](https://support.mooveagency.com/topic/website-re-loads-after-a-few-seconds-once/)
 * Hope this helps.
 *  Thread Starter [nabaraj chapagain](https://wordpress.org/support/users/nabaraj-chapagain/)
 * (@nabaraj-chapagain)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/gtm-not-working-while-adding-code-to-3rd-party-cookie-section/#post-13370269)
 * Hello
 * Thanks for the reply. Below is the GTM code
 * <!– 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)](https://www.googletagmanager.com/gtm.js?id=’+i+dl;f.parentNode.insertBefore(j,f));})(
   window,document,’script’,’dataLayer’,’GTM-xxxxxxx’);</script> <!– End Google 
   Tag Manager –>
 * I’ve put this inside the third party cookie section. We’re trying to track some
   form submissions and button clicks.
 * The GTM preview mode wont work. The code that is dynamically injected wont record
   any conversions.
 * We cant directly add to code to header because of the cookie added by the GTM.
   And trying to make it GDPR compliance wont track anything after moved from header
   to the plugin header section.
 * Any solution for this?
 *  Thread Starter [nabaraj chapagain](https://wordpress.org/support/users/nabaraj-chapagain/)
 * (@nabaraj-chapagain)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/gtm-not-working-while-adding-code-to-3rd-party-cookie-section/#post-13375182)
 * Can you provide some updates please?
 *  Plugin Author [Moove Agency](https://wordpress.org/support/users/mooveagency/)
 * (@mooveagency)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/gtm-not-working-while-adding-code-to-3rd-party-cookie-section/#post-13380065)
 * Hi [@nabaraj-chapagain](https://wordpress.org/support/users/nabaraj-chapagain/),
 * Please replace your GTM script with the following snippet, and place to the correct
   position (peplace the GTM-ZZZZZZ to your real ID):
 * **Third Party – Header Scripts**
 *     ```
       <!-- 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-ZZZZZZ');</script>
       <!-- End Google Tag Manager -->
       ```
   
 * **Third Party – Body Scripts**
 *     ```
       <!-- Google Tag Manager (noscript) -->
       <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-ZZZZZZ"
       height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
       <!-- End Google Tag Manager (noscript) -->
       ```
   
 * Also, please ensure the `https://www.example.com/wp-admin/admin-ajax.php` is 
   not protected, so if you open in a browser, you should see a 0. Sometimes the
   wp-admin area is protected but the admin-ajax.php is not whitelisted and this
   causes the issue. If it’s protected and you can’t whitelist the AJAX in your 
   website, you can add the following code snippet to your functions.php
    `add_action('
   gdpr_cc_prevent_ajax_script_inject', '__return_true' );`
 * If none of the solutions listed above is working, please share your site URL 
   in order to see the errors and start the investigation for you.
 * Thanks

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘GTM not working while adding code to 3rd party cookie section’ is closed
to new replies.

 * ![](https://ps.w.org/gdpr-cookie-compliance/assets/icon-256x256.png?rev=2376316)
 * [GDPR Cookie Compliance - Cookie Banner, Cookie Consent, Cookie Notice for CCPA, EU Cookie Law](https://wordpress.org/plugins/gdpr-cookie-compliance/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/gdpr-cookie-compliance/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/gdpr-cookie-compliance/)
 * [Active Topics](https://wordpress.org/support/plugin/gdpr-cookie-compliance/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/gdpr-cookie-compliance/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/gdpr-cookie-compliance/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [Moove Agency](https://wordpress.org/support/users/mooveagency/)
 * Last activity: [5 years, 9 months ago](https://wordpress.org/support/topic/gtm-not-working-while-adding-code-to-3rd-party-cookie-section/#post-13380065)
 * Status: resolved