Tuesday, March 28, 2017

Incorporating xDB analytics information into SXA

Sitecore Hackathon 2017

One of the possible categories for the 2017 Sitecore Hackathon was the Sitecore Experience Accelerator (SXA). With our "No Weekend 4 Us" team we took to this challenge and created a custom component that works with SXA and the xDB (and did other fancy stuff, but that is explained in other blog posts).

Different aspects of xDB

xDB obviously is huge. And it is often that huge potential that tends to scare off those who attempt to venture into the first steps that lead into harnessing xDB's true potential.

For our entry into the SxA part of the Hackathon, we decided to go for some quick integrations that would help us showcase some of the currently missing interactions that are possible.

We used the following 3 aspects:
  • Content provided based on previous visits
  • Creation and managing Favorite content
  • Sorting content based of the accumulated pattern cards.

Content based on your visists 

First step is to load all information of your current session/interactions. This is simple to achieve, by getting the tracker (if active, otherwise change those settings or this will be very hard :p) and retrieving the assorted current Interaction Pages.

What information can be easily retrieved or added programmatically is listed here: https://doc.sitecore.net/sitecore_experience_platform/developing/marketing_operations/analytics_tracking

After that it is time to retrieve the interaction history based off the same ContactId and merging these two together. We chose to provide a max number of days to go back into the history as well as a max number of visits we wanted to load from the contactRepository.

            var tracker = Tracker.Current;
            if (tracker == null || !tracker.IsActive)
                return Enumerable.Empty<Guid>();

            var currentPages = tracker.Interaction.Pages.GroupBy(p => p.Item.Id).Select(g => g.Key);

            var maxDate = DateTime.Now;
            var minDate = maxDate.AddDays(-MaxDays);

            var contactRepository = Factory.CreateObject("tracking/contactRepository", true) as ContactRepository;
            if (contactRepository == null)
                return Enumerable.Empty<Guid>();
            var interactions = contactRepository.LoadHistoricalInteractions(tracker.Contact.ContactId, MaxVisits, minDate, maxDate).ToArray();
            var previousPages = interactions.SelectMany(i => i.Pages).GroupBy(p => p.Item.Id).Select(g => g.Key);

            return currentPages.Concat(previousPages).Distinct();

Simply mix and stir to get a good Interaction cocktail of recent and previous logged interactions. 
So, very quick and clean code to get this information loaded and prepped for HTML or rendering manipulation through visualization or the actual order of your elements.

Favorite content

Time to allow for our visitors to be able to tag content as one of their favorite pieces of content.
Typically, we used to persist this on cookie level, or work our way through local storage and in some very rare cases we would persist this on a user's profile.

Come to think of it, neither of these approaches were ideal. Local storage and cookies will differ depending on the physical location the visitor is in (different device) so that is a no-go for most business requirements. And storing this directly on the profile makes the actual profile too heavy and polluted... Enter the Sitecore experience database...

So, as this interaction is indeed coupled to a visitor, but not necessarily his/her profile, it actually makes perfect sense to have this information stored on the tracked contact.

Sitecore allows for a number of solutions that may or may not suit your need.
Either through:
  • Custom Tags
  • Custom Extensions
  • Custom of ootb Facets

Custom tags allow for a contact to become tagged with a status as well as a time aspect. In doing so, you are able to find/search through all contacts that have that tag applied. You simply get your contact from the Tracker and either set or remove the desired tag as such:

contact.Tags.Set("FavoriteTag", whateverValue); 

However, we have no need for the timestamp aspect and want to store lists of data for example.

Custom Extensions are defined as a simple and easy way to stick any kind of custom data into an xDB contact without going through a lot of custom configuration. It is realized by registring a key/value pair into the SimpleValues property.

