Count and display the number of times that an asset has been viewed.

In order to count a directly accessed Asset, you will need to alter the url that the asset points to. This is so that the view is tracked before presenting the user with the original asset as intended.

So, instead of a link to the asset such as:

<a href="{{ file.url }}" target="_blank"></a>

You'll need to change it to:

{% set file = craft.assets.id(1234).one() %}

<a href="{{ actionUrl('asset-count/count', { id: file.id }) }}" target="_blank"></a>

// Or with Twig filter
<a href="{{ file | asset_count }}" target="_blank"></a>

// Or with Twig function
<a href="{{ asset_count(file) }}" target="_blank"></a>

Installation Instructions

To install this plugin, copy the command above to your terminal.

Active Installs
107
Version
2.0.0
License
MIT
Compatibility
Craft 3, Craft 4
Last release
July 10, 2022
Activity (30 days)
0
Closed Issues
0
Open Issues
0
Merged PRs
0
Open PRs