U can create one module in Design Tools (Design Manager) to be avaliable to insert in your landing pages templates.
Is easy to create if you have knowledge for insert one JS code how you mention in your question.
Look this free course in HubSpot, when teaches how create modules and templates: https://academy.hubspot.com/courses/cms-for-developers
Did this post help solve your problem? If so, please mark it as a solution.
Best regards!