Hi there,
you SHOULD NOT edit the Themes files ever, aside of potentially breaking things, any changes you make to the theme files will be lost when the theme is updated.
To insert codes use the Hook Element:
https://docs.generatepress.com/article/hooks-element-overview/
For codes in the <head> – use the wp_head hook
For codes after the opening <body> tag – use the wp_body_open hook
For codes in the <footer> – use the wp_footer hook.
And here we provide a guide on using them for adding Google Tag Manager:
https://docs.generatepress.com/article/implement-google-tag-manager/
The same applies to Classic Analytics, the only difference is Classic only requires the code in the head.