Google Tag Manager provides a code snippet that can be added to your pages in your HubSpot settings. For more information about Google Tag Manager, see Google's getting started guide, which includes a page on common questions.
Google advises the Javascript code snippet (labeled 1 in the above screenshot) to be placed as high in the <head> of the page as possible. This can be done in your settings in the Site header HTML field.
Google also advises that the <noscript> snippet (labeled 2 in the above screenshot) is placed after the opening <body> tag. However, it can be added to other sections of the page, depending on a website's settings. See Google Tag Manager's documentation for more details.
When adding code to the body of your HubSpot pages site-wide, you can only add the code directly before the closing </body> tag. This can be done in your settings in the Site footer HTML field.
Please note: if you add code to the header or footer HTML for a specific domain, it will override any code you have placed in header and footer HTML for All domains. Learn more about the order that code is applied to your pages.