Views Work v2.0
Track pageviews and content popularity in Craft CMS
More Craft plugins

Register a pageview

Pageviews are registered by a specially generated image. The image url is signed with a secret key so malicious users cannot easily tamper with your pageviews.

To show the image for an entry:


{# render the image for registration #}
{{ entry | views_work_image }}

Register views programmatically for an asset (example)

If you don't want to use a pixel, you can increase views programmatically, for example when an asset is shown:


{% set asset = craft.assets.one %}
    {% if asset %}
        {% do asset.viewsWork.increment()    %}
        <img src="{{ asset.url }}" style="max-width: 100px;" />
        Views: {{ asset.viewsWork.total }} / {{ asset.viewsWork.thisMonth }} / {{ asset.viewsWork.thisWeek }} / {{ asset.viewsWork.today }}
    {% endif %}

Weighted pageviews

Sometimes you'd want a pageview to count less than others. This can happen if you use pageviews as a popularity index and want to balance. In that case you can pass a weight factor to the image. In the case below, the factor is 1.5; every 2 pageviews, an extra pageview is counted on average.


{# render the image for registration #}
{{ entry | views_work_image({factor: 1.5}) }}