I'm hoping I've not gotten the wrong end of the stick here (as always the sitecore documentation is woeful!)
I wanted a way to store information against a visitor, I'm reasonably new to sitecore, but the contact facets seemed the idealsolution, pretty much implemented word for word from the link above, until it hit production I was quite pleased with it. When I stored information it persisted, I could read it:
public IMpmVisitorFacet GetMpmVisitorFacet()
{
return _contact.GetFacet<IMpmVisitorFacet>(_MPMVisitorConfigName);
}
and set info and everything seemed great. I could also see the sitecore SC_ANALYTICS_GLOBAL_COOKIE being set, everything seemed wonderful. Then I did some more thorough tests...
The problem appears to be that the data just doesn't persist for long. If I put some info into the facet it will hang around for an hour or so (I can close my browser, look at other, sites, etc. etc.) and I'll be able to access it but after an "amount of time" it just all goes away.
Having revisited the docs (have I mentioned that they're not very good) I noticed a caveat in a sentence that I didn't see before:
Well, I can create another web form page that only reads the employee number. That will show me that the contact facet data is being stored in memory at least. But what about permanent storage?
Hold on, I thought this was permanent storage?! So the example shows some code to read the "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 facet seems to only exist for a short period of time. It then goes on:
For performance reasons Sitecore only writes contact data to xDB when the session ends.This means that if I look in MongoDB...
it then goes on to show the data in it's new shiny trendy mongoDb implementation. But what use is it in mongo if I can't actually access and use that information programatically!
So this raises the question how do I access this contact information once the session is abandoned?
i.e. user logs into my site -> I add some information into their contact facet -> they come back the next day -> I want to read the information I added previously
There are several other docs which talk about accessing this data in the experience profile, to index into Lucene and in the Experience platform(why have two products with almost the exactly same name?!) but nothing to say how to access this information in the web site itself, in code.
To add to the comments by Dmytro Shevchenko:
- I can see my a user in the "experience profile" and I can see my visits to the site.
- I know this user did have my additional facet information because it triggered some code.
- I can find my user (from the id's taken out of the query string in the experience profile page) in the mongo Db
- But when I look at the user in mongoDb the additional information is not there.
- some of the contact records have this data but others don't
So it appears to be an issue with writing the new information to mongo...Does anyone have any help or similar experience of this?
ContactID. - Dmytro Shevchenko