How do I add a script just above the closing body tag?
You can achieve this simply by using jquery. If you want to access it from all theme pages you need to add the below line in your global common js file which has access to all the theme pages in the app.

$('body').append('&lt;script src="/name-of-your-library"&gt;&lt;/script&gt;');