We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 46971
    • 33 Posts
    I use the HitsPage extra to save the page views of some portfolio pages. On my start page I put out the view counts of several sites as a list for logged in users.

    Code Lines:
    <p>Views: [[!HitsPage?&saveTv=`true`]]</p> [[- Aufrufe der Projektseiten zählen]]

    In a tpl-chunk for getresource:
    [[!+modx.user.id:eq=`0`:then=``:else=`<p class="small ccc">Views: [[+HitsPage]]</p>`]]


    Now I would love to get the difference to the last login (later maybe a statistic for the week / month). For example the output should be something like this:

    Views: 22 | Last time (logged in): 14 | Increased: +6



    Does anybody know how to get this? Maybe without any line of php? laugh
    Any Pro user here? smiley
      • 3749
      • 24,544 Posts
      It's actually fairly complicated. AFAIK, the HitsPage snippet doesn't store any information other than the total number of hits for each page. That would make it literally impossible to use it to do what you want, since there's no historical data. You also won't be able to do it without any PHP code.

      In order to do what you ultimately want, you'd have to store the hits value for every week and/or month for every portfolio page. Probably the best way to do this is with a custom script triggered once per week or month by a cron job. The snippet would collect all the current data and save it to a new line in a file or to a new record in the DB.

      Then, a custom snippet on the summary page could access that data, do the calculations, and display whatever you want to site visitors.

      This should be done first, because in many ways it's simpler than the "since last login" report, and because once it works, it's possible to go from there to the "since last login" report. It's very easy to get the user's "last login" date when they log in, and it shouldn't be too difficult to calculate and display whatever you want based on the difference between the stored values near the time of the last login, and the current values.

      Maybe someone else can suggest a simpler way to do this.

        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting