I've tried this code, taken almost directly from Sitecore 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 totalCount
. On closer inspection, I found that the actual interactions are 0 (i.e. client.Interactions
even without filtering, returns a totalCount
of 0).
I check the analytics reports and I see page visits, even to the particular item I'm using, so it appears that data exists.
Any idea why this is happening, and/or what I'm doing wrong here?