Using User ID with Google Tag Manager / Analytics












-1















Hope somebody can help, I'm using GTM to push a userId variable over to google analytics, i can see the data in the chrome console / dataLayer but nothing is showing in the userID view on analytics. I'm using this code on my site at the top of the head:



<script>
dataLayer =
dataLayer.push({ 'userId': <%= currentUser.number %> });
</script>
<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-XXXXXXXX');
</script>


And at the top of the body:



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


On GTM i have a Data Layer variable set up as userId (Data Layer version2) and in the tag configuration (fields to set) I have Field Name userId and value {{userId}}.



Over on analytics I have set up a UserId view and a Custom Dimension Name of userId (scope is User, Index is 1).



Am I missing something??



thanks.










share|improve this question

























  • Did you wait 24 hours?

    – zborovskaya
    Nov 15 '18 at 13:09











  • No didn't realise there was a delay updating, will check again tomorrow - thanks.

    – Dan Thory
    Nov 15 '18 at 13:27











  • Its working now - thanks!

    – Dan Thory
    Nov 16 '18 at 9:01
















-1















Hope somebody can help, I'm using GTM to push a userId variable over to google analytics, i can see the data in the chrome console / dataLayer but nothing is showing in the userID view on analytics. I'm using this code on my site at the top of the head:



<script>
dataLayer =
dataLayer.push({ 'userId': <%= currentUser.number %> });
</script>
<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-XXXXXXXX');
</script>


And at the top of the body:



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


On GTM i have a Data Layer variable set up as userId (Data Layer version2) and in the tag configuration (fields to set) I have Field Name userId and value {{userId}}.



Over on analytics I have set up a UserId view and a Custom Dimension Name of userId (scope is User, Index is 1).



Am I missing something??



thanks.










share|improve this question

























  • Did you wait 24 hours?

    – zborovskaya
    Nov 15 '18 at 13:09











  • No didn't realise there was a delay updating, will check again tomorrow - thanks.

    – Dan Thory
    Nov 15 '18 at 13:27











  • Its working now - thanks!

    – Dan Thory
    Nov 16 '18 at 9:01














-1












-1








-1








Hope somebody can help, I'm using GTM to push a userId variable over to google analytics, i can see the data in the chrome console / dataLayer but nothing is showing in the userID view on analytics. I'm using this code on my site at the top of the head:



<script>
dataLayer =
dataLayer.push({ 'userId': <%= currentUser.number %> });
</script>
<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-XXXXXXXX');
</script>


And at the top of the body:



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


On GTM i have a Data Layer variable set up as userId (Data Layer version2) and in the tag configuration (fields to set) I have Field Name userId and value {{userId}}.



Over on analytics I have set up a UserId view and a Custom Dimension Name of userId (scope is User, Index is 1).



Am I missing something??



thanks.










share|improve this question
















Hope somebody can help, I'm using GTM to push a userId variable over to google analytics, i can see the data in the chrome console / dataLayer but nothing is showing in the userID view on analytics. I'm using this code on my site at the top of the head:



<script>
dataLayer =
dataLayer.push({ 'userId': <%= currentUser.number %> });
</script>
<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-XXXXXXXX');
</script>


And at the top of the body:



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


On GTM i have a Data Layer variable set up as userId (Data Layer version2) and in the tag configuration (fields to set) I have Field Name userId and value {{userId}}.



Over on analytics I have set up a UserId view and a Custom Dimension Name of userId (scope is User, Index is 1).



Am I missing something??



thanks.







google-analytics google-tag-manager






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 11:50









DaImTo

46.1k1163246




46.1k1163246










asked Nov 15 '18 at 11:18









Dan ThoryDan Thory

407




407













  • Did you wait 24 hours?

    – zborovskaya
    Nov 15 '18 at 13:09











  • No didn't realise there was a delay updating, will check again tomorrow - thanks.

    – Dan Thory
    Nov 15 '18 at 13:27











  • Its working now - thanks!

    – Dan Thory
    Nov 16 '18 at 9:01



















  • Did you wait 24 hours?

    – zborovskaya
    Nov 15 '18 at 13:09











  • No didn't realise there was a delay updating, will check again tomorrow - thanks.

    – Dan Thory
    Nov 15 '18 at 13:27











  • Its working now - thanks!

    – Dan Thory
    Nov 16 '18 at 9:01

















