Skip to content

Commit

Permalink
GH-69 :: add personalization
Browse files Browse the repository at this point in the history
  • Loading branch information
kentico-matthews committed Aug 27, 2024
1 parent 5970dd0 commit 9689687
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .../widgetsamples-qyagaxb2@ef49a8813e/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
<ContentItemCommonDataFirstPublishedWhen>2024-02-05 17:57:39Z</ContentItemCommonDataFirstPublishedWhen>
<ContentItemCommonDataGUID>2bc61792-947f-4750-92a3-11a3f0b2e1a1</ContentItemCommonDataGUID>
<ContentItemCommonDataIsLatest>True</ContentItemCommonDataIsLatest>
<ContentItemCommonDataLastPublishedWhen>2024-04-24 20:06:08Z</ContentItemCommonDataLastPublishedWhen>
<ContentItemCommonDataLastPublishedWhen>2024-08-27 17:46:31Z</ContentItemCommonDataLastPublishedWhen>
<ContentItemCommonDataPageBuilderWidgets>
<![CDATA[{"editableAreas":[{"identifier":"areaMain","sections":[{"identifier":"f5f94e54-9824-47b7-9a9b-439eee2c11d1","type":"TrainingGuides.SingleColumnSection","properties":{"sectionAnchor":null},"zones":[{"identifier":"731b8330-a83b-48fb-a682-35c081d45e6a","widgets":[{"identifier":"71006cf2-4a65-4746-bdd3-cd8024c678df","type":"Kentico.Widget.RichText","variants":[{"identifier":"0f376c40-6b7f-4f3d-9571-e7d461a2b463","properties":{"content":"<p>This page contains example usage of widgets that are similar to widgets seen in the Xperience by Kentico demo page.</p>"},"fieldIdentifiers":{"content":"5cf16e61-354d-4a34-b421-3ccbc64e0858"}}]},{"identifier":"9fd80f32-d748-4656-b250-3e00413360d2","type":"TrainingGuides.CallToActionWidget","variants":[{"identifier":"dfa4af7f-b1ba-427a-9937-154023dbd02f","properties":{"text":"Read more","type":"page","targetPage":"~/news","contentItem":null,"absoluteUrl":null,"isDownload":false,"identifier":null,"openInNewTab":false},"fieldIdentifiers":{"text":"ad515169-15ab-4631-9c99-0fdda8a4cabb","type":"0f756769-f45b-4659-858b-3170185d7f29","targetPage":"1e3d102d-2511-463b-9b3e-f3d70d0e1934","contentItem":"edee65a8-3690-4859-83d3-afcb873b7f59","absoluteUrl":"a501c256-0837-49d2-bc3d-a5638a3d529d","isDownload":"f6038b2b-ac96-4c22-b472-9609c80d16b8","identifier":"5b91e214-6bdb-4d61-ad52-f24a6928c8b4","openInNewTab":"141df6e9-e5a9-4910-a6e3-c15d94134cc9"}}]},{"identifier":"c096b68e-fe41-473b-9369-ed511db248ab","type":"TrainingGuides.HtmlCodeWidget","variants":[{"identifier":"1eef413a-487f-47da-be37-05f9ed94f9ac","properties":{"code":"<h4>This text was added as Html through the <em>Html code</em> widget</h4>","insertToHead":false},"fieldIdentifiers":{"code":"3fbd3f6a-cf6e-424d-bfe5-21c1234cfee9","insertToHead":"bcb66b93-d3bc-464e-b96d-f9bee9b75287"}}]},{"identifier":"28c2a900-f150-4035-86ae-dfab5e99a2d6","type":"TrainingGuides.HeroBanner","variants":[{"identifier":"f1536a8b-18f1-4ec2-a533-e90601ec0c56","properties":{"mode":"heroContentItem","productPageAnchor":null,"productPage":null,"selectedProductPageAnchor":null,"hero":[{"identifier":"f56a7c73-21d5-4604-8729-11cf5c74563f"}],"cta":null,"displayCTA":true,"openInNewTab":false,"changeDesign":true,"showBenefits":true,"showImage":true,"width":"circle","textColor":"Dark"},"fieldIdentifiers":{"mode":"419e04ac-fe70-4994-aea4-ecdaa3ffd194","productPageAnchor":"e8bcaf96-42f3-4f3e-bbf1-b2b74d25ded1","productPage":"4f7ab742-14de-42d3-b696-1e9197af4586","selectedProductPageAnchor":"b458e7a8-0cff-4350-8265-617f1ba27e77","hero":"2c515840-51cc-463d-9ecc-fd9fa557f731","cta":"3ddd63df-073a-4998-8006-df3355afa24b","displayCTA":"f1a2a3d7-4b00-4ee1-97e5-f072c6bd4d5c","openInNewTab":"46363e60-6e12-479a-9a59-64db42f58c48","changeDesign":"66c8c6b2-358a-445f-81dc-555200c8469e","showBenefits":"0facb279-680d-4f63-a88b-317f3f9f1aad","showImage":"de169e42-651d-49b4-ba3b-bdffef91d9f5","width":"4cd4fd88-a7ed-4d6f-a2b8-e2f70bd56f7f","textColor":"ebdf6005-46d7-4f98-b7db-353003230a1a"}}]}]}],"fieldIdentifiers":{"sectionAnchor":"3624ad74-5f9f-43dc-a9e6-e004e7dab319"}},{"identifier":"b63bd01f-a73c-48c6-b65e-2ae8a679ad85","type":"TrainingGuides.SingleColumnSection","properties":{"sectionAnchor":null},"zones":[{"identifier":"72dfa06b-f233-440a-8997-b90a5c32d556","widgets":[{"identifier":"a9d35e89-ae5c-4dde-9910-95ab467b0516","type":"TrainingGuides.ProductComparatorWidget","variants":[{"identifier":"c7019377-095f-4b1a-b310-33b03320a86a","properties":{"products":[{"webPageGuid":"29d47791-2031-47ca-ae0f-f6ce0e2dbd81"},{"webPageGuid":"fd3fd667-4404-4c08-9cc0-da3a42fd813c"}],"comparatorHeading":"Compare these products","headingType":"H3","headingMargin":"Large","callToAction":"See more","showShortDescription":true,"showPrice":true},"fieldIdentifiers":{"products":"f7bd156f-5926-4e59-b2a0-035b7eabfe6c","comparatorHeading":"a84a930a-7954-4f84-955c-277ea0aff43e","headingType":"3ced4bb7-5535-49a2-b085-d18a6b6b6bac","headingMargin":"3a8ad32e-b4f1-4bd1-ab4a-1cc1f71aaa5b","callToAction":"5afa859f-a916-4f98-87ab-3c5a0bdc62a4","showShortDescription":"52536c17-17e3-40c9-aff0-0e73335f9f76","showPrice":"e23b787d-aecf-4e0e-86c2-53a21c23c295"}}]},{"identifier":"3860c052-823a-4273-995e-58cb24485124","type":"TrainingGuides.ArticleListWidget","variants":[{"identifier":"3b66a384-ceae-4b64-9a6a-fa4bff300824","properties":{"contentTreeSection":[{"webPageGuid":"77c7aa1f-e0e3-4b74-a66f-8c0c87523c15"}],"topN":10,"ctaText":"Read more","orderBy":"NewestFirst"},"fieldIdentifiers":{"contentTreeSection":"d8d852f2-1c7a-4a6d-bb7d-61c507347d9b","topN":"c71177a6-8b72-44b3-9fac-ee72d7246c4d","ctaText":"13a01e21-11ed-4079-a394-dac03460f54e","orderBy":"8c026cca-c4e4-4cfc-acdf-35c0c05ecc9c"}}]},{"identifier":"6d88af4e-510e-4322-91bf-8b2eafc1e7e7","type":"TrainingGuides.FeaturedNewsWidget","variants":[{"identifier":"4105d9a9-4210-4fe6-8d24-021e50e9cf20","properties":{"article":[{"webPageGuid":"e637f5c7-7b4d-4359-a638-0956eedff300"}]},"fieldIdentifiers":{"article":"73ff6341-f3b5-4098-86e0-e88e1a5ec1f7"}}]},{"identifier":"dca67df2-b30d-473d-87d3-b2f0c8750d7d","type":"TrainingGuides.VideoEmbedWidget","variants":[{"identifier":"1a49df0b-230c-45a6-906b-a5ddc4ebba73","properties":{"service":"youtube","url":"https://youtu.be/Uyr0J6Ws4R8","dynamicSize":true,"width":560,"height":315,"playFromBeginning":true,"startingTime":0},"fieldIdentifiers":{"service":"a7f3de3b-91a6-4524-9803-4d8a6032387d","url":"0e30abd4-5031-44fe-a5ca-a343924c9f13","dynamicSize":"d2f7f695-a972-449b-a048-7ff72a9f641f","width":"b27d0cf3-9e34-4b5b-8386-a802e1f5f647","height":"54c167f1-2336-4881-b200-bd7df2f99bfe","playFromBeginning":"2bee441e-45a8-42d2-ab2d-897d2a3cfdef","startingTime":"83fd259e-6d29-4750-b4c2-b7e066bf8af8"}}]}]}],"fieldIdentifiers":{"sectionAnchor":"61d9d55a-1fe3-4e93-959c-107552e8f1d6"}}]}]}]]>
<![CDATA[{"editableAreas":[{"identifier":"areaMain","sections":[{"identifier":"f5f94e54-9824-47b7-9a9b-439eee2c11d1","type":"TrainingGuides.SingleColumnSection","properties":{"sectionAnchor":null},"zones":[{"identifier":"731b8330-a83b-48fb-a682-35c081d45e6a","widgets":[{"identifier":"71006cf2-4a65-4746-bdd3-cd8024c678df","type":"Kentico.Widget.RichText","variants":[{"identifier":"0f376c40-6b7f-4f3d-9571-e7d461a2b463","properties":{"content":"<p>This page contains example usage of widgets that are similar to widgets seen in the Xperience by Kentico demo page.</p>"},"fieldIdentifiers":{"content":"5cf16e61-354d-4a34-b421-3ccbc64e0858"}}]},{"identifier":"9fd80f32-d748-4656-b250-3e00413360d2","type":"TrainingGuides.CallToActionWidget","variants":[{"identifier":"dfa4af7f-b1ba-427a-9937-154023dbd02f","properties":{"text":"Read more","type":"page","targetPage":"~/news","contentItem":[],"absoluteUrl":"","isDownload":false,"identifier":null,"openInNewTab":false},"fieldIdentifiers":{"text":"ad515169-15ab-4631-9c99-0fdda8a4cabb","type":"0f756769-f45b-4659-858b-3170185d7f29","targetPage":"1e3d102d-2511-463b-9b3e-f3d70d0e1934","contentItem":"edee65a8-3690-4859-83d3-afcb873b7f59","absoluteUrl":"a501c256-0837-49d2-bc3d-a5638a3d529d","isDownload":"f6038b2b-ac96-4c22-b472-9609c80d16b8","identifier":"5b91e214-6bdb-4d61-ad52-f24a6928c8b4","openInNewTab":"141df6e9-e5a9-4910-a6e3-c15d94134cc9"}}]},{"identifier":"c096b68e-fe41-473b-9369-ed511db248ab","type":"TrainingGuides.HtmlCodeWidget","variants":[{"identifier":"1eef413a-487f-47da-be37-05f9ed94f9ac","properties":{"code":"<h4>This text was added as Html through the <em>Html code</em> widget</h4>","insertToHead":false},"fieldIdentifiers":{"code":"3fbd3f6a-cf6e-424d-bfe5-21c1234cfee9","insertToHead":"bcb66b93-d3bc-464e-b96d-f9bee9b75287"}}]},{"identifier":"28c2a900-f150-4035-86ae-dfab5e99a2d6","type":"TrainingGuides.HeroBanner","variants":[{"identifier":"f1536a8b-18f1-4ec2-a533-e90601ec0c56","properties":{"mode":"heroContentItem","productPageAnchor":"","productPage":[],"hero":[{"identifier":"f56a7c73-21d5-4604-8729-11cf5c74563f"}],"selectedProductPageAnchor":"","cta":null,"displayCTA":true,"openInNewTab":false,"changeDesign":true,"textColor":"Dark","showBenefits":true,"showImage":true,"width":"circle"},"fieldIdentifiers":{"mode":"419e04ac-fe70-4994-aea4-ecdaa3ffd194","productPageAnchor":"e8bcaf96-42f3-4f3e-bbf1-b2b74d25ded1","productPage":"4f7ab742-14de-42d3-b696-1e9197af4586","selectedProductPageAnchor":"b458e7a8-0cff-4350-8265-617f1ba27e77","hero":"2c515840-51cc-463d-9ecc-fd9fa557f731","cta":"3ddd63df-073a-4998-8006-df3355afa24b","displayCTA":"f1a2a3d7-4b00-4ee1-97e5-f072c6bd4d5c","openInNewTab":"46363e60-6e12-479a-9a59-64db42f58c48","changeDesign":"66c8c6b2-358a-445f-81dc-555200c8469e","showBenefits":"0facb279-680d-4f63-a88b-317f3f9f1aad","showImage":"de169e42-651d-49b4-ba3b-bdffef91d9f5","width":"4cd4fd88-a7ed-4d6f-a2b8-e2f70bd56f7f","textColor":"ebdf6005-46d7-4f98-b7db-353003230a1a"}}]}]}],"fieldIdentifiers":{"sectionAnchor":"3624ad74-5f9f-43dc-a9e6-e004e7dab319"}},{"identifier":"b63bd01f-a73c-48c6-b65e-2ae8a679ad85","type":"TrainingGuides.SingleColumnSection","properties":{"sectionAnchor":null},"zones":[{"identifier":"72dfa06b-f233-440a-8997-b90a5c32d556","widgets":[{"identifier":"a9d35e89-ae5c-4dde-9910-95ab467b0516","type":"TrainingGuides.ProductComparatorWidget","variants":[{"identifier":"c7019377-095f-4b1a-b310-33b03320a86a","properties":{"products":[{"webPageGuid":"29d47791-2031-47ca-ae0f-f6ce0e2dbd81"},{"webPageGuid":"fd3fd667-4404-4c08-9cc0-da3a42fd813c"}],"comparatorHeading":"Compare these products","headingType":"H3","headingMargin":"Large","callToAction":"See more","showShortDescription":true,"showPrice":true},"fieldIdentifiers":{"products":"f7bd156f-5926-4e59-b2a0-035b7eabfe6c","comparatorHeading":"a84a930a-7954-4f84-955c-277ea0aff43e","headingType":"3ced4bb7-5535-49a2-b085-d18a6b6b6bac","headingMargin":"3a8ad32e-b4f1-4bd1-ab4a-1cc1f71aaa5b","callToAction":"5afa859f-a916-4f98-87ab-3c5a0bdc62a4","showShortDescription":"52536c17-17e3-40c9-aff0-0e73335f9f76","showPrice":"e23b787d-aecf-4e0e-86c2-53a21c23c295"}}]},{"identifier":"3860c052-823a-4273-995e-58cb24485124","type":"TrainingGuides.ArticleListWidget","variants":[{"identifier":"3b66a384-ceae-4b64-9a6a-fa4bff300824","properties":{"contentTreeSection":[{"webPageGuid":"77c7aa1f-e0e3-4b74-a66f-8c0c87523c15"}],"topN":10,"ctaText":"Read more","orderBy":"NewestFirst"},"fieldIdentifiers":{"contentTreeSection":"d8d852f2-1c7a-4a6d-bb7d-61c507347d9b","topN":"c71177a6-8b72-44b3-9fac-ee72d7246c4d","ctaText":"13a01e21-11ed-4079-a394-dac03460f54e","orderBy":"8c026cca-c4e4-4cfc-acdf-35c0c05ecc9c"}}]},{"identifier":"6d88af4e-510e-4322-91bf-8b2eafc1e7e7","type":"TrainingGuides.FeaturedNewsWidget","conditionType":"TrainingGuides.Web.Features.Personalization","variants":[{"identifier":"4105d9a9-4210-4fe6-8d24-021e50e9cf20","properties":{"article":[{"webPageGuid":"e637f5c7-7b4d-4359-a638-0956eedff300"}]},"fieldIdentifiers":{"article":"73ff6341-f3b5-4098-86e0-e88e1a5ec1f7"}},{"identifier":"01400b28-9324-4bec-afc9-c626b4b5aad5","name":"Espresso lovers","properties":{"article":[{"webPageGuid":"c48419d1-41d5-4fb5-91a3-32968bd8aeb3"}]},"conditionTypeParameters":{"selectedContactGroups":[{"objectGuid":null,"objectCodeName":"EspressoLovers"}],"variantName":null},"fieldIdentifiers":{"article":"d6cac4e5-c0a2-4661-9b38-1661b37b238d"}}]},{"identifier":"dca67df2-b30d-473d-87d3-b2f0c8750d7d","type":"TrainingGuides.VideoEmbedWidget","variants":[{"identifier":"1a49df0b-230c-45a6-906b-a5ddc4ebba73","properties":{"service":"youtube","url":"https://youtu.be/Uyr0J6Ws4R8","dynamicSize":true,"width":560,"height":315,"playFromBeginning":true,"startingTime":0},"fieldIdentifiers":{"service":"a7f3de3b-91a6-4524-9803-4d8a6032387d","url":"0e30abd4-5031-44fe-a5ca-a343924c9f13","dynamicSize":"d2f7f695-a972-449b-a048-7ff72a9f641f","width":"b27d0cf3-9e34-4b5b-8386-a802e1f5f647","height":"54c167f1-2336-4881-b200-bd7df2f99bfe","playFromBeginning":"2bee441e-45a8-42d2-ab2d-897d2a3cfdef","startingTime":"83fd259e-6d29-4750-b4c2-b7e066bf8af8"}}]}]}],"fieldIdentifiers":{"sectionAnchor":"61d9d55a-1fe3-4e93-959c-107552e8f1d6"}}]}]}]]>
</ContentItemCommonDataPageBuilderWidgets>
<ContentItemCommonDataPageTemplateConfiguration>
<![CDATA[{"identifier":"TrainingGuides.EmptyPagePageTemplate","properties":null,"fieldIdentifiers":{}}]]>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System.Collections.Generic;

