Jessica_S seeks to display download counts for files uploaded directly to Discourse posts on a Pro hosting plan, using only theme components. She reports that her initial attempts to read click counts via a custom theme component resulted in a count of 0. Rajat_99 asks clarifying questions about whether unique or total downloads are needed and if guests should be counted.
RGJ clarifies that Discourse does expose click counts in the post stream JSON under the post.link_counts array. However, this tracking relies on links being processed as standard hyperlinks. Moin highlights a critical limitation: Discourse’s built-in link tracking may not apply to internal file attachments uploaded directly to the platform, especially if they are served via /uploads/short-url/ links, which are often excluded from standard click tracking to prevent privacy issues or enumeration.
Jessica_S shares her JavaScript implementation, which decorates attachment links by matching the file path against the link_counts array. Despite correct code structure, the counts remain empty. Moin confirms that uploaded attachments typically do not generate tracked link_counts entries in the JSON. Jessica_S confirms this finding, noting that only external links seem to work for tracking.
The discussion concludes with Jessica_S asking for advice on how to set up external hosting (e.g., GitHub Releases) to enable automatic download counting. The core takeaway is that to track download counts effectively on Discourse Pro using theme components, files likely need to be hosted externally and linked via standard URLs, as internal Discourse attachments do not reliably expose click data in the post.link_counts JSON field.
We run a community on Discourse (Pro hosting, so no custom plugins, only themes and theme components). We have a category where members share downloadable files (BIOS packages, scripts, config packs). These files are uploaded directly to Discourse, not hosted on GitHub or elsewhere.
What we want
A visible download count on each file, similar to the reference screenshot below (a skills marketplace showing favorites, installs and a download button). Ideally:
a count that increases each time someone downloads the attachment,
shown in the topic and, if possible, on topic list cards,
sortable or filterable later if the data is available.
What we tried
We built a theme component that adds a download button and tries to read the attachment’s click count. The count always stays at 0, even after several test downloads from different accounts.
What we need to know
Does Discourse track downloads of uploaded attachments out of the box? If yes, where is that data stored, and is it exposed in the topic/post JSON, or the Data Explorer?
If it is tracked as link clicks, are attachment clicks counted when the file is opened via the /uploads/short-url/... link, and does that count depend on any site setting (for example, tracking clicks for internal links)?
If it isn’t tracked, what’s the recommended approach on a hosted plan? For example, a tracking redirect, an API-based counter, or a theme component that reports to an external endpoint.
Does the count behave differently for files added through a Form Template “upload” field compared with files added in the normal composer?
Environment
Discourse Pro hosted, Foundation theme
Files uploaded as post attachments (not external links)
I would expect someone with 10+ years of experience in Discourse theme development to be able to figure out that Discourse exposes those counts in the post stream json
@RGJ Thanks for pointing this out. You’re right, I appreciate the clarification. I’ll look into the post.link_counts data in the post stream JSON and how it can be used to display attachment download counts through a Discourse theme component.
Did you check the json for that post manually? Is the link_count you are looking for included? I think the file needs to use an external link for this to work
So uploaded attachments don’t seem to be counted. If we use an external link instead (for example GitHub Releases), will the click count show automatically? How should I set that up as a beginner?