Hi all,
I have built an VUE SPA with discourse API to use on Wordpress, and was wondering if there’s way to send a POST request to update the Topic view count to discourse when user open the Topic on Wordpress?
The discussion revolves around syncing topic view counts from a WordPress site using a Vue.js SPA with the Discourse API. j3ang asks if it’s possible to update the topic view count in Discourse via a POST request when a user opens a topic on WordPress. angus explains that using the topics_controller’s show endpoint with proper authentication (e.g., API key) can track views, noting that TopicViewItem is the correct model for tracking views, not TopicView. j3ang clarifies that their setup uses a WordPress plugin for forum content and the Discourse plugin for SSO and webhooks, but the frontend is limited. They built a Vue SPA for better performance and features like filtering and search, but face issues with embedded replies displaying usernames instead of full names and asset paths being relative to Discourse. They also mention handling SEO via the wp_head hook. The core focus is on updating topic view counts in Discourse from a WordPress-based frontend.
Hi all,
I have built an VUE SPA with discourse API to use on Wordpress, and was wondering if there’s way to send a POST request to update the Topic view count to discourse when user open the Topic on Wordpress?
Hey Alex,
I’m curious to learn a little more about this. Anything you can share?
Viewing posts pulled by the WP Discourse plugin doesn’t create new views in Discourse, however if you use the standard show endpoint in the topics_controller, and you pass the check highlighted below, the “view” will be tracked. Note that using an api key will mean there’s a current_user.
One gotcha to note when you’re reading that code is that TopicView is not actually the droid you’re looking for (it’s a model that handles the data serialized when a topic is shown). The actual “topic view” model is TopicViewItem.
Hi @angus,
Thank you for your insight. I will look into the code base for topic views.
Regarding the SPA app:
Originally we had a forum plugin on Wordpress, they creates their own post type for questions and answers as well as category and tags. Upon setting up the SSO with WP Discourse plugin, I enabled Webhooks on discourse to sync topics to Wordpress with that post type, and using the embedding for answers.
At this point, the forum frontend is boring since each question item relying on its WP data only able to show title and author and I’d like to show the posters, views, likes and replies status as well. It didn’t make sense to me to modify that plugin.
With a SPA, pulling and display data would been much faster and flexible. It shows paginated latest topics, and a sidebar with Top topics, included with filter/search capability.
Originally, in the topic details view, I wanted to handle displaying the answers/replies as well. For some reason, the embedded replies was showing posters’ username instead of full name.
I also came across problems with the emoji and other assets are relative to the discourse site, so I fallback to stick with embeds.
Another problem was SEO, I was able to handle it with wp_head hook in WordPress.