Plain is headed towards 1.0! Subscribe for development updates →

plain-pageviews

Track pageviews from the client-side.

FAQs

Why not use server-side middleware?

Originally this was the idea. It turns out that tracking from the backend, while powerful, also means you have to identify all kinds of requests not to track (assets, files, API calls, etc.). In the end, a simple client-side tracking script naturally accomplishes what we're looking for in a more straightforward way.

 1from plain.templates import register_template_extension
 2from plain.templates.jinja.extensions import InclusionTagExtension
 3from plain.urls import reverse
 4
 5
 6@register_template_extension
 7class PageviewsJSExtension(InclusionTagExtension):
 8    tags = {"pageviews_js"}
 9    template_name = "pageviews/js.html"
10
11    def get_context(self, context, *args, **kwargs):
12        return {
13            "pageviews_track_url": reverse("pageviews:track"),
14        }