You should never make direct edits to the parent Theme files as they will be lost when the theme is updated. Changes to theme code should only be done with a Child Theme.
However, for adding GT / GTM codes to the site – this guide explains how to do that with hooks.
https://docs.generatepress.com/article/implement-google-tag-manager/
Simple rule with Hooks for adding code – you can use these hooks:
wp_head
– for code inside the <head></head>
wp_body_open
– for code immediately after the opening <body>
tag
wp_footer
– for code in the footer before the closing </body>
tag
Using the Hook method will not be affected by Theme updates.