Importing the number of pageviews and likes into the database (for popular posts feature)


It would be great if there would be a feature (even experimental) that allows the interogation of Google Analytics’ and Facebook’s APIs to retrieve the number of pageviews and likes respectively for each post.

The information could be then used by theme authors or developers to build fast and reliable lists of popular posts or to further increase the relevance of related posts.

Popular posts, while a useful and desired feature, are usually hard to get right while in the Wordpress landscape plugins have made a mess of it, mostly by overcomplicating things. So people tend to stay away, but would likely gladly jump back in if done right.

With Google it would need authentication while with Facebook the data is public as json. As soon as the information is in the database, a simple query sorting by any of these fields, with or without time-limits, should be enough to build the list.

After years of experimenting I have settled for a plugin called Social Metrics that does cron jobs with the two services and updates the respective fields. Seeing how impressive Ghost looks already, the functionality of that plugin would be the only thing I’ll miss from WP.


If you follow the JAMstack model there’s no need to insert that data into Ghost.

Instead, you can either pull the data directly from 3rd party services, or use your cron to compile the data somewhere else, and pull the two things together in your frontend.

There’s quite a few different ways to achieve this, i.e. publish a list of popular post slugs/ids and using the API to fetch those posts, publishing a pre-populated list with all fields, or adding a #popular tag to posts that are most popular and using this to pull related posts that are also popular.

E.g. filter=tag:[{{primary_tag.slug}}, 'hash-popular'] would return posts with either tag, but automatically ordered so that posts with both tags are first.

There’s quite a lot that can be done without having to amend Ghost core to cope with specific use cases. We’re actively working on our APIs and webhooks at the moment to facilitate this way of working.


Thank you. Would you kindly point me to any sort of relevant implementation so I can see what I can do myself. I’ll share here whatever I’m able to come up with.

What exactly would be somewhere else? After looking over the code a bit I realise that a lot of things are done much easier (I have 300+ lines in my functions.php just to correct functionality that in ghost is either default or easily configurable) but it’s my first contact with node.js and I don’t quite know where to start…

The way I see it this far, a basic core implementation - or at least a best-practice recommendation on how it should be done - would help make the functionality less theme dependant.


I found this resource that apparently does the job, but it seems quite complicated to put in place while I’m not sure if it’s either robust (will it break on the next update?) or scalable performance-wise (the guy uses it on a separate page, but could this be used safely as a frontpage section, for example?)