This seems to work:
// Check if cookies are accepted
if ($.cookie('cc_cookie_accept') == 'cc_cookie_accept') {
console.log('cookies accepted');
$.removeCookie('cc_page_cache', {
path : '/',
domain : 'mydomain.com'
});
} else {
console.log('cookies not accepted');
$.cookie('cc_page_cache', 'no_page_cache', {
path : '/',
domain : 'mydomain.com'
});
}
Then in the Page Cache settings I added:
Rejected Cookies: cc_page_cache
Only thing is, on the moment the cached pages were created and cookies weren't accepted yet at that point, you will be served the cached pages without the Google Analytics in it although you did accepted the cookies by that time...