diff --git a/README.md b/README.md index 1647dcc..c45430a 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,7 @@ dotnet add package Kentico.Xperience.TagManager 3. In the administration go to UI application 'Tag Management'. 4. Create a new record: + - Fill in a tag name - Select one of the channels. - Select whether you want to use Custom Code Snippet or other Snippet type - We have prepared some of the most often used types: @@ -101,7 +102,9 @@ dotnet add package Kentico.Xperience.TagManager - Bottom of the head - inserts a script right before the closing head tag. - Top of the body - inserts a script immediately after the opening body tag. - Bottom of the body - inserts a script right before the closing body tag. + - Select tag location within the rendered page HTML - Fill in a consent if required. + - Check 'Enable tag rendering' to activate the tag or uncheck to deactivate - Select whether you want to display tags in the Xperience administration preview or Page Builder, or both. This option defaults to None. 5. During rendering the livesite page, the Tag manager module automatically adds custom code snippets with accepted consents to defined locations. 6. To dynamically update the rendered code snippets, for example if a consent is accepted, call javascript function `window.xperience.tagManager.updateCodeSnippets()`. diff --git a/images/screenshots/create_custom_snippet.png b/images/screenshots/create_custom_snippet.png index 0582dd0..eb880c4 100644 Binary files a/images/screenshots/create_custom_snippet.png and b/images/screenshots/create_custom_snippet.png differ diff --git a/images/screenshots/create_snippet.png b/images/screenshots/create_snippet.png index 3b31e54..dc80b07 100644 Binary files a/images/screenshots/create_snippet.png and b/images/screenshots/create_snippet.png differ diff --git a/images/screenshots/listing.png b/images/screenshots/listing.png index bea23ab..44a6c21 100644 Binary files a/images/screenshots/listing.png and b/images/screenshots/listing.png differ diff --git a/images/screenshots/ui_application.png b/images/screenshots/ui_application.png index 9da1408..879b5cf 100644 Binary files a/images/screenshots/ui_application.png and b/images/screenshots/ui_application.png differ diff --git a/src/Kentico.Xperience.TagManager/Admin/CodeSnippetConfigurationModel.cs b/src/Kentico.Xperience.TagManager/Admin/CodeSnippetConfigurationModel.cs index da69810..4f4d6f1 100644 --- a/src/Kentico.Xperience.TagManager/Admin/CodeSnippetConfigurationModel.cs +++ b/src/Kentico.Xperience.TagManager/Admin/CodeSnippetConfigurationModel.cs @@ -38,7 +38,10 @@ internal class CodeSnippetConfigurationModel [ObjectIdSelectorComponent(objectType: ConsentInfo.OBJECT_TYPE, Label = "Consent", Order = 6, Placeholder = "No consent needed")] public IEnumerable ConsentIDs { get; set; } = []; - [DropDownComponent(Label = "Kentico administration Display Mode", Options = CodeSnippetExtensions.DisplayModeFormComponentOptions, Order = 7)] + [CheckBoxComponent(Label = "Enable tag rendering", Order = 7)] + public bool Enable { get; set; } = true; + + [DropDownComponent(Label = "Kentico administration Display Mode", Options = CodeSnippetExtensions.DisplayModeFormComponentOptions, Order = 8)] public string DisplayMode { get; set; } = "None"; public void MapToChannelCodeSnippetInfo(ChannelCodeSnippetItemInfo info) @@ -51,5 +54,6 @@ public void MapToChannelCodeSnippetInfo(ChannelCodeSnippetItemInfo info) info.ChannelCodeSnippetItemIdentifier = TagIdentifier; info.ChannelCodeSnippetItemCode = Code; info.ChannelCodeSnippetAdministrationDisplayMode = DisplayMode; + info.ChannelCodeSnippetItemEnable = Enable; } } diff --git a/src/Kentico.Xperience.TagManager/Admin/InfoModels/ChannelCodeSnippetItem/ChannelCodeSnippetItemInfo.generated.cs b/src/Kentico.Xperience.TagManager/Admin/InfoModels/ChannelCodeSnippetItem/ChannelCodeSnippetItemInfo.generated.cs index 4aba8fc..a502db6 100644 --- a/src/Kentico.Xperience.TagManager/Admin/InfoModels/ChannelCodeSnippetItem/ChannelCodeSnippetItemInfo.generated.cs +++ b/src/Kentico.Xperience.TagManager/Admin/InfoModels/ChannelCodeSnippetItem/ChannelCodeSnippetItemInfo.generated.cs @@ -162,6 +162,16 @@ public virtual int ChannelCodeSnippetItemConsentId set => SetValue(nameof(ChannelCodeSnippetItemConsentId), value); } + /// + /// Channel code snippet consent ID. + /// + [DatabaseField] + public virtual bool ChannelCodeSnippetItemEnable + { + get => ValidationHelper.GetBoolean(GetValue(nameof(ChannelCodeSnippetItemEnable)), true); + set => SetValue(nameof(ChannelCodeSnippetItemEnable), value); + } + /// /// Deletes the object using appropriate provider. diff --git a/src/Kentico.Xperience.TagManager/Admin/TagManagerModuleInstaller.cs b/src/Kentico.Xperience.TagManager/Admin/TagManagerModuleInstaller.cs index d8ad0a4..61eafa3 100644 --- a/src/Kentico.Xperience.TagManager/Admin/TagManagerModuleInstaller.cs +++ b/src/Kentico.Xperience.TagManager/Admin/TagManagerModuleInstaller.cs @@ -79,6 +79,16 @@ private static void InstallChannelCodeSnippetClass(ResourceInfo resourceInfo) }; formInfo.AddFormItem(formItem); + formItem = new FormFieldInfo + { + Name = nameof(ChannelCodeSnippetItemInfo.ChannelCodeSnippetItemEnable), + Visible = false, + DataType = FieldDataType.Boolean, + Enabled = true, + AllowEmpty = false, + }; + formInfo.AddFormItem(formItem); + formItem = new FormFieldInfo { Name = nameof(ChannelCodeSnippetItemInfo.ChannelCodeSnippetItemGuid), diff --git a/src/Kentico.Xperience.TagManager/Admin/UIPages/CodeSnippetEditPage.cs b/src/Kentico.Xperience.TagManager/Admin/UIPages/CodeSnippetEditPage.cs index 407583e..04ca32e 100644 --- a/src/Kentico.Xperience.TagManager/Admin/UIPages/CodeSnippetEditPage.cs +++ b/src/Kentico.Xperience.TagManager/Admin/UIPages/CodeSnippetEditPage.cs @@ -46,6 +46,7 @@ protected override CodeSnippetConfigurationModel Model ConsentIDs = info.ChannelCodeSnippetItemConsentId == 0 ? [] : [info.ChannelCodeSnippetItemConsentId], TagIdentifier = info.ChannelCodeSnippetItemIdentifier, Location = info.ChannelCodeSnippetItemLocation, + Enable = info.ChannelCodeSnippetItemEnable }; return model; diff --git a/src/Kentico.Xperience.TagManager/Admin/UIPages/CodeSnippetListingPage.cs b/src/Kentico.Xperience.TagManager/Admin/UIPages/CodeSnippetListingPage.cs index 201e5d2..444aa14 100644 --- a/src/Kentico.Xperience.TagManager/Admin/UIPages/CodeSnippetListingPage.cs +++ b/src/Kentico.Xperience.TagManager/Admin/UIPages/CodeSnippetListingPage.cs @@ -87,6 +87,10 @@ public override async Task ConfigurePage() value is null or 0 ? LocalizationService.GetString("No consent needed") : allConsents.FirstOrDefault(c => c.ConsentID == (int)value)?.ConsentDisplayName ?? "") + .AddColumn( + nameof(ChannelCodeSnippetItemInfo.ChannelCodeSnippetItemEnable), + "Enable", + sortable: true) .AddColumn( nameof(ChannelCodeSnippetItemInfo.ChannelCodeSnippetItemLastModified), "Last Modified", diff --git a/src/Kentico.Xperience.TagManager/Rendering/DefaultChannelCodeSnippetsService.cs b/src/Kentico.Xperience.TagManager/Rendering/DefaultChannelCodeSnippetsService.cs index 304151a..416fb51 100644 --- a/src/Kentico.Xperience.TagManager/Rendering/DefaultChannelCodeSnippetsService.cs +++ b/src/Kentico.Xperience.TagManager/Rendering/DefaultChannelCodeSnippetsService.cs @@ -66,11 +66,13 @@ async Task> GetCodeSnippetsInterna $"{ChannelCodeSnippetItemInfo.OBJECT_TYPE.Replace('.', '_')}.{nameof(ChannelCodeSnippetItemInfo.ChannelCodeSnippetItemConsentId)}", nameof(ConsentInfo.ConsentID)); }) + .WhereTrue(nameof(ChannelCodeSnippetItemInfo.ChannelCodeSnippetItemEnable)) .WhereEquals(nameof(WebsiteChannelInfo.WebsiteChannelID), channelContext.WebsiteChannelID) .WhereIn(nameof(ChannelCodeSnippetItemInfo.ChannelCodeSnippetItemType), SnippetFactoryStore.GetRegisteredSnippetFactoryTypes().ToArray()) .Columns(nameof(ChannelCodeSnippetItemInfo.ChannelCodeSnippetItemLocation), nameof(ChannelCodeSnippetItemInfo.ChannelCodeSnippetItemCode), nameof(ChannelCodeSnippetItemInfo.ChannelCodeSnippetItemConsentId), + nameof(ChannelCodeSnippetItemInfo.ChannelCodeSnippetItemEnable), nameof(ChannelCodeSnippetItemInfo.ChannelCodeSnippetAdministrationDisplayMode), nameof(ChannelCodeSnippetItemInfo.ChannelCodeSnippetItemIdentifier), nameof(ChannelCodeSnippetItemInfo.ChannelCodeSnippetItemID),