2

I'm using nuxtjs.

this is my google tag manager script:

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

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

but I got this error message (tag must not be included in a div):

enter image description here

my structure:

<div class="wrapper">
    <Heder />
    <main>
        <Nuxt/>
    </main>
   <Footer>


//my google tag manager script

</div>
ThilankaD
  • 1,021
  • 1
  • 13
  • 24
S.M_Emamian
  • 17,005
  • 37
  • 135
  • 254
  • 1
    Why not use [`@nuxtjs/gtm`](https://github.com/nuxt-community/gtm-module)? – tony19 Jun 13 '21 at 05:29
  • i am not familiar with nuxt but isn't there any `index.html` as a entry file to your app? why not setup there? – Deniz Jun 13 '21 at 06:51

1 Answers1

0

You should place the Google tag manager code snippet on every page you want to add GTM to it, inside the very first of the <head> tag, not the <body> tag. And <noscript> code should be placed immediately after the <body> tag as instructed in here

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

    //rest of the head
</head>

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

    // rest of the body
</body>

</html>
ThilankaD
  • 1,021
  • 1
  • 13
  • 24