Proper way to disable all tracking in the middle of a pageview?

In the process of adapting for GDPR, we want to allow for consent to track to be withdrawn during a pageview. This would effectively stopping collection of data from that point forward, including during the current pageview. I could not find a method in the Javascript tracker for this in the documentation. trackConsentWithdrawn appears to only log that consent has been withdrawn, but does not prevent further page pings or events from being sent to the collector.

What is the most appropriate way to achieve this?

I think one way of doing this would be to set the opt out cookie using setOptOutCookie when the user withdraws consent. This should prevent future events from being sent as long as the opt out cookie has been set.

If you are using POST in the Javascript tracker you may also want to call flushBuffer just before the user withdraws consent in order to fire off any events in localStorage that you had consent to collect so you don’t ‘lose’ these events.

Thanks! I think this is what I needed.