MODX Most Popular Posts (or pages)

Jan 13, 2019


This blog has a couple of posts already about hit-tracking, so why a whole new Extra to do the job?

  1. MostPopular is session-aware, meaning it attempts to detect multiple hits (page views) within the same session and won't log duplicates. This behaviour is configurable.
  2. The logging Snippet also tries to skip hits from bots/crawlers.
  3. There's an option, enabled by default, to throttle hit logging by IP address. IP addresses are hashed to avoid storing data that can potentially be used to identify a user.
  4. Optionally log arbitrary data along with the page view, to support visualization and/or analysis (in an external workflow).
  5. Optionally log hits asynchronously via AJAX call.
  6. Not only can the listing Snippet get the "most popular" MODX Resources, but it can be configured with a time-frame, such as: "most popular Resources within the past 30 days".
  7. The query for most popular Resources is more performant than, for example, sorting by MODX TV values—especially in sites where there are a lot of TVs and Resources. With 5 million page views in the database, the default call for the "mpResources" Snippet returns in under 2 seconds.

NOTE: The use of features like datetime filtering, can drastically reduce query performance. For example, with 5 million hits to scan, setting the &fromDate property to a value that includes all records, increases the query time by a factor of 25. The datetime index can only do so much. Try to restrict such features to lower volume scenarios, or at least set the properties such that result sets are smaller, like: &fromDate=`-28 days` &toDate=`-21 days`



Install via MODX Extras Installer or download from the MODX Extras repo


Log Page Views


Include the "mpLogPageView" Snippet call as uncacheable on every Resource you wish to track. Generally this is done in the Template.

Get Most Popular Posts


Returns a comma-separated list of Resource IDs with the most pave views. Operates in 4 distinct "modes". See the README for more information or check back on this post.