Sitecore

Resetting Profiles by Derek Hunziker

0.reset.png

One of the coolest features of Sitecore is its ability to profile content and match visitors to predefined patterns. This sort of targeting can be extremely valuable for Marketers and Sales Representatives who wish to pinpoint customers based on their website activity.

The feature itself is quite sophisticated, but once you get over the initial terminology learning curve and understand how things are assembled in Sitecore, creating profiles and applying them to pages is relatively straightforward. So too is personalizing content based on pattern matches—it's really quite easy to understand and use.

Maintaining profiles over time, however, can be tricky—especially for large content-driven websites. One concern in particular, is the lack of referential integrity between the profiles and the pages you apply them to. Let me explain what I mean by that with an example.

In the screenshot below, I have created a new Profile Card named "Decision Maker" under the "Focus" profile. Pay close attention to the values I set for each Profile Key (8, 3, 3, and 8).

1.define.png

After applying this Profile Card to a page, the value is stored within a special "__Tracking" field on the item. This field is not directly visible within the Content Editor, but by looking under the hood, we can see that the actual value of the field is stored as XML and looks something like what you see below.

2.xml.png

Circled above, are my values "8, 3, 3, 8", as well as the name of my profile card "decision maker". Absent, are any sort of references to the Profile Card or Profile Key unique IDs—the only ID we can see is a reference to the "Focus" profile itself. This is where the problem lies.

Now, let's say a Marketer isn't quite happy with the "Decision Maker" Profile Card and decides to make a few updates to it. They rename the Profile Card to "Influencer" and change the values to "7, 4, 5, 6".

3.rename.PNG

You might expect that this change to the Profile Card itself would automatically propagate to all of the pages that you've applied this Profile Card to. Unfortunately, it does not—the values will remain "8, 3, 3, 8". As it turns out, modifying profiles after they've been applied to pages does not automatically update those pages, at least until you go to those pages, open/close the profile dialog, and republish the items. Long story short—things can get messy ;)

After witnessing several clients and colleagues struggle with this exact issue, I decided to create a Sitecore PowerShell Extensions script to help reset profiles across multiple items. This would be something you'd use if you wanted to start fresh with your content profiling or if you want to adjust profiles across entire sections of your website. At this point, it's worth noting that Sitecore already provides a process for applying profiles across multiple items, however, I have seen multiple cases of profiles being applied in unexpected places with this approach, so if you decide to use it, please consider taking a snapshot of your master database before using it.

Usage

The script is made available within the Content Editor's context menu. Simply right-click an item in the content tree and select Scripts > Reset Profiles. The item you right-clicked will be used as the starting point for the script and you will be presented with an option to include descendant items, as well as assign new profiles to all of the pages.

3.screenshot.PNG

Installation

  1. Navigate to /sitecore/system/Modules/PowerShell/Script Library
  2. Elevate your session by clicking on the link in the content editor warnings bar
  3. Right-click the Script Library and insert a new Module
  4. Name it whatever you please, ensure that "Enable module" is checked, and select the "Content Editor Context Menu" integration point (top of the list).
  5. Navigate to ../Script Library/[Your Module]/Content Editor/Context Menu
  6. Right-click and insert a new PowerShell Script item, naming it "Reset Profiles"
  7. Copy the script into the "Script body" field and save the item. The script is now available in the context menu for every item in the tree.
  8. If you wish to limit access to this script (a very, very good idea!), you can define rules under the "Show if rules are met or not defined" field. An example might be "where the current user is an administrator".

Script

https://gist.github.com/dthunziker/8e36eb458ebe0a4700b125148f47172e

PLEASE NOTE: This script was tested on Sitecore 8.2 Update-2 with Sitecore Powershell Extensions v4.3.0.17491. Use at your own risk and please do so in your QA environments first :)