Can I access the granite of contact with the site after a session break?

I hope I don’t have the wrong end of the stick here (as always the documentation on the side-card is terrible!)

I need a way to store information against the visitor, I'm fairly new to sitecore, but the contact faces were the perfect solution , I implemented word for word from the above link to a large extent, until it got into production, I was very pleased with this. When I saved the information, it was saved, I could read it:

public IMpmVisitorFacet GetMpmVisitorFacet() { return _contact.GetFacet<IMpmVisitorFacet>(_MPMVisitorConfigName); } 

and set up the information, and everything seemed gorgeous. I could also see that sitecore SC_ANALYTICS_GLOBAL_COOKIE installed, everything seemed wonderful. Then I did some more thorough tests ...

The problem is that the data simply does not last long. If I put some information on the facet, it will stand for about an hour or so (I can close the browser, look at other sites, etc. Etc.), And I can access it, but after the "amount time, "it’s just leaving.

After reviewing the documents (I already mentioned that they are not very good), I noticed a reservation in a sentence that I had not seen before:

Well, I can create another page of the web form that only reads the employee number. This will show me that the contact facet data is stored at least in memory. But what about persistent storage?

Hold on, I thought this was a permanent store ?! Thus, the example shows some code for reading "facet".

 var contact = Tracker.Current.Contact; var data = contact.GetFacet<IEmployeeData>("Employee Data"); data.EmployeeId = "ABC123"; ..... <p>Employee data contact facet updated.</p> <p>Contact ID: <b><%=contact.ContactId.ToString()%></b></p> <p>Employee #: <b><%=data.EmployeeId%></b></p> 

But this line seems to exist only for a short period of time. Then it continues:

For performance reasons, Sitecore only writes contact information to xDB when the session ends. That means if I look in MongoDB ...

Then he continues to show the data in it with a new brilliant fashionable implementation of mongoDb. But what use is it in mongo if I cannot access this information and use it programmatically!

So the question is, how do I access this contact information after the session is left?

i.e. the user is registered on my site β†’ I add some information to their contact face β†’ they return the next day β†’ I want to read the previously added information

There are several other documents that talk about access to this data in the experimental profile , in the index in Lucene and in the Experience platform (why are there two products with almost the same name ?!), but there is nothing to say how to access this information on the web itself -site in code.


To add to the comments of Dmitry Shevchenko :

  • I can see my user in the "experience profile", and I can see my site visits.
  • I know that this user had additional information about the facet because it caused some code.
  • I can find my user (from the identifier displayed from the query string to the experience profile page) in mongo Db
  • But when I look at the user in mongoDb, the additional information is not there.
  • Some contact entries have this information, but others do not

So it seems that the problem is related to writing new information in mongo . Anyone have any help or similar experience?

+5
source share
3 answers

After much debugging, messing around and testing, I finally figured it out. My problem, it turned out, was not writing mongo, it was reading from mongo as soon as it was written.

The sitecore documentation seems (as usual) to completely skip the pretty fundamental part of the job. About a third is deleted in the documents that he indicates :

 public EmployeeData() { base.EnsureAttribute<string>(FIELD_EMPLOYEE_ID); } 

The "EnsureAttribute" method is the equivalent of declaring a value type variable.


Well, this is very misleading. It seems that this is EnsureAttribute - this is loading the facet data into the current class from mongo. If you do not do this for each property in its face, then it does not set the value from mongoDb! . It was my mistake, I did not "provide" every property in the class.

So what happens

  • I put my data in a facet
  • facet data is saved in the session, and I see access to it changes it, etc.
  • Eventually the data will be flushed to mongo (xDb if you need)
  • the user returns, the system recognizes them correctly ( there is no need to identify the user , SC_ANALYTICS_GLOBAL_COOKIE does this for you)
  • But it does not load data (from mongo and back to the session), unless you "provide" it.

Thus, EnsureAttribute does not declare the type of value (this, in my opinion, is completely wrong), it loads data from mongodb and into the current Session .

+2
source

I think this step may be missing here - the Tracker.Current.Session.Identify() method to identify a known contact. Data in the Tracker api only continues for the current session, and you need to load the contact into the session.

The xDB implementation relies on a contact identifying itself when visiting the site, by logging in or registering, for example.

After logging in, you can use a unique identifier, such as an email address, and pass it to the authentication method - Tracker.Current.Session.Identify("Email Address of the visitor") .

Once you have called this method, if the user has previously identified himself, the contact information will be loaded into the current session, and any existing facet information will be available in Tracker Api.

0
source

Your problem is how you drag the contact: If you are in a page request, you must access the current contact through Tracker.Current.Contact. your code is not in the page request, but the user may have a live session, use ContactManager with the methods described above. If the contact is not live right now, you should use ContactRepository. See a usage example here. Copied from https://sitecore.stackexchange.com/questions/3319/why-are-custom-xdb-facets-being-overwritten-on-session-end to which Dmitry Shevchenko responded.

0
source

Source: https://habr.com/ru/post/1232537/


All Articles