There are times when you need to add tracking code to your WordPress website. Sometimes your WordPress theme will provide an option but if you can look at a WordPress plugin.
If you just need to add code to one page, just had the code into a text box. It won’t be displayed when you publish the page.
But if you want the code on all pages, I would recommend the Head, Footer and Post Injections plugin by Stefano Lissa. It gives a number of options for many different placement of tracking code. If you just to add some code to the Head section of our HTML, just copy and paste the code.
An alternative plugin is Insert Headers and Footers by WPBeginner. It is very easy without a lot of options.
Finally, if you want to get very fancy, Google has something called Google Tag Manager. It allows you to add code just once to your website and then add additional things without having to edit any part of your website. It is very robust but also has a steep learning curve.