bug Google Analytics has stopped working
Since June 3rd, when the Git bot applied the following commit --> https://github.com/javierasping/sentinel/commit/0cf1c666d6f4bbddc971541cbe24c068b3ab6c9f, my Google Analytics stats have stopped working. I have been looking into it and the script is not being inserted into the HTML code. My Google tag is G-GVDYVWJLRH.
When I search for it in the generated HTML code, I cannot find it.
javiercruces@HPOMEN15:~/Documentos/sentinel/public$ grep -r "G-GVDYVWJLRH" .
My website is in www.javiercd.es .
I have tried to do as in previous cases where you helped me update to the latest version of Hugo as well as update the dependencies using the following commands:
# update to latest version of all modules
hugo mod get -u
# update the npm dependencies
hugo mod npm pack
# cleanup go.sum file
hugo mod tidy
# install npm dependencies
npm install
My current version of Hugo is:
javiercruces@HPOMEN15:~/Documentos/sentinel$ hugo version
hugo v0.128.1-0ff542b4b9cc7b5cb425bbab8bdb5aace81d0c03+extended linux/amd64 BuildDate=2024-07-02T06:46:41Z VendorInfo=gohugoio
Thank you very much in advance for your help, best regards!!
Same problem here
Since June 3rd, when the Git bot applied the following commit --> javierasping/sentinel@0cf1c66, my Google Analytics stats have stopped working.
In your config.yaml, I see this code which is incorrect IMHO:
142 # Enable Analytics
143 analytics:
144 enabled: true
145 services:
146 # Google Analytics
147 google:
148 id: G-GVDYVWJLRH
According to the Hugo documentation, the Google analytics ID should be go here:
services:
googleAnalytics:
id: "G-GVDYVWJLRH"
In your config.yaml, I can't see a services section at the root level at all. Can you please add one and report back if that cures your problem?
Remark: In case this fixes your problem, this quirk should be fixed in the repo hugo-toha.github.io as well.
Good morning and thank you very much for your interest. I have tried what you suggested, but the problem persists. Google Analytics is not being inserted into the page code. As a temporary solution, I have manually added the following code:
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-GVDYVWJLRH"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-GVDYVWJLRH');
</script>
In previous versions, this or something similar was automatically added by the theme, but since the commit I mentioned, it stopped working that way, so I have temporarily resolved it by adding it manually.
I have added the quotation marks as you mentioned earlier and applied the changes to match the official Hugo documentation, but it hasn't had any effect.
Thank you very much, but none of this has solved the issue!!
Good morning and thank you very much for your interest.
You are welcome.
I have tried what you suggested, but the problem persists.
Sorry to hear that. I checked out your site (https://github.com/javierasping/sentinel/commit/0cf1c666d6f4bbddc971541cbe24c068b3ab6c9f) and was able to resolve your issue. I'm quite confident my advice given above is valid and will resolve your issue once applied correctly.
Can you please download this file to the root folder of your site:
Once downloaded, please delete existing file config.yaml, afterwards rename the downloaded file:
hugo.yaml.txt --> hugo.yaml # GitHub does not allow upload of .yaml files!
Afterwards run hugo (using latest version 0.133.1) and you will find the google analytics script in the html source of your files again.
Does this work for you?
Thank you very much for responding and showing interest!!!! I tried your change with my current repository version and updated Hugo to the latest version.
javiercruces@HPOMEN15:~/Documentos/sentinel$ ls -l
total 240
**-rw-r--r-- 1 javiercruces javiercruces 8138 Aug 31 20:00 _config_.yaml.txt**
-rw-r--r-- 1 javiercruces javiercruces 8055 Sep 1 22:30 hugo.yaml
javiercruces@HPOMEN15:~/Documentos/sentinel$ hugo version
hugo v0.133.1-47d00202e7e61769ce4d14691e43b27852c9cce4+extended linux/amd64 BuildDate=2024-08-26T13:58:46Z VendorInfo=gohugoio
I’m not sure if you have checked in a post that does not have the analytics script; manually verify in the HTML code that the script has not been inserted automatically. I am currently writing new posts and have tried your solution, but it did not work.
I will provide you with an example of a page with the script manually added and another where the script has been removed. Hugo does not add the analytics automatically.
I’m not sure if it’s because with the update the analytics work differently, but in older versions, if I searched for my tag in the HTML, I could verify that Hugo was adding it. In a class activity, I had to submit the HTML code of the generated page. You can check that in any HTML file it is included without me manually adding it in the Markdown file.
I’m providing you with the link in case you want to check it: https://github.com/javierasping/CodigoHTML_sentinel/blob/main/categories/index.html.
Thank you in advance for your help. If, as you mentioned, the analytics are being generated locally, please verify that the analytics script is not manually added in the post file. I always place it first, right below the title, date, and other details (I’ve been doing this since I noticed that the graph in Google Analytics was at 0).
If there’s anything else I can try, please let me know. Thank you very much for your help!
I’m trying to respond as quickly as possible since you’re helping me. Today, you caught me in front of the computer, so I was able to reply quickly. ;)
It's a pity your repository is a fork that cannot be forked again. Therefore I'm unable to create a pull request that fixes your issue.
What I did: I created a new own repository which starts with https://github.com/javierasping/sentinel/commit/0cf1c666d6f4bbddc971541cbe24c068b3ab6c9f and has 3 additional commits
With the second commit, I added the change to config.yaml, as proposed by me: https://github.com/deining/sentinel/commit/7badf14732aa2edf65355a4a8e55274a6f71b99f
Then I regenerated the site via command hugo an d commited the changes in my third commit.
This third commit clearly shows that after changing config.yaml, google analytics script is now added to 115 different html pages in total:
https://github.com/deining/sentinel/commit/060c295371a0239c0dc07050b19f41f589c59837
For me this clearly shows that my change takes effect and effectively resolves your issue!
I hope that clarifies the situation and bring you on the right track!
It's true that with that change, the Analytics script has started to be automatically added, but what surprises me even more is that statistics are disabled (enabled: false) and yet it still works. Thank you so much for taking the time to help me! I'm going to change my config.yaml and remove the statistics I manually added.
Tonight, I'm going to apply the change to the page since I have a few posts where I need to remove the script that I manually added. Thank you so much for helping me, deining!!!
I have applied the commit to my repository. Thank you so much! I ran this script to manually remove the analytics code from all the individual posts where I added it, and the analytics are now working.
find . -type f -name "*.md" | while read -r fichero; do
sed -i '/<!-- Google tag (gtag.js) -->/d' "$fichero"
sed -i '/<script async src="https:\/\/www.googletagmanager.com\/gtag\/js?id=G-GVDYVWJLRH"><\/script>/d' "$fichero"
sed -i '/<script>/d' "$fichero"
sed -i '/window.dataLayer = window.dataLayer || \[\];/d' "$fichero"
sed -i '/function gtag(){dataLayer.push(arguments);}/d' "$fichero"
sed -i '/gtag('\''js'\'', new Date());/d' "$fichero"
sed -i '/gtag('\''config'\'', '\''G-GVDYVWJLRH'\'');/d' "$fichero"
sed -i '/<\/script>/d' "$fichero"
done
I credited you in the commit ;)) https://github.com/javierasping/sentinel/commit/52dc44b2bec44c7346db585d19cc101329504af6
Thanks a lot!!