Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/doublesecretagency/craft-viewcount
View Count plugin for Craft CMS
https://github.com/doublesecretagency/craft-viewcount
Last synced: about 11 hours ago
JSON representation
View Count plugin for Craft CMS
- Host: GitHub
- URL: https://github.com/doublesecretagency/craft-viewcount
- Owner: doublesecretagency
- License: other
- Created: 2019-01-22T06:32:25.000Z (almost 6 years ago)
- Default Branch: v2-dev
- Last Pushed: 2024-02-21T23:30:01.000Z (9 months ago)
- Last Synced: 2024-04-24T00:41:35.474Z (7 months ago)
- Language: PHP
- Size: 812 KB
- Stars: 6
- Watchers: 4
- Forks: 3
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# View Count plugin for Craft CMS
**Count the number of times an element has been viewed.**
---
---
## Track views via Twig, PHP, or AJAX
Basic tracking looks like this...
```twig
{% do craft.viewCount.increment(elementId) %}
```However, there are several more advanced ways to [increment a view counter](https://plugins.doublesecretagency.com/view-count/how-to-increment-the-counter/).
## Allow multiple counters on the same element
If you need to track multiple aspects of the same element, it's easy to do so! Simply specify an [optional key](https://plugins.doublesecretagency.com/view-count/using-a-unique-key/) when setting up the tracking mechanism.
## Sort by "most viewed"
Once you've started logging views, you'll likely want to know which items have been [viewed the most...](https://plugins.doublesecretagency.com/view-count/sort-by-most-viewed/)
```twig
{% set articles = craft.entries.section('articles') %}
{% do craft.viewCount.sort(articles) %}
```## Display view totals in the control panel
You can add a ["Total Views" field](https://plugins.doublesecretagency.com/view-count/total-views-fieldtype/), which displays a read-only total for each element.
## Events
They do [exactly what you think...](https://plugins.doublesecretagency.com/view-count/events/)
- EVENT_BEFORE_VIEW
- EVENT_AFTER_VIEW
Within the `EVENT_BEFORE_VIEW` event, you can prevent the view from being counted.---
## Further Reading
If you haven't already, flip through the [complete plugin documentation](https://plugins.doublesecretagency.com/view-count/).
And if you have any remaining questions, feel free to [reach out to us](https://www.doublesecretagency.com/contact) (via Discord is preferred).
**On behalf of Double Secret Agency, thanks for checking out our plugin!** 🍺