Adding Google Analytics Question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bowiedawgs01
    New Member
    • Jul 2014
    • 11
    • 5.0.X

    Adding Google Analytics Question

    A previous admin had tried to setup Analytics in the past, and the code was still in there. I created my own Analytics account and want to install it myself. I have a couple of questions.

    I have read people say to remove the <script> tags. Can you be more specific?

    Here's the code Google gives me:

    <!-- Global Site Tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-1"></script>

    <script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments)};
    gtag('js', new Date());

    gtag('config', 'UA-XXXXXXXXX-1');
    </script>

    Do I remove everything in bold? The line with the link to googletagmanager confuses me. How do I remove the <script> tags from that? How should it look if I'm not removing it completely?

    Question 2: The old code that was in there, as well as an example posted on this site with a similar question earlier this year, is completely different than the one Google is giving me. It looks like this:

    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-XXXXXXXXX-1', 'auto');
    ga('send', 'pageview');

    Which one is right? I don't see that old code anywhere. Did Google change it up?

  • braintrainnerd
    Senior Member
    • Oct 2017
    • 228
    • 5.0.x

    #2
    I am in the exact same situation. The current google analytics code is different from the old code.

    Comment

    • William Thomas Jr
      Senior Member
      • Nov 2014
      • 526
      • 5.1.x

      #3


      I would think you could create a new template if you can't find a solution.

      1) Create a new template called footer_google_analytics.

      2) Paste your Google code into it. Save the template.

      3) Go to Products and Hooks in the Admin CP. Click "Add New Hook".

      4) Select "footer_copyright" as the Hook Location.

      5) Give it the title, Google Analytics

      6) For the template name enter footer_google_analytics

      7) Save the hook.

      Other wise, wouldn't putting the code in the footer template before </body> tag work? Or put the code in header include.
      Last edited by William Thomas Jr; Sun 22 Oct '17, 4:47pm.

      Comment


      • Wayne Luke
        Wayne Luke commented
        Editing a comment
        vBulletin Cloud doesn't have access to Template Hooks or to edit Templates directly.
    • braintrainnerd
      Senior Member
      • Oct 2017
      • 228
      • 5.0.x

      #4
      Thanks for your reply William. I will try your suggestions later and report back if I have any problems.

      Comment

      • Wayne Luke
        vBulletin Technical Support Lead
        • Aug 2000
        • 73981

        #5
        We're working to update the software to handle the new format. Currently, you have to add it like this:

        Code:
        </script>
        <!-- Global Site Tag (gtag.js) - Google Analytics -->
        <script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-1"></script>
        <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments)};
        gtag('js', new Date());
        
        gtag('config', 'UA-XXXXXXXXX-1');
        </script>
        <script>
        I am sorry for the confusion.
        Translations provided by Google.

        Wayne Luke
        The Rabid Badger - a vBulletin Cloud demonstration site.
        vBulletin 5 API

        Comment


        • braintrainnerd
          braintrainnerd commented
          Editing a comment
          Should that be <script> at the top and </script> at the bottom?

          Also, in ACP > settings > options > Expand settings group, in the list there are 3 settings related to Analytics - "Google Analytics Account ID", "Enable Google Analytics" and "Google Analytics Javascript". I entered your suggested code into the "Enable Google Analytics" settings, but it doesn't appear to be working - analytics doesn't show anybody visiting my forum, even though I am browsing it. Should I be editing any of the other 2 settings on the list?

        • Wayne Luke
          Wayne Luke commented
          Editing a comment
          In the AdminCP go to Settings -> Options -> Search Engine Tools.

          Set "Enable Google Analytics" to Yes.
          Copy your code in the Google Analytics Javascript box. The closing (</script>) and opening script (<script>) tags that I posted are necessary in that order with the new code at this time.

          Those are the only two options that need to be changed for Analytics.

          Looking at the site, you switched the closing and opening tags that I added in my example above. This breaks the code. They need to be switched like I have them.
      • braintrainnerd
        Senior Member
        • Oct 2017
        • 228
        • 5.0.x

        #6
        Thanks a lot Wayne, it's working now.

        Comment

        • RUBE
          New Member
          • Jul 2017
          • 23
          • 5.3.x

          #7
          Hello
          Wayne Luke Set "Enable Google Analytics" to Yes.
          Copy your code in the Google Analytics Javascript box. The closing (</script>) and opening script (<script>) tags that I posted are necessary in that order with the new code at this time.
          I have vBulletin 5.3.3
          Do we still add those extra java script tags in there like that?

          Thank You for Your Time!!!!!
          RUBE
          Thank You for Your Time!
          RUBE

          Comment

          • Wayne Luke
            vBulletin Technical Support Lead
            • Aug 2000
            • 73981

            #8
            Originally posted by RUBE
            Hello


            I have vBulletin 5.3.3
            Do we still add those extra java script tags in there like that?

            Thank You for Your Time!!!!!
            RUBE
            Yes. They will not be needed in 5.4.0. However, you code shouldn't break if they are left in.
            Translations provided by Google.

            Wayne Luke
            The Rabid Badger - a vBulletin Cloud demonstration site.
            vBulletin 5 API

            Comment

            • RUBE
              New Member
              • Jul 2017
              • 23
              • 5.3.x

              #9
              Originally posted by Wayne Luke

              Yes. They will not be needed in 5.4.0. However, you code shouldn't break if they are left in.
              Thank You Sir for your quick response and...

              Thank You for Your Time!!!!!
              RUBE

              Thank You for Your Time!
              RUBE

              Comment

              • Solid Signal
                New Member
                • Jan 2012
                • 23
                • 4.1.x

                #10
                So using the script code at top as an example, what is the correct format for vB 5.4.0?

                Comment

                • Wayne Luke
                  vBulletin Technical Support Lead
                  • Aug 2000
                  • 73981

                  #11
                  Originally posted by Solid Signal
                  So using the script code at top as an example, what is the correct format for vB 5.4.0?

                  Code:
                  <!-- Global Site Tag (gtag.js) - Google Analytics -->
                  <script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-1"></script>
                  <script>
                  window.dataLayer = window.dataLayer || [];
                  function gtag(){dataLayer.push(arguments)};
                  gtag('js', new Date());
                  
                  gtag('config', 'UA-XXXXXXXXX-1');
                  </script>
                  Translations provided by Google.

                  Wayne Luke
                  The Rabid Badger - a vBulletin Cloud demonstration site.
                  vBulletin 5 API

                  Comment

                  Related Topics

                  Collapse

                  Working...