diff --git a/Oqtane.Client/Themes/Controls/Theme/CookieConsent.razor b/Oqtane.Client/Themes/Controls/Theme/CookieConsent.razor index c1cf1501..1ff5406b 100644 --- a/Oqtane.Client/Themes/Controls/Theme/CookieConsent.razor +++ b/Oqtane.Client/Themes/Controls/Theme/CookieConsent.razor @@ -120,6 +120,9 @@ cookieString = _canTrack ? await CookieConsentService.CreateConsentCookieAsync() : await CookieConsentService.WithdrawConsentCookieAsync(); } + //update the page state + PageState.AllowCookies = _canTrack; + if (!string.IsNullOrEmpty(cookieString)) { var interop = new Interop(JSRuntime); diff --git a/Oqtane.Client/UI/SiteRouter.razor b/Oqtane.Client/UI/SiteRouter.razor index 9f2b7e99..79ff5b42 100644 --- a/Oqtane.Client/UI/SiteRouter.razor +++ b/Oqtane.Client/UI/SiteRouter.razor @@ -14,6 +14,7 @@ @inject IUrlMappingService UrlMappingService @inject ILogService LogService @inject ISettingService SettingService +@inject ICookieConsentService CookieConsentService @inject IJSRuntime JSRuntime @implements IHandleAfterRender @implements IDisposable @@ -293,6 +294,14 @@ // load additional metadata for modules (page, modules) = ProcessModules(site, page, modules, moduleid, action, (!string.IsNullOrEmpty(page.DefaultContainerType)) ? page.DefaultContainerType : site.DefaultContainerType, SiteState.Alias); + //cookie consent + var _allowCookies = PageState?.AllowCookies; + if(!_allowCookies.HasValue) + { + var cookieConsentSettings = SettingService.GetSetting(site.Settings, "CookieConsent", string.Empty); + _allowCookies = string.IsNullOrEmpty(cookieConsentSettings) || await CookieConsentService.CanTrackAsync(cookieConsentSettings == "optout"); + } + // populate page state (which acts as a client-side cache for subsequent requests) _pagestate = new PageState { @@ -316,7 +325,8 @@ ReturnUrl = returnurl, IsInternalNavigation = _isInternalNavigation, RenderId = Guid.NewGuid(), - Refresh = false + Refresh = false, + AllowCookies = _allowCookies.GetValueOrDefault(true) }; OnStateChange?.Invoke(_pagestate);