# Where to add tracking code?

**URL:** <https://discourse.gohugo.io/t/where-to-add-tracking-code/22434>\
**Category:** support\
**Created:** [December 22, 2019, 1:40pm UTC](https://discourse.gohugo.io/t/where-to-add-tracking-code/22434 "2019-12-22T13:40:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![eggbean](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/eggbean/32/10191_2.png) [@eggbean](https://discourse.gohugo.io/u/eggbean)\
**Post date:** [December 22, 2019, 1:40pm UTC](https://discourse.gohugo.io/t/where-to-add-tracking-code/22434/1 "2019-12-22T13:40:34Z")

</div>

Where can I add tracking code within the element? This is not for Google Analytics, so I can’t use the config.toml file, unless I can use it in a way I do not know about. I would obviously prefer that to editing the theme file, so that I can easily switch themes. Thanks.

---

<div class="post-metadata">

**Author:** ![davidsneighbour](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/davidsneighbour/32/24507_2.png) [@davidsneighbour](https://discourse.gohugo.io/u/davidsneighbour)\
**Post date:** [December 22, 2019, 1:43pm UTC](https://discourse.gohugo.io/t/where-to-add-tracking-code/22434/2 "2019-12-22T13:43:02Z")

</div>

That depends on your theme. Some have a special template file where you can add code “right after the `<body>`-tag”, in some others you have to add the code by yourself.

1. Post your repository here and we’ll have a look if there is an easy place.
2. Where should the code go, into the `<head>`, after `<body>` opens or at the end of `<body>`? A good theme will offer these three locations for you.

---

<div class="post-metadata">

**Author:** ![eggbean](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/eggbean/32/10191_2.png) [@eggbean](https://discourse.gohugo.io/u/eggbean)\
**Post date:** [December 22, 2019, 1:45pm UTC](https://discourse.gohugo.io/t/where-to-add-tracking-code/22434/3 "2019-12-22T13:45:04Z")

</div>

Thanks. I am currently using this theme: [https://github.com/yursan9/manis-hugo-theme](https://github.com/yursan9/manis-hugo-theme)

I would prefer to put the tracking code within `<head>.`

---

<div class="post-metadata">

**Author:** ![davidsneighbour](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/davidsneighbour/32/24507_2.png) [@davidsneighbour](https://discourse.gohugo.io/u/davidsneighbour)\
**Post date:** [December 22, 2019, 1:46pm UTC](https://discourse.gohugo.io/t/where-to-add-tracking-code/22434/4 "2019-12-22T13:46:22Z")

</div>

use the code button for html-code. that’s this one; `</>` on top of this editor when you write a message. Then we can see that you might have written `<head>` there 😉

---

<div class="post-metadata">

**Author:** ![davidsneighbour](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/davidsneighbour/32/24507_2.png) [@davidsneighbour](https://discourse.gohugo.io/u/davidsneighbour)\
**Post date:** [December 22, 2019, 1:50pm UTC](https://discourse.gohugo.io/t/where-to-add-tracking-code/22434/5 "2019-12-22T13:50:52Z")

</div>

Assuming you have installed the theme normally (meaning there is a folder `themes/themename` with that theme in your repo do the following:

1. create a folder layouts in the ROOT DIRECTORY _of your website (not the theme)_ (where the config.toml) is located.
2. in there create a folder partials
3. in _there_ create a file `meta.html`
4. in that file place the content of this: [https://github.com/yursan9/manis-hugo-theme/blob/master/layouts/partials/meta.html](https://github.com/yursan9/manis-hugo-theme/blob/master/layouts/partials/meta.html)
5. then add your code before `</head>`

These are the rules:

- Everything in your “local” layouts directory (the one you just created) will overwrite what happens in your theme. To change something from the theme, copy the file in question in the same place in your own layouts directory and Hugo will use _that_ file instead of the theme file
- If the theme gets an update you will have to check if the contents of the original changed or are the same. You might need to copy it over into your modification.

---

<div class="post-metadata">

**Author:** ![eggbean](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/eggbean/32/10191_2.png) [@eggbean](https://discourse.gohugo.io/u/eggbean)\
**Post date:** [December 22, 2019, 1:54pm UTC](https://discourse.gohugo.io/t/where-to-add-tracking-code/22434/6 "2019-12-22T13:54:55Z")

</div>

Ah yes, all makes sense. Thank you.
