# Ghost code injection fine tunning for Google Tag Manager

**URL:** <https://forum.ghost.org/t/ghost-code-injection-fine-tunning-for-google-tag-manager/1129>\
**Category:** Ideas\
**Created:** [April 30, 2018, 4:26pm UTC](https://forum.ghost.org/t/ghost-code-injection-fine-tunning-for-google-tag-manager/1129 "2018-04-30T16:26:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dsecareanu](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/dsecareanu/32/413_2.png) [@dsecareanu](https://forum.ghost.org/u/dsecareanu)\
**Post date:** [April 30, 2018, 4:26pm UTC](https://forum.ghost.org/t/ghost-code-injection-fine-tunning-for-google-tag-manager/1129/1 "2018-04-30T16:26:11Z")

</div>

Hey all,

Just a quick idea on the Ghost code injection, in relation to Google Tag Manager:

- does it make sense to add a section of code injection also right after the opening tag?
- the idea is that the standard Google Tag Manager implementation requires a two part tracking code to be inserted (one in header and one in body)
- I know it’s kind of a single exception, but it would allow for much more flexibility as all other tags could be fired through GTM and would make the Ghost code injection cleaner

Thanks!

---

<div class="post-metadata">

**Author:** ![dsecareanu](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/dsecareanu/32/413_2.png) [@dsecareanu](https://forum.ghost.org/u/dsecareanu)\
**Post date:** [May 1, 2018, 6:19pm UTC](https://forum.ghost.org/t/ghost-code-injection-fine-tunning-for-google-tag-manager/1129/2 "2018-05-01T18:19:38Z")

</div>

Also, for post injection, I know there is the option to inject something different in every post, but I also think that a global before/after post (not just header/footer) injection would be useful as well (especially for those wanting to monetize their Ghost blog/publication in any way).

---

<div class="post-metadata">

**Author:** ![HauntedThemes](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/hauntedthemes/32/15301_2.png) [@HauntedThemes](https://forum.ghost.org/u/HauntedThemes)\
**Post date:** [May 1, 2018, 7:46pm UTC](https://forum.ghost.org/t/ghost-code-injection-fine-tunning-for-google-tag-manager/1129/3 "2018-05-01T19:46:20Z")

</div>

All your problems can be solved by modifying the theme. I don’t think a code injection right after the opening tag would be useful. Simply edit your `default.hbs` and put your code in there, after `<body>`. For global before/after post you can edit `post.hbs` and inject the desired code in there. No need for extra fields in Ghost admin.

---

<div class="post-metadata">

**Author:** ![dsecareanu](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/dsecareanu/32/413_2.png) [@dsecareanu](https://forum.ghost.org/u/dsecareanu)\
**Post date:** [May 1, 2018, 8:08pm UTC](https://forum.ghost.org/t/ghost-code-injection-fine-tunning-for-google-tag-manager/1129/4 "2018-05-01T20:08:32Z")

</div>

By the same token neither the current code injection feature isn’t useful as any code can be added to the theme files. 😉

While I agree with you, I think that for non tech users an option in the admin is useful as it reduces the required theme hacks.

---

<div class="post-metadata">

**Author:** ![em\_div](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/em_div/32/383_2.png) [@em\_div](https://forum.ghost.org/u/em_div)\
**Post date:** [May 3, 2018, 4:18am UTC](https://forum.ghost.org/t/ghost-code-injection-fine-tunning-for-google-tag-manager/1129/5 "2018-05-03T04:18:48Z")

</div>

And reduces issues that can arise from theme updates or ghost updates. The more vanilla, the easier.

---

<div class="post-metadata">

**Author:** ![NabilaMoumen](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/nabilamoumen/32/2790_2.png) [@NabilaMoumen](https://forum.ghost.org/u/NabilaMoumen)\
**Post date:** [March 16, 2019, 7:58am UTC](https://forum.ghost.org/t/ghost-code-injection-fine-tunning-for-google-tag-manager/1129/6 "2019-03-16T07:58:07Z")

</div>

Hi,

Indeed, it would be so much appreciated to have the option to insert a code into the theme (and not only into the header or footer) directly via the interface (e.g. for GTM purposes).

Anyway, I’ve tried the manipulation (even thought I am not technical) and here’s my issue:

- I need to download the theme to be able to mofify the file default.hbs
- the I am able to modify the file adding my tag
- however, when I download my zip into Ghost, I am requested to give a different name than the original template, so I do and I can then activate my new template
- Here problem: I have an 505 error message on my blog saying “ENOENT: no such file or directory, open ‘/home/ghost/content/themes/casper–1-/default.hbs’”

Any idea where do I need to change the path to the new template name ???
