Tracks SilverStripe page views/visitors/hits in a simple counter record
Tracks page views in a simple counter record, and the behaviour is applied
DataObject subclass through an extension.
This approach of a separate counter record is particularly handy
if you apply it to
Versioned objects like
you can store the view data independently of staging and live concerns.
Views are limited by session. This is a slightly simplistic approach, since it doesn't use other criteria such as the current IP address or browser cookies to prevent abuse. Common web crawlers and search engine bots are excluded from view counts.
Add the following to your YAML config (e.g.
MyRecordClass: extensions: - ViewCountableExtension
Views stored in a
ViewCount record which relates to your record class.
If applying the extension to a
SiteTree subclass, views are automatically tracked.
For other classes, call
trackViewCount() in your own controller