1) Log in to the backend of your OpenCart store.
2) Under "Design" goto "Theme Editor" > "Common" select the "Edit" option for the layout you want to add the script to.
3) Open the "header.twig" or "header.tpl" file and locate the </head> tag. Before the </head> tag, add your script.
OR
4) Open the "footer.twig" or "footer.tpl" file and locate the </body> tag. Before the </body> tag, add your script.
5) Save the file and clear the cache of your opencart store.
Test your changes by visiting the frontend of your store to see if the script is working as expected.