Programmatic Personalization Problem with the Sitefinity API

May 22, 2019
Just gonna leave this here first
https://feedback.progress.com/Project/153/feedback/Details/259791-expose-a-parameterless-getusersegment-so-we-can-programatically-work-with-persona

So the personalization UI in sitefinity is pretty slick, you can see the docs and demos.  The basic idea is when you personalize something in the UI it renders blank on the page, and depending on segment match, the result is delivered through an XHR callback.

If you need to make a custom widget personalizable it's equally as simple, just inherit from IPersonalizable on the Controller and SF will handle the rest.  I don't believe there's even anything to implement.  The page editor UI will just allow you to create variants for the different segments.

Now you're all pumped up to maybe extend it further with some custom code right?! If in segment1 do X, else if in segment2 do Y?

Well, you can't... 🤷 As a developer, this kinda suck... bad.  One would even think when bidding on a contract and selling features you would ASSUME this would work.

The core issue is that Sitefinity sees personalization as something that comes from a page or a widget; it's page-centric if you will.

There's only 1 real method to query to see if a user is in a segment
public ISegment GetUserSegment(Guid pageDataId)

So lets unpack what that means.  It means you need to get a PageData object from a page which has been personalized, and the function will look at which segments are on that page, and return to you the segment to which they belong.

WHICH MEANS

You can't programatically access personalization in Sitefinity (easily).  If you have 10 segments and just need to find where someone belongs, you need to make a dummy page, apply the segments to that, just so you can run this function. Add a new segment, don't forget to edit the dummy page... painful right, it's a hack and as a developer it makes you look bad when the client was sold on this cool tech.

User segments should be available to use as developers to use like a Dynamic Role.  I should literally be able to do that IF\ELSE logic in my code to check segments and tailor content outside of the SF personalization UI.  The system is supposed to be extensible, this is a massive blocker.

There should be something like:
manager.GetUserSegment(); //Parameterless
or
manager.GetUserSegments(); // <- Returns all matches sorted by the priority

Obviously there's some segment types which make no sense because they are page specific.  But like Location, IP, Previous page visits, profile matches, etc... these things are very useful for us as developers to solve issues for clients.

Please vote
https://feedback.progress.com/Project/153/feedback/Details/259791-expose-a-parameterless-getusersegment-so-we-can-programatically-work-with-persona


Image Description

Steve McNiven-Scott

Best\Only Blogger on this site. Therefore defacto blogger of the year Award Winner.