From f2c8d9923a7f98bbc02f720a863e9f9bd0742c3b Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Fri, 9 Jun 2023 16:28:26 -0700 Subject: [PATCH] Include Google Analytics and Tag Manage when user concents. Fix #13825 --- .../OrchardCore.Google/Analytics/GoogleAnalyticsFilter.cs | 8 ++++++-- .../TagManager/GoogleTagManagerFilter.cs | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Google/Analytics/GoogleAnalyticsFilter.cs b/src/OrchardCore.Modules/OrchardCore.Google/Analytics/GoogleAnalyticsFilter.cs index b0ab1ea993e..0f0e2f33132 100644 --- a/src/OrchardCore.Modules/OrchardCore.Google/Analytics/GoogleAnalyticsFilter.cs +++ b/src/OrchardCore.Modules/OrchardCore.Google/Analytics/GoogleAnalyticsFilter.cs @@ -1,5 +1,7 @@ +using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Html; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.RazorPages; @@ -32,11 +34,13 @@ public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultE if ((context.Result is ViewResult || context.Result is PageResult) && !AdminAttribute.IsApplied(context.HttpContext)) { - if (_scriptsCache == null) + var canTrack = context.HttpContext.Features.Get()?.CanTrack ?? true; + + if (_scriptsCache == null && canTrack) { var settings = (await _siteService.GetSiteSettingsAsync()).As(); - if (!string.IsNullOrWhiteSpace(settings?.TrackingID)) + if (!String.IsNullOrWhiteSpace(settings?.TrackingID)) { _scriptsCache = new HtmlString($"\n\n\n"); } diff --git a/src/OrchardCore.Modules/OrchardCore.Google/TagManager/GoogleTagManagerFilter.cs b/src/OrchardCore.Modules/OrchardCore.Google/TagManager/GoogleTagManagerFilter.cs index 776f2edae12..290f9aa4207 100644 --- a/src/OrchardCore.Modules/OrchardCore.Google/TagManager/GoogleTagManagerFilter.cs +++ b/src/OrchardCore.Modules/OrchardCore.Google/TagManager/GoogleTagManagerFilter.cs @@ -1,5 +1,7 @@ +using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Html; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.RazorPages; @@ -32,11 +34,13 @@ public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultE if ((context.Result is ViewResult || context.Result is PageResult) && !AdminAttribute.IsApplied(context.HttpContext)) { - if (_scriptsCache == null) + var canTrack = context.HttpContext.Features.Get()?.CanTrack ?? true; + + if (_scriptsCache == null && canTrack) { var settings = (await _siteService.GetSiteSettingsAsync()).As(); - if (!string.IsNullOrWhiteSpace(settings?.ContainerID)) + if (!String.IsNullOrWhiteSpace(settings?.ContainerID)) { _scriptsCache = new HtmlString("\n\n"); }