From a0e6b413ce00bdd8f7834cae6e4b9e638f6526fd Mon Sep 17 00:00:00 2001 From: Szabolcs Deme Date: Wed, 14 Jun 2023 02:06:39 +0200 Subject: [PATCH 1/3] Adding shape for GoogleTag --- .../ViewModels/GoogleTagViewModel.cs | 10 +++++++ Lombiq.BaseTheme/Views/GoogleTag.cshtml | 30 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 Lombiq.BaseTheme/ViewModels/GoogleTagViewModel.cs create mode 100644 Lombiq.BaseTheme/Views/GoogleTag.cshtml diff --git a/Lombiq.BaseTheme/ViewModels/GoogleTagViewModel.cs b/Lombiq.BaseTheme/ViewModels/GoogleTagViewModel.cs new file mode 100644 index 0000000..ba746d7 --- /dev/null +++ b/Lombiq.BaseTheme/ViewModels/GoogleTagViewModel.cs @@ -0,0 +1,10 @@ +using OrchardCore.DisplayManagement.Views; + +namespace Lombiq.BaseTheme.ViewModels; + +public class GoogleTagViewModel : ShapeViewModel +{ + public string GoogleTagPropertyId { get; set; } + public string CookieDomain { get; set; } + public GoogleTagViewModel() => Metadata.Type = "GoogleTag"; +} diff --git a/Lombiq.BaseTheme/Views/GoogleTag.cshtml b/Lombiq.BaseTheme/Views/GoogleTag.cshtml new file mode 100644 index 0000000..ba67a3e --- /dev/null +++ b/Lombiq.BaseTheme/Views/GoogleTag.cshtml @@ -0,0 +1,30 @@ +@model Lombiq.BaseTheme.ViewModels.GoogleTagViewModel + +@using Microsoft.AspNetCore.Http.Features; +@using Microsoft.Extensions.Hosting; +@using OrchardCore.Environment.Shell + +@inject IHostEnvironment HostEnvironment + +@{ + var trackingConsentFeature = ViewContext.HttpContext.Features.Get(); + var cookieDomain = string.Empty; + + if(!string.IsNullOrEmpty(Model.CookieDomain)) + { + cookieDomain =$", {{'cookie_domain': '{ Model.CookieDomain }' }}"; + } +} + +@if ((trackingConsentFeature is null || trackingConsentFeature.CanTrack)) +{ + + + +} From b4a75750a5eb5120edb2bf73402c03897de0b3cf Mon Sep 17 00:00:00 2001 From: Szabolcs Deme Date: Wed, 14 Jun 2023 02:13:58 +0200 Subject: [PATCH 2/3] Adding production check --- Lombiq.BaseTheme/Views/GoogleTag.cshtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lombiq.BaseTheme/Views/GoogleTag.cshtml b/Lombiq.BaseTheme/Views/GoogleTag.cshtml index ba67a3e..87cecd4 100644 --- a/Lombiq.BaseTheme/Views/GoogleTag.cshtml +++ b/Lombiq.BaseTheme/Views/GoogleTag.cshtml @@ -16,7 +16,7 @@ } } -@if ((trackingConsentFeature is null || trackingConsentFeature.CanTrack)) +@if (HostEnvironment.IsProduction() && (trackingConsentFeature is null || trackingConsentFeature.CanTrack)) { From c1900d01d7c92c734bc0d1fbab7b51e2162c5d1d Mon Sep 17 00:00:00 2001 From: Szabolcs Deme Date: Wed, 14 Jun 2023 18:51:56 +0200 Subject: [PATCH 3/3] Putting the script in the head tag --- Lombiq.BaseTheme/Views/GoogleTag.cshtml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Lombiq.BaseTheme/Views/GoogleTag.cshtml b/Lombiq.BaseTheme/Views/GoogleTag.cshtml index 87cecd4..e7836ee 100644 --- a/Lombiq.BaseTheme/Views/GoogleTag.cshtml +++ b/Lombiq.BaseTheme/Views/GoogleTag.cshtml @@ -10,17 +10,16 @@ var trackingConsentFeature = ViewContext.HttpContext.Features.Get(); var cookieDomain = string.Empty; - if(!string.IsNullOrEmpty(Model.CookieDomain)) + if (!string.IsNullOrEmpty(Model.CookieDomain)) { - cookieDomain =$", {{'cookie_domain': '{ Model.CookieDomain }' }}"; + cookieDomain = $", {{'cookie_domain': '{Model.CookieDomain}' }}"; } } @if (HostEnvironment.IsProduction() && (trackingConsentFeature is null || trackingConsentFeature.CanTrack)) { - - - +