Tracking contacts

Current version: 10.2

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:

  1. 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

  2. The contact browses a few pages.

  3. The contact closes their browser and the session ends - the contact is saved to xConnect:

    • A new Sitecore.XConnect.Contact is created

    • An anonymousSitecore.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:

  1. Contact visits www.sitecore.net - they have the SC_ANALYTICS_GLOBAL_COOKIE set to 60573a38-6925-4d92-8bff-327e41650d8f

  2. Request is sent to xConnect for the device profile matching 60573a38-6925-4d92-8bff-327e41650d8f

  3. The LastKnownContactId of the device profile is used to retrieve a contact from xConnect by its tracker identifier

  4. 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)

  5. 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:

  1. Contact clears cookies

  2. 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

  3. 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:

  1. 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

  2. The contact registers with the username myrtlesitecore and logs in

  3. When the contact logs in, you can use their username to identify them upon successful login:

    RequestResponse
    Sitecore.Analytics.Tracker.Current.Session.IdentifyAs("sitecoreextranet", "myrtlesitecore");
    
    Note

    Identification and authentication are separate, unrelated events. Contacts are identified against the xDB, and authenticated against whatever mechanism the website is using.

  4. 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

  5. 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:

  1. The contact visits www.sitecore.net - they have the SC_ANALYTICS_GLOBAL_COOKIE set to 60573a38-6925-4d92-8bff-327e41650d8f

  2. Request is sent to xConnect for a device profile that matches 60573a38-6925-4d92-8bff-327e41650d8f.

  3. 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

  4. If the contact exists, it is loaded into session - the anonymous tracking identifier was used to locate a known contact

  5. 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:

  1. The contact clears their cookies

  2. 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

  3. 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.

  4. At the end of the session, a third interaction is saved against the contact

  5. 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:

  1. The contact visits www.sitecore.net - they have the SC_ANALYTICS_GLOBAL_COOKIE set to 29751ac1-d99c-4efe-8547-cb42d90de6a0

  2. A request is sent to xConnect to get the device profile with an ID that matches 29751ac1-d99c-4efe-8547-cb42d90de6a0

  3. The LastKnownContactId property of the device profile is used to retrieve a contact by its Tracker identifier

  4. If the contact exists, it is loaded into session - the device profile was used to load the contact

  5. At the end of the session, a fourth interaction is saved against the contact.

Do you have some feedback for us?

If you have suggestions for improving this article,