Is there a way to enable/disable programatically during runtime?

I would like to enable analytics after user clicks confirmation button.

How are you enabling it now? You can instantiate it only when you need it.

I am using annotation configuration

There are more features in Google Analytics that meet the eye, but quickly looking there is no configuration option to do this. However, You should be able to do that using a JS call. Something like this:

getUI().ifPresent(ui -> ui.getPage().executeJs("window['ga-disable-' + $0] = $1;",trackingId, false));

Let us know if that works!