Hello,
I would expect that you can code this using the "gtag" method found here:
https://developers.google.com/tag-platform/security/guides/consent?consentmode=advanced#gtag.js_4
gtag is basically the mechanism to add code directly to a website (i.e. not using GTM), using custom code rules / actions, you can run any JS on your site (with the appropriate triggers).
While I can't provide a complete end-to-end solution for you, since I don't know anything about your implementation, I can confirm that gtag coding works, as I use this for triggering Google conversion codes.
If this is outside your level of confidence, perhaps you can leverage a developer within your organization to help you.
Just make sure to test the implementation thoroughly to ensure it's working.
Good Luck