会话刷新后,我仍然可以访问Sitecore联系人界面吗? [英] Can I still access a sitecore contact facet once session is flushed?

查看:120
本文介绍了会话刷新后,我仍然可以访问Sitecore联系人界面吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我在这里没有遇到错误的结局(因为站点核心文档一如既往的糟糕!)

I'm hoping I've not gotten the wrong end of the stick here (as always the sitecore documentation is woeful!)

我想要一种针对访问者存储信息的方法,我对Sitecore来说还很陌生,但是

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);
}

并设置信息,一切似乎都很棒.我还可以看到设置了sitecore SC_ANALYTICS_GLOBAL_COOKIE,一切似乎都很棒.然后,我做了一些更彻底的测试...

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:

出于性能原因,Sitecore仅在以下情况下将联系人数据写入xDB: 会话结束.这意味着如果我查看MongoDB ...

For performance reasons Sitecore only writes contact data to xDB when the session ends.This means that if I look in MongoDB...

然后继续显示其新的闪亮时尚mongoDb实现中的数据.但是,如果我实际上无法以编程方式访问和使用该信息,在mongo中有什么用!

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!

因此,这引发了一个问题:一旦会话被放弃,我该如何访问此联系信息?

即用户登录到我的网站->我将一些信息添加到他们的联系方式中->他们第二天回来->我想阅读我之前添加的信息

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.

要通过 Dmytro Shevchenko 添加到评论中,

  • 我可以在体验资料"中看到我的用户,也可以看到我的用户 访问该网站.
  • 我知道该用户确实有我的其他方面信息,因为它 触发了一些代码.
  • 我可以找到我的用户(从ID中从查询字符串中取出ID 体验资料页面)在mongo Db中
  • 但是当我在mongoDb中查看用户时,其他信息是 不在那里.
  • 某些联系人记录中有此数据,而其他联系人则没有
  • 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

所以将新信息写给mongo似乎是个问题 ...有人对此有任何帮助或类似经验吗?

So it appears to be an issue with writing the new information to mongo...Does anyone have any help or similar experience of this?

推荐答案

经过大量的调试,摆弄和测试,我终于弄明白了.事实证明,我的问题不是写给mongo,而是写完mongo后再读出来.

After a great deal of debugging, fiddling and testing I finally figured this out. My issue, it turned out, wasn't the writing to mongo it was in the reading back out of mongo once it had been written.

sitecore文档似乎(像往常一样)完全错过了此工作的相当基本的部分.大约三分之一的查看其说明的文档:

The sitecore documentation seems (as usual) to completely miss a rather fundamental part of the working of this. About a third of the way down the docs it states:

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

"EnsureAttribute"方法等效于声明一个 值类型变量.

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


好的,这很容易引起误解.此EnsureAttribute似乎要执行的操作是从mongo将构面的数据加载到当前类中. 如果您不针对每个属性执行此操作,那么它就不会设置mongoDb中的值!这是我的错误,我没有确保"类中的每个属性.


Ok, this is very misleading. What this EnsureAttribute appears to do is load the data for the facet into the current class from mongo. If you don't do this for every property in your facet then it does not set the value from the mongoDb! This was my mistake, I hadn't "ensured" every property in the class.

发生了什么事

  • 我将数据放入了方面
  • 构面数据保留在会话中,我可以看到,访问它并对其进行更改等.
  • 数据最终会刷新到mongo(如果需要,则为xDb)
  • 用户返回,系统正确识别出他们(无需识别用户SC_ANALYTICS_GLOBAL_COOKIE为您完成此操作)
  • 但是除非您确保"数据,否则它不会加载数据(从mongo中加载并返回到会话中).
  • I put my data into the facet
  • the facet data persists in the Session and I can see, access it change it,etc.
  • The data is eventually flushed to mongo (xDb if you must)
  • the user returns, the system recognises them correctly (there is no need to identify the user, the SC_ANALYTICS_GLOBAL_COOKIE does this for you)
  • But it does not load the data (out of mongo and back into the session) unless you "ensure" it.

因此EnsureAttribute不会声明值类型" (在我看来,这是完全错误的),它将数据从mongodb中加载到当前的Session中.

So the EnsureAttribute does not "declare a value type" (this is just totally wrong in my opinion) it loads the data out of mongodb and into the current Session.

这篇关于会话刷新后,我仍然可以访问Sitecore联系人界面吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