The code for this is again very simple:

            var tracker = Tracker.Current;
            if (tracker == null || !tracker.IsActive || tracker.Contact == null)
                return new List<string>();

            var currentFavoriteBlogs = tracker.Contact.Extensions.SimpleValues[FavoriteKey];
            return string.IsNullOrEmpty(currentFavoriteBlogs) ? new List<string>() : currentFavoriteBlogs.Split('|').ToList();

Allowing us to let a user define content as a favorite through the frontend. Where the actual javascript that performed the post action is actually also embedded through scripts in the media library with SxA.

Custom or ootb Facets are the all-out solution for structuring contact data with a complex object. As this functionality seems over the top for a requirement as basic as ours we decided to hold back on this.

Pattern cards

Since we wanted content to become self-aware through the interaction behavior of the visitor, we needed to track what type of visitor we had on hand.
We went forward and created a specific Profile to which we could add our specific Pattern Cards and Profile Patterns.

Once created and assigned, we were able to go forward and write the code needed to find out our contacts derived pattern card after a number of interactions.

            var myProfile = Tracker.Current.Contact.BehaviorProfiles.Profiles.FirstOrDefault(p => p.Id == new ID(blogInterestItemId));
            if (myProfile != null && !ID.IsNullOrEmpty(myProfile.PatternId))
                var patternCard = Sitecore.Context.Database.GetItem(myProfile.PatternId);
                return patternCard;

Once this information was available, we could start showing content that would be of interest to our current visitor. Same type of FAQ content, blog entries ... and so on.

However, it isn't as simple as that... Where you tag content with Profile Patterns, the visitor gets assigned a specific (or a number of) Pattern Cards by clicking over tagged content and in turn gathering value points for specific aspects of those profile cards. Over time, the visitor will be 'best-matched' to Pattern Cards.
But that doesn't solve our issue. Because now we want to show content that is tagged with the same Profile patterns that are relevant to our visitor. But since Profile cards and Pattern cards can be quite different we would need to make assumptions based on the profile keys alone... And that would be too risky.

So went ahead and used Sitecore's tagging mechanism in the _semantics field to help us out. This allowed us to tag an actual assigned Pattern Card against a piece of content.

            const string SemanticsField = "__semantics";
            if (blogItem != null && !string.IsNullOrEmpty(currentPatternCard?.Fields[SemanticsField]?.Value))
                var tag = currentPatternCard.Fields[SemanticsField].Value.Split('|').FirstOrDefault();
                return tag != null && blogItem.Fields[SemanticsField].Value.Contains(tag);

            return false;

Ideally, this could have been done by using the same approach across Pattern Cards and Profile Cards but given the amount of content that otherwise would need to be checked against the link database versus the content we had on hand when constructing our SXA overview, this was the more obvious choice.

All in all, it was interesting to see how easy and straight-forward it was to incorporate xDB analytics information into the actual site behavior. And once you get this foundation set, you are good to go explore deeper and deeper into the rabbits hole.

Tuesday, March 21, 2017

Sitecore User Group - BeLux session recap and a future sesion

Since June 2014, we have been hard put at keeping the Sitecore User Group for Belgium and Luxembourg alive, kicking and interesting (in whatever order).

Over the course of that time, we have had some very interesting speakers and sessions.

If you have never visited us, I can highly recommend each and every session.

You can find general information on the Meetup platform here:

What's next?


The next session will be focussing on;
  • SUGCON Recap: http://www.sugcon.eu/
  • Sitecore Cloud with Azure PaaS
  • Sitecore Experience Accelerator - hands-on
We are finalizing the agenda but if you need more information, please follow here for more information on the location, specific agenda details and the various speakers:


Previous sessions


With regards to previous sessions and the presentations, we tend to make these available on the platform. However, since the meetup platform no longer supports file-hosting, information is now spread across the following pages:

Older sessions: https://www.meetup.com/Sitecore-User-Group-Belgium/pages/22666793/Files_and_Presentations/

Recent sessions: https://www.meetup.com/Sitecore-User-Group-Belgium/files/

