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

Google Analytics not working #27

Open
adityas129 opened this issue Mar 10, 2020 · 1 comment
Open

Google Analytics not working #27

adityas129 opened this issue Mar 10, 2020 · 1 comment

Comments

@adityas129
Copy link

I've been trying to get google analytics to work but with no success. Here are the steps I have taken that should have apparently done the job:

  1. Add google tag id in config.toml: googleAnalytics = "UA-12345-2"

  2. Create a folder in themes/hugo-coder-portfolio/layout/partials named google

  3. Create a file in the folder created in step two called analytics.html and paste my google tracking code there

  4. Add this snippet to themes/hugo-coder-portfolio/layout/partials/header.html:

    {{ template "_internal/google_analytics.html" . }} {{ template "_internal/google_analytics_async.html" . }} {{ partials "google/analytics" . }}
  5. hugo serve -D

According to a few blog posts (https://gohugo.io/templates/internal/#use-the-google-analytics-template and https://www.soberkoder.com/google-analytics-hugo/ and https://bash-prompt.net/guides/custom-html-jugo/) this should have worked but did not.

Is there something that I am doing wrong?

@erisnar
Copy link

erisnar commented Mar 28, 2021

Hei,

For anyone interested in this I solved this by following:

Create a new folder layouts in the root directory. Copy the contents of /themes/coder-portfolio/layouts/partials/header.html into /layouts/header.html.

Add the following code:

<head>
  {{ template "_internal/google_analytics.html" . }}
  {{ template "_internal/google_analytics_async.html" . }}
</head>

In your config.toml file add:

googleAnalytics = "<TRACKING CODE>"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants