At a high-level, your logic is sound, so my recommendation would be to do the following in order to troubleshoot your issue:
Step 1: Verify xDB and Visitor Tracking
In order to troubleshoot this issue, the first thing that you should do is make sure that you have xDB enabled, configured correctly and that your visitor tracking/visitor identification code is present. This post is a good checklist for this step.
Step 2: Verify Visitor Identification Logic
Before continuing with this troubleshooting step, make sure that you have a clear understanding of what it means to identify a visitor and what the difference is between a contact and a user. If you do, skip the below sections and ask yourself "Did I actually identify my users as contacts?" If you don't, read the below and then ask yourself the same question.
A visitor is anyone (human) or anything (robot) that visits the site. It doesn't matter if the visitor is a human who has been to the site 1000 times and has registered their profile - it's still a visitor.
According to Sitecore's documentation, a contact is defined as the following:
A contact represents an individual who interacts with or may potentially interact with your organization. The contact, or contact entity, contains all the information that you collect about an individual from their interactions across channels, devices and websites.
Basically, a contact is a collection of a visitor's interaction history and any interaction data collected from said visitor. It is important to understand that while a contact "represents an individual" the visitor actually is the individual so the contact represents the visitor. A contact is analogous to a dossier and is essentially a group of everything you know about the visitor, based on the the way that they have interacted with the site.
Sitecore tracks all contacts and merges them if/when a contact is identified as an existing contact. All visitors start out as "unidentified contacts" and remain that way until they provide enough information to be identified as an existing contact.
A user, in this case (i.e. this is a concept - not in reference to Sitecore Users specifically), is a visitor to the site who has or has not registered an account and is or is not logged into the site.
An authenticated user has registered an account on the site and is currently logged in.
An unauthenticated user may or may not have registered an account on the site but they are currently not logged in.
A user profile, in this case (i.e. this is a concept - not in reference to Sitecore User Profiles, specifically), is to an authenticated user similar to what a contact is to a visitor. A contact is the collection of data that we have recorded about a visitor, while a user profile is a collection of data that we have recorded about an authenticated user, e.g. username, name, birthday, email address, etc.
Visitor vs Contact vs User vs User Profile
Visitors and our conceptual users are both entities that come to or interact with the website. An individual browsing a site is both a visitor - identified or unidentified - and a user - authenticated or unauthenticated. The key difference is that visitors are completely authentication-agnostic.
Contacts and our conceptual user profiles are both records or data about an entity. Contacts contain all interaction data collected from a visitor while a user profile has all data that the user has saved or the site's logic has recorded for a user behind the scenes. There are two key differences between contacts and user profiles:
- Contacts leverage visitors whereas user profiles leverage authenticated users as the sources of their information. Sometimes these sources overlap, e.g. when an user registers and provides their full name and email this information is saved in their user profile but the interaction can also be coded to be stored in their contact
- Contacts record data for visitors whether they are identified or unidentified, regardless of whether or not the visitor is also an authenticated or unauthenticated user
Understanding Contact Identification
When we talk about identifying contacts with Sitecore, what we mean is that we need to specify - with code - what information can be used to uniquely identify a contact. This could be any
string, e.g. phone number, email, username, etc.
Why Should I Identify Contacts?
Imagine that on your site you don't identify contacts. When Person A browses to the site, he/she becomes an unidentified visitor. This visitor interacts with the site, the interactions are tracked, the collected data is stored as a contact, and the experience is personalized. Then the visitor leaves. Assume now that Person A browses back to the site a week later. Since the site doesn't identify contacts, the site now knows nothing about the visitor and all of the information collected during the previous visit is effectively gone (it's still available in analytics, but it doesn't do anything to help us tailor or analyze the experience/interactions of the visitor on this repeat visit.
Contact Tracking and Identification by Analogy
If you are new to contact identification or aren't entirely certain that you understand what it is, how it works or why, then the analogy below should be sufficient to get you going. Otherwise, move onto the section "How to Identify Contacts in Sitecore".
The process of identifying and tracking contacts is analogous to making an appointment at the doctor's office and giving them all of your information but giving them your name, phone number and birthday last. In this analogy, you are the visitor and even though the staff has not yet been given your identifying information - in this case, your name, phone number and birthday - they still record all of your information so they have it while you're there. This "record" would be the "contact". If you were to leave the doctor's office before giving them your name, phone number and birthday then they will not have had any way to identify you. Assuming you did not give them your identifying information and you return a week later, even if you give your identifying information to the staff first they will not be able to look up the information you gave on your last visit because you did not identify at that time. However, as soon as you give them your identifying information your record will be an "identified contact" and any subsequent visitors who give the exact same identifying information will be recognized and identified as you.
In this analogy, you can think of the act of identifying contacts as analogous to specifying which pieces of information should be considered "identifying information" (in the analogy, this would have been the patient's name, phone number and birthday).
How to Identify Contacts in Sitecore
The first thing to know about contact identification is that Sitecore identifies every contact as unique (i.e. as a new contact) by default. Identifying a contact as a visitor who has previously interacted with the site and has an existing contact record - even in the case of a user who logs in using Sitecore membership - must be wired up by the developer as an additional, though fairly low-effort - step.
The second thing to know about contact identification is that, as stated above, any
string can be used to identify a contact, so it is important to pick a value that you know will be unique to each visitor and available on return visits (either via form submission, authentication, etc.). We will refer to this value as the
To identify a contact, you would make this method call in your code:
Most frequently, I find myself recommending that email addresses be used as identifiers, as email addresses can be provided to the site regardless of authentication state, e.g. contact form submissions, newsletter sign-ups, etc. In contrast, if "username" were to be used then only authenticated users would have their own contacts and unauthenticated users could either be identified as a single contact - thus skewing the data - or not at all. I prefer to identify as many unauthenticated users as possible to get create the best possible experience for as many visitors as I can, which is why I try to use a value that both authenticated and unauthenticated users would have.
For additional resources related to how to identify contacts, see this blog post, and the official Sitecore documentation.
Understanding How Sitecore Merges Identified Contacts
When a contact is identified, Sitecore looks to see if the
identifier has been used for a contact that has already been stored. In other words, Sitecore says to itself something like "Haven't I met this visitor before? Let me try to remember..." If Sitecore finds a stored contact with the same
identifier then Sitecore merges any newly tracked contact data with the old data (preference given to the new data), and updates the existing contact when the session ends.
Step 3: Reach Out to Sitecore Support
If none of the above apply to you, my recommendation is that you reach out to Sitecore support. They should be able to help you further diagnose why your contact identification isn't working as expected.