Where to put tracking script on WordPress?

Good Morning,
I have a question regarding Matomo and WordPress.
I have a website with a woocommerce and we want to enter the tracking codes (scripts) and we have doubts. Should they be entered in the header.php or in the footer.php?
In this case we do not want to install the plugin to reduce loading times.
Thank you very much and greetings.

Hi,

That should not matter. You can place it in the header (as it makes sure that additional Matomo-related code you place in the page works), but if you don’t use any advanced JS features, you can also just put it in the footer of the page.