# How to inject content into \`before-script-load\`?

**URL:** <https://meta.discourse.org/t/how-to-inject-content-into-before-script-load/265989>\
**Category:** Development\
**Created:** [May 23, 2023, 9:35pm UTC](https://meta.discourse.org/t/how-to-inject-content-into-before-script-load/265989 "2023-05-23T21:35:51Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![gormus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gormus/32/428592_2.png) [@gormus](https://meta.discourse.org/u/gormus)\
**Post date:** [May 24, 2023, 4:23pm UTC](https://meta.discourse.org/t/how-to-inject-content-into-before-script-load/265989/5 "2023-05-24T16:23:32Z")

</div>

Thank you @Lilly, @Falco and @pfaffman.

> [@Falco](#):
>
> As for the actual pages in Discourse, themes can inject content in the head element just fine, but without much control of the exact place where it happens

I believe this is my main problem.

As an example, I need to make sure the `dataLayer` object I set is always added to page before any other script, if possible. Especially before GTM loads (either via builtin, or a custom loader).

On my local development box, I tried utilizing the _initializes_, _pre-initializers_, and the `head_tag.html` template;  
And inside `head_tag.html` template, I tried wrapping my code with `<script></script>` and the `<script type="text/discourse-plugin" version="0.1"></script>` tags.

With each one I can see the bootstrapping order relative to each other. But other than this, I don’t seem to have control over the order of the scripts loaded.

---

_[View the full topic](https://meta.discourse.org/t/how-to-inject-content-into-before-script-load/265989)._
