Watch this short video in order to learn how to add custom code to the Magento <head> HTML tag or follow the step-by-step instructions below.
In order to easily add it in the Magento 2 please go to Admin Panel > Content > Configuration.
Then, choose the store view you want the head tag to be changed on or select Global in order to change it on every store views.
Afterwards, find the HTML Head section and add your code in the Scripts and Style Sheets field.
Once the changes have been performed don't forget to press the Save Configuration button and flush Magento Cache.