Asset Count


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>


Free

Package Name

To install this plugin, search for its package name on the Plugin Store and click “Install”.


Information

  • Version 1.0.0
  • Last Update 1/12/2020
  • Active Installs 17
  • Compatibility Craft 3
  • License MIT
  • Categories Templating, Assets, Utilities

Report an issue