Tracking contacts
How both known and anonymous contacts are identified and tracked in session.
Tracking anonymous contacts
Sitecore relies on cookies to track anonymous contacts - specifically the SC_ANALYTICS_GLOBAL_COOKIE
cookie. The following scenarios explain how Sitecore recognizes a returning anonymous contact.
First visit - Laptop
In the following scenario, a contact visits a website for the first time on their laptop:
-
Contact visits www.sitecore.net - a device GUID is generated and assigned as follows:
-
Sitecore.Analytics.Tracker.Current.Contact.ContactId
set to 60573a38-6925-4d92-8bff-327e41650d8f -
SC_ANALYTICS_GLOBAL_COOKIE set to 60573a38-6925-4d92-8bff-327e41650d8f
-
-
The contact browses a few pages.
-
The contact closes their browser and the session ends - the contact is saved to xConnect:
-
A new
Sitecore.XConnect.Contact
is created -
An anonymous
Sitecore.XConnect.ContactIdentifier
is added:-
Identifier: 60573a3869254d928bff327e41650d8f
-
Source:
Sitecore.Analytics.XConnect.DataAccess.Constants.IdentifierSource
(Use “xDB.Tracker” in 9.0.0 - property is marked internal)
-
-
A contact ID is generated by xConnect - this ID is different from the tracking ID
-
An interaction with a few page view events is saved
-
A device profile with an ID of 60573a38-6925-4d92-8bff-327e41650d8f is saved to xConnect - the
LastKnownContactId
of the device profile points to the corresponding contact ID, which happens to be identical to the ID the device profile itself.
-
Second visit - Laptop
In the following scenario, the same contact returns to a website on their laptop:
-
Contact visits www.sitecore.net - they have the
SC_ANALYTICS_GLOBAL_COOKIE
set to 60573a38-6925-4d92-8bff-327e41650d8f -
Request is sent to xConnect for the device profile matching 60573a38-6925-4d92-8bff-327e41650d8f
-
The
LastKnownContactId
of the device profile is used to retrieve a contact from xConnect by its tracker identifier -
If the contact exists, it is loaded into session - if not, a new GUID is generated (the new contact will be saved on session end)
-
At the end of the session, a second interaction is saved against the contact
In this scenario, the tracker has enough information to identify the contact as an existing anonymous contact. A new interaction is saved on session end.
Third visit - Laptop, cleared cookies
In the following scenario, the same contact returns to a website on their laptop after clearing their cookies:
-
Contact clears cookies
-
Contact visits
www.sitecore.net
- because cookies have been cleared,SC_ANALYTICS_GLOBAL_COOKIE
no longer exists and a new device GUID is generated:-
Sitecore.Analytics.Tracker.Current.Contact.ContactId
set to 29751ac1-d99c-4efe-8547-cb42d90de6a0 -
SC_ANALYTICS_GLOBAL_COOKIE set to 29751ac1-d99c-4efe-8547-cb42d90de6a0
-
-
On session end, a new contact, interaction, and device are saved to xConnect that has no relationship with the previous contact.
Tracking known contacts
In order for a contact to be tracked across devices, they must identify themselves on each device. Once a contact has identified themselves on a device, the tracker uses various methods to recognize the contact even when the session expires.
The following scenarios explain how the tracker recognizes a known contact.
First visit - Laptop
In the following scenario, a contact visits a website for the first time on their laptop and logs in. The username submitted on login is used to create an identifier in the xDB:
-
Contact visits www.sitecore.net for the first time - a device GUID is generated and assigned as follows:
-
Sitecore.Analyltics.Tracker.Current.Contact.ContactId
set to 60573a38-6925-4d92-8bff-327e41650d8f -
SC_ANALYTICS_GLOBAL_COOKIE set to 60573a38-6925-4d92-8bff-327e41650d8f
-
-
The contact registers with the username myrtlesitecore and logs in
-
When the contact logs in, you can use their username to identify them upon successful login:
RequestResponseSitecore.Analytics.Tracker.Current.Session.IdentifyAs("sitecoreextranet", "myrtlesitecore");
NoteIdentification and authentication are separate, unrelated events. Contacts are identified against the xDB, and authenticated against whatever mechanism the website is using.
-
When the contact identifies, they are saved to xConnect with the following identifiers:
-
A known identifier based on the information passed into
IdentifyAs()
:-
Identifier: myrtlesitecore
-
Source: sitecoreextranet
-
IdentifierType:
ContactIdentifierType.Known
-
-
A tracker identifier is added:
-
Identifier: 60573a3869254d928bff327e41650d8f
-
Source:
Sitecore.Analytics.XConnect.DataAccess.Constants.IdentifierSource
(Use “xDB.Tracker” in 9.0.0 - property is marked internal) -
IdentifierType:
ContactIdentifierType.Anonymous
-
-
An alias identifier is added:
-
Identifier: Randomly generate GUID
-
Source:
Sitecore.XConnect.Constants.AliasIdentifierSource
-
IdentifierType:
ContactIdentifierType.Anonymous
-
-
-
On session end, the interaction and device profile are saved to xConnect.
LastKnownContactId
points to the corresponding contact tracker ID.
Second visit - Laptop
In the following scenario, the same contact returns to a website on their laptop:
-
The contact visits
www.sitecore.net
- they have the SC_ANALYTICS_GLOBAL_COOKIE set to 60573a38-6925-4d92-8bff-327e41650d8f -
Request is sent to xConnect for a device profile that matches 60573a38-6925-4d92-8bff-327e41650d8f.
-
The
LastKnownContactId
of the device profile is used to get the contact by its tracker identifier - in this case, the tracker identifier matches the device profile ID:-
Identifier: 60573a3869254d928bff327e41650d8f
-
Source:
Sitecore.Analytics.XConnect.DataAccess.Constants.IdentifierSource
(Use “xDB.Tracker” in 9.0.0 - property is marked internal) -
IdentifierType:
ContactIdentifierType.Anonymous
-
-
If the contact exists, it is loaded into session - the anonymous tracking identifier was used to locate a known contact
-
At the end of the session, a second interaction is saved against the contact
Third visit - Laptop, cleared cookies
In the following scenario, the same contact returns to a website after clearing their cookies:
-
The contact clears their cookies
-
The contact visits
www.sitecore.net
and because the cookies have been cleared,SC_ANALYTICS_GLOBAL_COOKIE
no longer exists and a new device GUID is generated:-
Sitecore.Analytics.Tracker.Current.Contact.ContactId
set to 29751ac1-d99c-4efe-8547-cb42d90de6a0 -
SC_ANALYTICS_GLOBAL_COOKIE
set to 29751ac1-d99c-4efe-8547-cb42d90de6a0
-
-
Contact logs in and is identified using the following identifier:
-
Identifier: myrtlesitecore
-
Source: sitecoreextranet
-
IdentifierType:
ContactIdentifierType.Known
This contact and the identifier already exist, so no additional tracking identifier is created.
-
-
At the end of the session, a third interaction is saved against the contact
-
When the contact is saved, the
SC_ANALYTICS_GLOBAL_COOKIE
is used to create a new device profile - there is a table in the collection database that associates analytics cookie GUIDs with the last known contact that used this cookie.
Fourth visit - Laptop
In the following scenario, the same contact returns to a website on their laptop with an analytics cookie that does not match their tracking identifier:
-
The contact visits
www.sitecore.net
- they have theSC_ANALYTICS_GLOBAL_COOKIE
set to 29751ac1-d99c-4efe-8547-cb42d90de6a0 -
A request is sent to xConnect to get the device profile with an ID that matches 29751ac1-d99c-4efe-8547-cb42d90de6a0
-
The
LastKnownContactId
property of the device profile is used to retrieve a contact by its Tracker identifier -
If the contact exists, it is loaded into session - the device profile was used to load the contact
-
At the end of the session, a fourth interaction is saved against the contact.