I see various guides on how to add Google Analytics/ GA into a page dynamically, e.g. for a Single Page Application/ SPA.
How can I do the reverse, i.e. a user clicks a button and Google Analytics is completely removed from that page, without a full page load?
The instructions at https://developers.google.com/analytics/devguides/collection/gtagjs/user-opt-out suggesting to set
window['ga-disable-GA_MEASUREMENT_ID'] = true;
I don't think helps doing this, since the page states
This window property must be set before any calls to gtag() are made