Hiding components from users when they are not logged in. AKA Personalisation and you!

Hiding components from users when they are not logged in. AKA Personalisation and you!
When you first install Sitecore 7.2 this is the page that greets you:
Sitecore 7.2 Home Screen

However for this example, let’s make it so that users that aren’t logged in can’t see the title and body, until they are logged in they shouldn’t be welcomed to our system.
While this is a silly example, the same mechanism can be used to achieve many other requirements, such as show specific content based on the users location, goals that have been set, or perhaps hiding welcome content after they have already used the website.
To make this even better, the rules engine is easily customised such that you can create custom rules based on applicable business requirements such as if the user has a certain attribute in their profile.

  1. Firstly, we need to make sure that analytics are enabled, personalisation is driven through the analytics engine and requires it to be turned on
  2. Log into Sitecore, go to the content editor and select the Home item.
  3. In the menu select Presentation and Detailssc72-presentation-details
  4. Under Sample Layout select editsc72-layout-edit
  5. In the Device Editor select Controls, then Sample Rendering and click Personalize.sc72-device-editor-personalise
  6. In the Personalize the Component window click New Condition
  7. Name the condition “Hide for Anonymous”
  8. Under the “Hide for Anonymous” condition click Editsc72-personalize-the-component-hide-edit
  9. In the rule editor, find the Security rules and click on “where the current user is anonymous” and click ok.
  10. Back on the Personalize the Component window to the right of where we clicked edit, check the “Hide Component” tick box.sc72-personalize-the-component-hide-with-rule
  11. Publish the home item.

If you open an incognito window or clear your cookies and go to the home screen you will get this cold unwelcoming page:
sc72-no-welcome

NOTE: To quote the great Stan Lee “With great power there must also come- great responsibility”, whilst the rules engine allows you to tailor content you must be careful to not over personalise and create content that is never seen because you have too many rules chained together or have catch all rules.

Now go forth, create custom rules and amazing websites.

Sitecore 7.2 Personalisation Buttons Not Showing

Sitecore has the fantastic ability to personalise content for users, however this is not enabled by default.
I recently had to jump into a Sitecore 7.2 solution and for the life of me couldn’t figure out why personalisation options weren’t showing.

sc72 Component No Personalise Button Showing

I finally remembered that for 7.2 personalistion requires analytics (DMS).
If you get to the point where you’re looking at the screenshot above and wondering where Personalise is, just follow these steps:

  1. Download the corresponding DMS version for your version of Sitecore from the SDN.
  2. Extract the DMS download (in my case DMS 7.2 rev.150408)
  3. In SQL Server Management Studio attach the Sitecore.Analytics database.
  4. Copy the 3 .config files into YOURSITECOREWEBSITE\App_Config\Include
  5. Update the connectionstring.config for the analytics database.
  6. <add name="analytics" connectionString="Data Source=localhost;Initial Catalog=Sitecore_analytics;Integrated Security=False;User ID=USERNAME;Password=PASSWORD" />
    

Now if you go to edit a component you will get:
sc72 Component Personalise Button

If you are dealing with a client where they don’t want an Analytics Database to be installed or configured, you can simply add the 3 config files and in Sitecore.Analytics.config change:

<!--  ANALYTICS DISABLE DATABASE
      Disables the database so that no reading or writing to the database occurs.
      Default: false
-->
<setting name="Analytics.DisableDatabase" value="false" />

to:

<!--  ANALYTICS DISABLE DATABASE
      Disables the database so that no reading or writing to the database occurs.
      Default: false
-->
<setting name="Analytics.DisableDatabase" value="true" />

Doing this also means you do not need to add the connection string for the analytics database, but this will mean you will lose the ability to personalise on any historical events such as previous visits or goals and is therefore not recommended.