This page demonstrates how to display view counts using the page view tracking script.
Simply add an element with data-page-views attribute:
<div data-page-views>Loading...</div>
Use data-format to customize the display format with
{views} and {domain} placeholders:
<span data-page-views data-format="👀 {views}
views"></span>
Include domain information in your view counter:
<p data-page-views data-format="{domain} has been viewed {views}
times"></p>
Loading...
You can also use CSS classes instead of data attributes:
<div class="page-views">Views: Loading...</div><span id="view-count">Loading...</span>
The script automatically looks for elements with any of these selectors:
[data-page-views] - Data attribute (recommended).page-views - CSS class#page-views - ID.view-count - CSS class#view-count - ID
Use the data-format attribute to customize how the count is
displayed:
{views} - Replaced with the view count (automatically
formatted with commas)
{domain} - Replaced with the current domainExamples:
data-format="{views}" - Just the numberdata-format="{views} views" - Number with "views" text
data-format="Viewed {views} times" - Custom textdata-format="📊 {views} page views on {domain}" - With
domain
To use view counters on your website:
<script
src="https://hard-house.club/track.js"></script>
You can also fetch view counts directly without using the automatic counter: