Prompt
how to track article views in a knowledge base
Latest observation
Nov 5, 2026
OpenAI APIWeb search: off
To track article views in a knowledge base, you typically instrument each article page so it records a “view” event whenever the article is loaded by a real user.
Common approaches
1) Frontend page-load tracking
Add analytics code to the article page that sends an event on page load.
Track fields like:
- article ID
- article title
- timestamp
- user ID or anonymous session ID
- referrer
- device/browser
- page URL
Example event:
knowledge_base_article_view- properties:
{ article_id: 123, category: "Billing", user_type: "guest" }
This is the simplest method and works well with tools like:
- Google Analytics
- Mixpanel
- Amplitude
- Segment
- PostHog
2) Backend logging
When a user requests an article, log the view on the server.
Pros:
- More reliable than frontend if JS is blocked
- Can filter out bots more easily
- Can track authenticated users accurately
Typical implementation:
- Article page request hits backend
- Backend creates a view record in a
article_viewstable or sends to analytics - Optionally deduplicate repeated views from same user/session within a short window
3) Hybrid approach
Use frontend events for analytics and backend logging for accuracy.
This is best if you need:
- robust reporting
- fraud/bot filtering
- unique vs total views
- per-user history
Best practices
Count unique views separately from total views
- Total views: every page load
- Unique views: one per user/session per article within a time window
For example:
- Count only one view per user per article every 24 hours
Filter out bots and internal traffic
Exclude:
- search engine crawlers
- uptime monitors
- your own team’s IPs
Decide what a “view” means
Common definitions:
- article fully loaded
- user scrolled at least 25%
- user spent at least 10 seconds on page
If you want more meaningful engagement, use one of those instead of raw page loads.
Example database schema
CREATE TABLE article_views (
id BIGSERIAL PRIMARY KEY,
article_id BIGINT NOT NULL,
user_id BIGINT NULL,
session_id VARCHAR(100) NULL,
viewed_at TIMESTAMP NOT NULL DEFAULT NOW(),
referrer TEXT NULL,
user_agent TEXT NULL,
ip_address INET NULL
);
For unique views, you can add a deduplication rule like:
- unique index on
(article_id, user_id, date_trunc('day', viewed_at)) - or maintain a separate aggregated table
Example frontend event tracking
fetch('/api/article-view', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
article_id: 123,
session_id: getSessionId(),
referrer: document.referrer
})
});
Metrics you can report
- total views per article
- unique views per article
- views over time
- top viewed articles
- views by category
- conversion from article view to support ticket deflection
If you want, I can also give you:
- a database design,
- a PHP/Laravel implementation,
- a Node/Express implementation, or
- a Google Analytics/PostHog setup.