You’re actually able to add any JS code inside pages and layouts, you just need to remove the tags.
I think this topic might be helpful: