Integrating Disqus an Google Analytics with Hugo properly

Hey guys,
I am new to Hugo, and as far as I understand, integrating with Google Analytics or Hugo requires updating theme specific layout templates.

Following the information on and struggling with the files of the template I use, I got it working.

However, I ended up updating template specific files. So, anytime I want to upgrade my theme, or change it to another one, I will need to make sure that I don’t forget to migrate my changes over as well.

Is there a better way for doing this, so that I don’t have to worry about breaking my comments or analytics integration while changing themes (Octopress 2, for instance, provides a theme independent way to do it)?


Learn about the lookup order, that will make everything easier. But for your specific question, while they don’t exactly carry over between themes (because we can name partials anything), a way to separate changes to templates from the theme you’re using, you can drop it into your site’s layouts directory.

The lookup order looks at your site’s templates before the theme’s templates. So you can put your changes in their own partials, and then just load it wherever you need it.

Hope that makes sense. Theming in Hugo is more like a printing press, rather than say a CMS. We can’t always completely separate the logic from the content, and themes only have loose parameters to allow for the most flexibility. Good luck! :slight_smile:

Thanks maiki. Moving my changes to my site’s layouts folder helped in many ways.
This is also underlined in Theme Customizing as

When you use a theme cloned from its git repository, do not edit the theme’s files directly. Instead, theme customization in Hugo is a matter of overriding the templates …

Other than that, it looks like I’ll just need to learn to live with Hugo’s theme model.