Implementing a simple page-counter in Elements?

Maybe a good thing to implement. A simple page-counter within elements, just to have an easy access to the number of visitors …

1 Like

You can make a simple custom component. You will just need to change the tailwind text colour class to what you want.

<span id="counter" class="text-text-500">Page Visits: </span>

<script>
const key = "pageVisits:" + location.pathname;
const visits = (localStorage[key] = (+localStorage[key] || 0) + 1);
document.getElementById("counter").textContent = "Page visits: " + visits;
</script>

1 Like

Thank you Doobox

I use a lot of your apps in RW and it was my motivation to get something similar to your app :wink: Greetings to Jersey

Bettor version that purposely only works in the published page. Else while developing teh site you will be crating local storage keys that become entirely redundant after publishing.

<span id="counter" class="text-text-500">Page Visits: (0)</span>

@if(!preview) 
<script>
const key = "pageVisits:" + location.pathname;
const visits = (localStorage[key] = (+localStorage[key] || 0) + 1);
document.getElementById("counter").textContent = "Page visits: " + visits;
</script>
@endif

Very nice move. Thank you very much. If I can help you as a Corporate Designer - I gladly will do so.

1 Like

Wait Noooooo!

I’ve lost the plot. This will only work per visitor.

For all visitors to see the real page views a server side php solution is needed.

So i wait patiently till you develop a add on for elements :slight_smile: