Skip to main content
Known Participant
March 14, 2024
Answered

Question about placing a google analytics script on your html-page

  • March 14, 2024
  • 5 replies
  • 2650 views

Dear all,

 

I have a google analytics script I need to place in the code of my website www.dickensfellowship.nl.

The instructions tell that I must place in under the <head> tag on each html-page. Since my website has many pages, this will take a lot of work. As most pages are connected to a template I thought it was best to put this code in there instead and update the connected pages so that I could save time. However, I'm not sure if this code will work when it's placed in a non-editable region within a page. What's your experience? Your advice?

 

Silly question, perhaps.

 

    This topic has been closed for replies.
    Correct answer L e n a

    You have no problem placing this code fragment within a TEMPLATE.

    If you're using several different templates, depending on the sections of your site, and since you're already using a proprietary aspect of DW, I'd advise you to use a LIBRARY element instead, which you'll then insert into each TEMPLATE. This way, if you need to modify GA's snipet, you'll only have to make one modification, and DW will pass it on to all the templates, and then all the pages.

    For my part, I prefer to place this fragment just before the closing BODY, as this allows me to intercept only real user interaction, not to interfere with the loading time of real content and thus improve usability. Placing it in the HEADER benefits GA more, as it analyzes various behaviors that are favorable to it, and not really to you.

    By the way, and just for your information, have you heard of Piwik, now Matomo https://matomo.org/?

    5 replies

    Nancy OShea
    Adobe Expert
    March 15, 2024

    You have a place for Google Tag Manager in your current template.  Analytics can go in the same place.

     

    <!-- Include all compiled plugins (below), or include individual files as needed -->  
    <script src="js/popper.min.js"></script>
    <script src="js/bootstrap-4.4.1.js"></script>
    <!-- Google tag (gtag.js) -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-2B2L2HYSVP"></script>
    <script>window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date()); gtag('config', 'G-2B2L2HYSVP');
    </script>
    </body>
    </html>

     

    Nancy O'Shea— Product User, Community Expert &amp; Moderator
    Inspiring
    March 15, 2024
    quote

    You have a place for Google Tag Manager in your current template.  Analytics can go in the same place.

     

    <!-- Include all compiled plugins (below), or include individual files as needed -->  
    <script src="js/popper.min.js"></script>
    <script src="js/bootstrap-4.4.1.js"></script>
    <!-- Google tag (gtag.js) -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-2B2L2HYSVP"></script>
    <script>window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date()); gtag('config', 'G-2B2L2HYSVP');
    </script>
    </body>
    </html>
    By @Nancy OShea

     

    I share your reasoning 100%, but going further if @edinav24550678 uses two distinct templates in the website, a LIBRARY item will provide more flexible encapsulation of your code (see previous comment above)... than copying this code directly into the TEMPLATE. 

    Known Participant
    March 15, 2024

    Thank you all for your replies. I've added the google-script on each page via the templates just above the "body"-closing tag and uploaded all pages. I've also added the code to my Library. Just wait a week to see what results Google Analytics will show.

    Nancy OShea
    Adobe Expert
    March 14, 2024

    1. I don't recommend using Library Items. They're too limited.  And besides, you're already using a sitewide Template.  You don't need both.

     

    2. Inasmuch as analytics scripts are not mission critical and can actually decrease performance, you want the imporant parts of your page to take priority & load first. 

     

    Please do what @BenPleysier suggested and add the Google Analytics 4 code just above the closing </body> tag of your main Template.dwt file. 

     

    <script>

    <!--Google Analytics 4 Code here-->

    </script>

    </body>

     

    3. Save Template & populate changes to child pages.

    4. Republish your entire site.

     

    You should start seeing results in your Google Console with 48 hours.

     

    Nancy O'Shea— Product User, Community Expert &amp; Moderator
    Brainiac
    March 14, 2024
    quote

     

    Please do what @BenPleysier suggested and add the Google Analytics 4 code just above the closing </body> tag of your main Template.dwt file. 

     


    By @Nancy OShea

     

    Ben didn't suggest it, Lena did. The bloody big 'thumbs up' emoji is rather eye catching though!

    Nancy OShea
    Adobe Expert
    March 14, 2024
    quoteBen didn't suggest it, Lena did.
    By @osgood_

    =========

    I stand corrected.

    The mention of Library Items chased me away.  🙂

     

     

     

     

    Nancy O'Shea— Product User, Community Expert &amp; Moderator
    Adobe Expert
    March 14, 2024

    More than likely Google Analytics may end up being the first in a long line of scripts you will need to add to your pages. I would typically recommend looking to install Google Tag Manager ( https://tagmanager.google.com/#/home ) and embed the analytics script on your page and embed all of your other scripts like it as well. This will give you better management to avoid DW templates or adding code manually.  In addition you will also be able to preview your changes before you publish them allowing you to test before integrating new scripts that could potentially break your site.

    L e n aCorrect answer
    Inspiring
    March 14, 2024

    You have no problem placing this code fragment within a TEMPLATE.

    If you're using several different templates, depending on the sections of your site, and since you're already using a proprietary aspect of DW, I'd advise you to use a LIBRARY element instead, which you'll then insert into each TEMPLATE. This way, if you need to modify GA's snipet, you'll only have to make one modification, and DW will pass it on to all the templates, and then all the pages.

    For my part, I prefer to place this fragment just before the closing BODY, as this allows me to intercept only real user interaction, not to interfere with the loading time of real content and thus improve usability. Placing it in the HEADER benefits GA more, as it analyzes various behaviors that are favorable to it, and not really to you.

    By the way, and just for your information, have you heard of Piwik, now Matomo https://matomo.org/?

    BenPleysier
    Adobe Expert
    March 14, 2024
    quote

    For my part, I prefer to place this fragment just before the closing BODY, as this allows me to intercept only real user interaction, not to interfere with the loading time of real content and thus improve usability. Placing it in the HEADER benefits GA more, as it analyzes various behaviors that are favorable to it, and not really to you.


    By @L e n a

     

    Wappler is the DMXzone-made Dreamweaver replacement and includes the best of their powerful extensions, as well as much more!
    Jon Fritz
    Adobe Expert
    March 14, 2024

    Put it in the Template, outside the editable region, as instructed. Then allow DW to update all of your Child pages connected to your .dwt file.

    It will work as expected.

    Known Participant
    March 14, 2024

    Thanks for your reply.