Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add enable checkbox to disable tag without deleting #32

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()`.
Expand Down
Binary file modified images/screenshots/create_custom_snippet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/screenshots/create_snippet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/screenshots/listing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/screenshots/ui_application.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ internal class CodeSnippetConfigurationModel
[ObjectIdSelectorComponent(objectType: ConsentInfo.OBJECT_TYPE, Label = "Consent", Order = 6, Placeholder = "No consent needed")]
public IEnumerable<int> 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)
Expand All @@ -51,5 +54,6 @@ public void MapToChannelCodeSnippetInfo(ChannelCodeSnippetItemInfo info)
info.ChannelCodeSnippetItemIdentifier = TagIdentifier;
info.ChannelCodeSnippetItemCode = Code;
info.ChannelCodeSnippetAdministrationDisplayMode = DisplayMode;
info.ChannelCodeSnippetItemEnable = Enable;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ public virtual int ChannelCodeSnippetItemConsentId
set => SetValue(nameof(ChannelCodeSnippetItemConsentId), value);
}

/// <summary>
/// Channel code snippet consent ID.
/// </summary>
[DatabaseField]
public virtual bool ChannelCodeSnippetItemEnable
{
get => ValidationHelper.GetBoolean(GetValue(nameof(ChannelCodeSnippetItemEnable)), true);
set => SetValue(nameof(ChannelCodeSnippetItemEnable), value);
}


/// <summary>
/// Deletes the object using appropriate provider.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ async Task<ILookup<CodeSnippetLocations, CodeSnippetDto>> 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),
Expand Down