Adding Google Tagmanager to a Volto Project

Not sure if this the best approach but I’m currently adding Google Tag Manager (GTM) to a Volto project by shadowing components/theme/Header/Header.jsx and inserting a Helmet component. I import it like this:

import { Helmet } from '@plone/volto/helpers';

Here’s an example of how I’m adding the GTM script:

<Helmet>
  <script>{`(function(w,d,s,l,i){...})(window,document,'script','dataLayer','GTM-XXXX');`}</script>
</Helmet>

This approach works, but it requires a full rebuild of the frontend to deploy it. Is there a more efficient way to handle GTM in Volto without needing a redeploy?

Any advice is much appreciated!

I think a more efficient way might be creating a custom hook for the same , I am not sure but I think there is already a custom hook created for the same which will prevent the rebuilding of frontend.

Thanks @aadityaforwork... I don't know enough to determine how I'd use a custom hook to solve this problem.