Did you wait 24 hours?

– zborovskaya
Nov 15 '18 at 13:09





Did you wait 24 hours?

– zborovskaya
Nov 15 '18 at 13:09













No didn't realise there was a delay updating, will check again tomorrow - thanks.

– Dan Thory
Nov 15 '18 at 13:27





No didn't realise there was a delay updating, will check again tomorrow - thanks.

– Dan Thory
Nov 15 '18 at 13:27













Its working now - thanks!

– Dan Thory
Nov 16 '18 at 9:01





Its working now - thanks!

– Dan Thory
Nov 16 '18 at 9:01












2 Answers
2






active

oldest

votes


















0














The code / setup I used above does work for showing userId within a userID view on analytics - as Ms.Easy said, you have to wait 24hrs for it to update.






share|improve this answer































    0














    This might not work as you have declared dataLayer.push method above the GTM container.
    You can only declare dataLayer=method above the GTM container.
    To send the user Id to GA, Use the below Code:



    <script>
    dataLayer = [{ 'userId': <%= currentUser.number %> }];
    </script>
    <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-XXXXXXXX');
    </script>


    And at the top of the body:



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


    Now set up the dataLayer variable and tag in GTM to capture the value and send to GA.



    Hope this helps!






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53318303%2fusing-user-id-with-google-tag-manager-analytics%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      The code / setup I used above does work for showing userId within a userID view on analytics - as Ms.Easy said, you have to wait 24hrs for it to update.






      share|improve this answer




























        0














        The code / setup I used above does work for showing userId within a userID view on analytics - as Ms.Easy said, you have to wait 24hrs for it to update.






        share|improve this answer


























          0












          0








          0







          The code / setup I used above does work for showing userId within a userID view on analytics - as Ms.Easy said, you have to wait 24hrs for it to update.






          share|improve this answer













          The code / setup I used above does work for showing userId within a userID view on analytics - as Ms.Easy said, you have to wait 24hrs for it to update.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 16 '18 at 9:03









          Dan ThoryDan Thory

          407




          407

























              0














              This might not work as you have declared dataLayer.push method above the GTM container.
              You can only declare dataLayer=method above the GTM container.
              To send the user Id to GA, Use the below Code:



              <script>
              dataLayer = [{ 'userId': <%= currentUser.number %> }];
              </script>
              <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-XXXXXXXX');
              </script>


              And at the top of the body:



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


              Now set up the dataLayer variable and tag in GTM to capture the value and send to GA.



              Hope this helps!






              share|improve this answer




























                0














                This might not work as you have declared dataLayer.push method above the GTM container.
                You can only declare dataLayer=method above the GTM container.
                To send the user Id to GA, Use the below Code:



                <script>
                dataLayer = [{ 'userId': <%= currentUser.number %> }];
                </script>
                <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-XXXXXXXX');
                </script>


                And at the top of the body:



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


                Now set up the dataLayer variable and tag in GTM to capture the value and send to GA.



                Hope this helps!






                share|improve this answer


























                  0












                  0








                  0







                  This might not work as you have declared dataLayer.push method above the GTM container.
                  You can only declare dataLayer=method above the GTM container.
                  To send the user Id to GA, Use the below Code:



                  <script>
                  dataLayer = [{ 'userId': <%= currentUser.number %> }];
                  </script>
                  <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-XXXXXXXX');
                  </script>


                  And at the top of the body:



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


                  Now set up the dataLayer variable and tag in GTM to capture the value and send to GA.



                  Hope this helps!






                  share|improve this answer













                  This might not work as you have declared dataLayer.push method above the GTM container.
                  You can only declare dataLayer=method above the GTM container.
                  To send the user Id to GA, Use the below Code:



                  <script>
                  dataLayer = [{ 'userId': <%= currentUser.number %> }];
                  </script>
                  <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-XXXXXXXX');
                  </script>


                  And at the top of the body:



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


                  Now set up the dataLayer variable and tag in GTM to capture the value and send to GA.



                  Hope this helps!







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 16 '18 at 10:09









                  Anuj BAnuj B

                  2391212




                  2391212






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53318303%2fusing-user-id-with-google-tag-manager-analytics%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Florida Star v. B. J. F.

                      Danny Elfman

                      Lugert, Oklahoma