If there are any questions, if you are interested in hosting a future session or wish to present a topic yourself, do please reach out and contact us.

Friday, March 3, 2017

Sitecore and Microsoft - An Azure story

Kind reader, perhaps a small introduction might just suit this blogpost perfectly. What exactly is Azure and the cloud as a whole? I know that for most of you readers, the following information is nothing more than a lesson in history and may even very well be within your set of active knowledge. Worst case, you can skip it altogether and jump right into the next paragraph. 

So, what is Microsoft Azure?

Not so long ago, and here and there the following scenario still stands, a typical website or application was hosted on internally hosted machines per company. Big companies tend to have centralized IT departments and data centers to secure and manage their IT infrastructure through meticulously defined processes and monitoring. Smaller companies need to fend for themselves while making due with the tools and budgets available to provide the best server maintenance as possible. And typically, web servers are not exactly put at the top of the priority list.
In both cases, the IT department is tasked with the painstaking task of maintaining servers to have up to date software and hardware. This often makes IT a liability or blocking factor for continuous business development.

Enter Cloud based platforms such as Azure. The idea behind these platforms is simple enough; Move the overhead and workload of the IT departments from inside of the (often departmental) companies and outsource them to specialized data centers. When talking about cloud, 3 acronyms come into play; IaaS, PaaS and SaaS. These cloud models are explained below by highlighting the differences between what you manage and what is managed for you.

I will not go into any more detail on what Microsoft Azure has to offer. If you need more information, I advise to read their documentation on https://docs.microsoft.com/en-us/azure/ and any other resource available online.

Now that we have set the stage on Azure it is time to give some history and evolution on how Sitecore has been reaching out to Microsoft to incorporate this way of managing your IT services.

Sitecore and SaaS

 Software as a Service takes all the previous mentioned things to an even higher level. You basically subscribe to a specific product that runs on Azure and simply use it.
Sitecore has no SaaS solution or offering. But if they did, it would behave (kind of) like this: you subscribe to a Sitecore SaaS and choose your type of solution (for example a CM with two CD’s) and you would start developing, content creation and what more directly on that platform. Without doing deploys or module installations. On top of that, the SaaS solution would allow you to opt-in or out of specific functionalities and modules and would ensure that you (and any SaaS user) are always on the latest version of the platform.

But just to be clear; Sitecore has (at the moment of writing) no solution for SaaS, nor have they shown any interest in the creation of such a solution.

Sitecore and IaaS

Since Infrastructure as a Service gives you the same access as you would have on any on premise machines, there is little to no difference for the hosting of your application environment. This implies that it is generally beneficial to move into Azure hosting as it gives flexibility for machine scaling as well as a pricing that is based on the actual server usage.

Sitecore and PaaS

The story becomes entirely different once you move into Platform as a Service. In a side by side comparison, obviously PaaS would win over IaaS anytime. As it makes an abstract of all layers of your hosting environments except for your own application and data. However, that same abstraction obviously removes some flexibility that we have become accustomed to when using on premise or IaaS. Since Microsoft is in charge of the runtime, OS and middleware, any changes and settings that get changed outside of your dedicated application and data environment are reset whenever Microsoft performs an update or reboot of the system.
A number of solutions exist for Sitecore and PaaS and there is quite some history around them.

The PaaS Hybrid solution

It might be good to briefly touch on this solution before we dive into the other solutions that are available. Hybrid means that the different Sitecore roles are placed on different cloud models. Generally the CM (content management) environment is placed on IaaS whereas the CD (content delivery) environments are hosted in PaaS. The means as to how the deployments, provisioning and configurations can be handled are described by Sitecore in more detail.

The Sitecore Azure module

On December 2011 – Sitecore released a first version of their Azure module. This module was to be installed as any Sitecore module into your internal Content Management environment combined with a Sitecore Azure environment file. It offered the following Azure capabilities: Cloud Service, Storage Service, SQL Databases Service, Traffic Manager Service, and Cache Service. 

