Skip to main content
Formatting and clarifying the result count text
Source Link
Dan Sinclair
  • 5.5k
  • 2
  • 20
  • 44

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).

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 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'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).

Bumped by Community user
Bumped by Community user
Bumped by Community user
Source Link

Sitecore 10.1 standalone instance always brings 0 interactions

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 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?