using CMS.ContactManagement;
using CMS.DataEngine;

using TrainingGuides.Web.Features.Personalization;

using Kentico.PageBuilder.Web.Mvc.Personalization;
using Kentico.Xperience.Admin.Base.FormAnnotations;
using Kentico.Xperience.Admin.Base.Forms;

[assembly: RegisterPersonalizationConditionType(
"TrainingGuides.Web.Features.Personalization",
typeof(IsInContactGroupConditionType),
"Is in contact group",
Description = "Evaluates if the current contact is in one of the contact groups.", IconClass = "icon-app-contact-groups", Hint = "Display to visitors who match at least one of the selected contact groups:")]

namespace TrainingGuides.Web.Features.Personalization;

/// <summary>
/// Personalization condition type based on contact group.
/// </summary>
public class IsInContactGroupConditionType : ConditionType
{
/// <summary>
/// Selected contact group code names.
/// </summary>
[ObjectSelectorComponent(PredefinedObjectType.CONTACTGROUP,
Label = "Contact groups",
Order = 0,
MaximumItems = 0)]
public IEnumerable<ObjectRelatedItem> SelectedContactGroups { get; set; } = Enumerable.Empty<ObjectRelatedItem>();


/// <summary>
/// Evaluate condition type.
/// </summary>
/// <returns>Returns <c>true</c> if implemented condition is met.</returns>
public override bool Evaluate()
{
var contact = ContactManagementContext.GetCurrentContact();

if (contact == null)
{
return false;
}

if (SelectedContactGroups == null || !SelectedContactGroups.Any())
{
return contact.ContactGroups.Count == 0;
}

return contact.IsInAnyContactGroup(SelectedContactGroups.Select(c => c.ObjectCodeName).ToArray());
}
}

0 comments on commit 9689687

Please sign in to comment.