Through the interface, a number of hosting locations allowed for the creation of an Azure Content Delivery Environment:

The overall idea behind this module was sane, but it came with some overall flaws and early product problems. First off, not all existing modules were supported by the Azure PaaS model. And furthermore, even newly created modules were not guaranteed to be PaaS enabled.

You can check the entire list here: https://kb.sitecore.net/articles/880886
Another problem was that the module had some issues with SQL Azure, especially when upgrading and deploying. 
A number of issues have been listed here: https://doc.sitecore.net/cloud/81/azure/using_sitecore_azure/troubleshooting_sitecore_azure ...as this list is quite extensive, I chose not to go into detail on this.
Bottomline: Great idea but not to good in real life projects that need to run really smooth and have error-free deployments

So, even though this approach to PaaS seems like a sure win, keep in mind that to any solution there still is an amount of effort that needs to be performed. And certain implementations and modules will simply not yet be suited for the PaaS architecture. That simply is the tradeoff between self-managed and provided services.

Sitecore with pure PaaS

Sitecore has now opened up a new chapter by introducing Microsoft Azure’s PaaS solution with Web Apps. As this is a venture the stepped in to together with Microsoft, you can expect to see a whole lot of high-value seminars and webinars coming your way on this topic.

What is so different and what does this offer?
  • No longer restricted to a number of predefined configurations
  •   Full flexibility to use ARM templates to provision the environments of your choice
  • Fast and Easy deployment  through web deploy with
  • Based on Azure best practices allowing for flexibility and ease of scaling
  • Development improvements through streamlined deployments, remote debugging and advanced application insights
Ideally, as is the idea with any and all of the Azure solutions, this should over time not only reduce your overall development cost but also reduce your hosting cost. Opening more budget to analyze and develop all those features requested by the business department.
For more specific information on the Sitecore cloud solution, go here: https://doc.sitecore.net/cloud
And a fantastic document by Pieter Brinkman on the benefits listed above, with more detail on the solution and Web Apps right here: https://www.sitecore.net/en/company/blog/489/five-reasons-why-microsoft-azure-web-apps-and-sitecore-are-a-match-made-in-heaven-4415
Want to know how to go forward from here and use the ARM templates? Then head on over to the getting started section here: http://www.sitecore.net/getting-started/deployment/sitecore-on-azure


Any pitfalls?

As this is a new solution, there is still a steep learning curve. And yes, you will need to know more on Azure then we used to know before. But that it turn will give more flexibility and ability to manage that same cloud environment.

However, some things still need some clarifications I guess:
  • How will licensing keep up with this? If I don’t have a Consumption based license, will I be able to use this?
  • A number of possible solutions still exist on where configurations per environment should be stored. It is good that multiple solutions exist rather than being unable to perform that task, but it would be even better if only a single solution was preferred and put forward as best-practice.
  • The sample ARM templates still need to be expanded on to cover heavier topologies. As this approach will become more globally adopted and more knowledge gets retained, this will go away
  • A number of solutions are still not able to run in the PaaS solution:
    • ExM
    • WFFM
    • FxM
However, Sitecore is well aware of this and will be releasing updates to these modules to make sure that they match up with the new solution.
 It is good to see that Sitecore and Microsoft are working together so closely both from a development and architectural point of view. This synergy will really help to reach out into the future and serve faster, more scalable top of the line enterprise solutions.

Tuesday, January 31, 2017

Sitecore MVP's announced for 2017

Hi all,

just a small message since I am honored to call myself Sitecore Technology MVP for 2017.

My congratulations to all fellow MVP's that made it to the list in 2017!
I'm looking forward to sharing ideas, concerns and research with you all.

See you somewhere in Las Vegas, Usergroups and any of the online and offline platforms that help us share and care!