I've tried this code, taken almost directly from sitecoreSitecore documentation (they are using Goal, I'm using PageViewEvent).
var itemId = <some id of an Item in content>;
using (var client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
{
queryable = client.Interactions.Where(x =>
x.Events.OfType<Sitecore.XConnect.Collection.Model.PageViewEvent>().Any(y =>
y.ItemId == itemId.Guid));
if (queryable == null) return totalCount;
Sitecore.XConnect.Client.Synchronous.IEntityBatchEnumerator<Interaction> enumerable =
queryable.GetBatchEnumeratorSync();
while (enumerable.MoveNext())
{
foreach (Interaction interaction in enumerable.Current)
{
int pageVisits = interaction.Events.OfType<Sitecore.XConnect.Collection.Model.PageViewEvent>()
.Count(x =>
x.ItemId == itemId.Guid &&
x.ItemLanguage == Sitecore.Context.Language.Name);
if (uniqueVisits)
{
pageVisits = pageVisits > 0 ? 1 : 0;
}
totalCount += pageVisits;
}
}
}
This always 0 returns for totalCounttotalCount
. On closer inspection, I found that the actual interactions are 0 (i.e. client.Interactions
even without filtering, returns a totalCounttotalCount
of 0).