Hi @Antony,
So I have had a play with this. You can add the following type of Javacript as a function that can then be called on a click (for example if they click the accept cookies button). This will dynamically insert the tracking scripts from google analytics. You can then take this to do the same for any other thirdparty libs you are using. You would then want to probably create a cookie to track that they have accepted so you can just run the script straight away. I havent actually tried this with Google Analytics but I think it should work.
Add the following script to the bottom of your body.
<script>
function addCookie(){
const target = document.body;
const gascript = document.createElement("script");
gascript.setAttribute("async", "")
gascript.src = "https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID";
target.appendChild(gascript);
const gascriptblock = document.createElement("script");
const inlineScript = document.createTextNode(`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments)};
gtag('js', new Date());
gtag('config', 'TRACKING_ID');
`);
gascriptblock.appendChild(inlineScript);
target.appendChild(gascriptblock);
}
</script>
Then you could add this function as an action on your button as a static event for example:
Hope that helps