Jessica_S initiated a discussion regarding the inability to display download counts for files uploaded directly to Discourse posts, specifically on a Pro hosting plan restricted to theme components. She noted that her current implementation shows a count of 0 and asked if Discourse natively tracks these downloads or if external solutions are required. Rajat_99 sought clarification on whether unique or total downloads were needed, but RGJ provided the technical solution: Discourse exposes link click data in the post stream JSON under post.link_counts. RGJ demonstrated that attachment clicks are counted, and this data can be accessed via JavaScript, eliminating the need for external APIs.
Following this advice, Rajat_99 acknowledged the utility of post.link_counts for theme development. However, Jessica_S reported that while she had integrated the logic, the counts still did not appear automatically. When asked for details by Moin, she shared her theme component code here. The shared JavaScript utilizes apiInitializer and decorateCookedElement to target attachments in the first post of a topic. It attempts to match the attachment’s URL path against the link_counts array to retrieve the clicks value, then formats and appends this count to the download button’s UI. The accompanying CSS styles the button with rounded corners and a badge for the count. The discussion currently highlights a disconnect between the available JSON data and the theme component’s ability to render it, suggesting potential issues with the selector logic or data mapping in her implementation.
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.