This is a simpler example I could find on how to build your JS function which would inject the script tag.
There are other sample codes on the page, which you can try as well.
Once you have created this function on page or in your custom JS file, call that function in page flow.
Hope this helps.