Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix google analytics feature #989

Merged
merged 4 commits into from
Nov 26, 2024

Conversation

joyao
Copy link
Member

@joyao joyao commented Oct 1, 2024

Issue

Fixes #955

Description

Fix google analytics feature based on official document.
https://gohugo.io/templates/embedded/#google-analytics

Test Evidence

image

Copy link

netlify bot commented Oct 1, 2024

Deploy Preview for toha-ci ready!

Name Link
🔨 Latest commit 1399825
🔍 Latest deploy log https://app.netlify.com/sites/toha-ci/deploys/6746607090587a0008dcd0ef
😎 Deploy Preview https://deploy-preview-989--toha-ci.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@BernatBC BernatBC added the bug-fix Bug fixes label Oct 2, 2024
Copy link
Member

@hossainemruz hossainemruz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @joyao ! Thank you for the PR. Look like we are breaking compatibility here. With this change, following configuration will not work anymore:

services:
  googleAnalytics:
    ID: G-MEASUREMENT_ID

Do we want to force user to use analytics configuration from site.Params.analytics.services.google.id ? In that case, we should also provide a way do specify respectDoNotTrack under site.Params.analytics.services.google section.

@joyao
Copy link
Member Author

joyao commented Oct 18, 2024

Hi @joyao ! Thank you for the PR. Look like we are breaking compatibility here. With this change, following configuration will not work anymore:

services:
  googleAnalytics:
    ID: G-MEASUREMENT_ID

Do we want to force user to use analytics configuration from site.Params.analytics.services.google.id ? In that case, we should also provide a way do specify respectDoNotTrack under site.Params.analytics.services.google section.

I think both methods should be supported. I’ll fix it and thanks for your suggestion.

@joyao
Copy link
Member Author

joyao commented Oct 21, 2024

Hi @hossainemruz, under the "{{ with .google }}" condition, my original changes support both project custom settings and original settings as following, and have been tested.

analytics:
  enabled: true
  services:
    # Google Analytics
    google:
      id: G-H4LBG7NDFZ
      respectDoNotTrack: false
services:
  googleAnalytics:
    ID: G-H4LBG7NDFZ
privacy:
  googleAnalytics:
    disable: false
    respectDoNotTrack: true

So I just add the "respectDoNotTrack" part.

@joyao joyao requested a review from hossainemruz October 21, 2024 15:43
@jamesdeluk
Copy link

So what's the current workaround for getting analytics working, manually having these two files within layouts?

@joyao
Copy link
Member Author

joyao commented Nov 16, 2024

So what's the current workaround for getting analytics working, manually having these two files within layouts?

Hi @jamesdeluk, this PR hasn't been merged yet. If you want to have this fixed feature, you can merge my branch or fix these two files manually in your project.

@jamesdeluk
Copy link

Hi @jamesdeluk, this PR hasn't been merged yet. If you want to have this fixed feature, you can merge my branch or fix these two files manually in your project.

Thanks. And which is the best yaml config of the two above?

@joyao
Copy link
Member Author

joyao commented Nov 16, 2024

Thanks. And which is the best yaml config of the two above?

This one:

analytics:
  enabled: true
  services:
    # Google Analytics
    google:
      id: G-H4LBG7NDFZ
      respectDoNotTrack: false

You don't need to make many changes to this, this section is already in the current hugo.yaml file. You just need to change the id.

@jamesdeluk
Copy link

This one:

analytics:
  enabled: true
  services:
    # Google Analytics
    google:
      id: G-H4LBG7NDFZ
      respectDoNotTrack: false

You don't need to make many changes to this, this section is already in the current hugo.yaml file. You just need to change the id.

Great, thanks! And I guess respectDoNotTrack can be set to true and it'll still work?

@joyao
Copy link
Member Author

joyao commented Nov 16, 2024

Great, thanks! And I guess respectDoNotTrack can be set to true and it'll still work?

Yes, it should work. :)

@joyao
Copy link
Member Author

joyao commented Nov 25, 2024

Hi @hossainemruz, I believe it works as expected. Please take your time reviewing it. Thank you.

@hossainemruz
Copy link
Member

Sorry for taking this long. I had plan to merge it this weekend but couldn't make it. I will definitely make sure to merge within next weekend.

@hossainemruz hossainemruz merged commit 3be5a58 into hugo-toha:main Nov 26, 2024
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-fix Bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug Google Analytics has stopped working
4 participants