how can I show yesterday's page view statistics in Kentico?

amir kian asked on July 28, 2020 08:58

I want to show yesterday page view statistics statistic in kentico10 I have used page view web part, but it doesn't include yesterday field as shown below.

Image Text

But it doesn't include yesterday field!

Recent Answers


David te Kloese answered on July 28, 2020 10:27

This is mainly an example Web Part. I'd recommend to clone it and create your own Web Part.

You can alter this one, but it might break functionality on other places or when applying upgrades or a hotfix.

That being said; When you've cloned it:

You have to alter the Web Part Properties and Code. In Kentico:

web part config

In Code:

code

In the ReloadData() method you can extend the switch logic for the StatisticsType based on what you extended in the previous step setting the fromDate (00:00 yesterday) and toDate (23:59? yesterdaor 00:00 today) values.

1 votesVote for this answer Mark as a Correct answer

amir kian answered on July 28, 2020 13:07 (last edited on July 28, 2020 13:08)

@David I used below codes to show yesterday case 5: { fromDate = fromDate.AddDays(-1); toDate = DateTimeHelper.GetDayStart(DateTime.Now); interval = HitsIntervalEnum.Day; } break; Is it correct?

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on July 28, 2020 14:40

Allmost, think you also need to round the FromDate.

So something like:

case 5:
    {
        fromDate = DateTimeHelper.GetDayStart(fromDate.AddDays(-1));
        toDate = DateTimeHelper.GetDayStart(toDate);
        interval = HitsIntervalEnum.Day;
    }
    break;

Since both to and from properties are already set I'd use those instead of adding a new DateTime.Now. But the result would be the same :)

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on August 11, 2020 15:41

Cross posted here, with the answer.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.