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.
1import uuid
2
3from plain import models
4
5
6class Pageview(models.Model):
7 uuid = models.UUIDField(default=uuid.uuid4, editable=False, unique=True)
8
9 url = models.URLField(max_length=1024, db_index=True)
10 timestamp = models.DateTimeField(db_index=True, auto_now_add=True)
11
12 title = models.CharField(max_length=512, blank=True)
13 referrer = models.URLField(max_length=1024, blank=True)
14
15 user_id = models.CharField(max_length=255, db_index=True, blank=True)
16 session_key = models.CharField(max_length=255, db_index=True, blank=True)
17
18 class Meta:
19 ordering = ["-timestamp"]
20
21 def __str__(self):
22 return self.url