can we track page_view and other events with server side and have distinct_id without mixpanel scripts
Yes, you can absolutely track page views and other events server-side without any Mixpanel client-side scripts, and you manage the distinct_id yourself. Here's how:
Tracking Events Server-Side
You can use Mixpanel's server-side SDKs (Python, Node.js, Java, Go, PHP) or the HTTP API directly โ no browser scripts needed. [Choosing the Right Method]
Option 1: HTTP API (language-agnostic)
curl --request POST \
--url https://api.mixpanel.com/track \
--header 'Content-Type: application/json' \
--data '[{
"event": "page_view",
"properties": {
"token": "YOUR_PROJECT_TOKEN",
"distinct_id": "user-12345",
"time": 1740000000,
"$insert_id": "unique-dedup-key-abc123",
"page_name": "/pricing"
}
}]'Option 2: Python SDK
from mixpanel import Mixpanel
mp = Mixpanel('YOUR_PROJECT_TOKEN')
mp.track(user_id, 'page_view', {
'page_name': '/pricing',
'ip': request.remote_addr # forward client IP for geolocation
})Option 3: Node.js SDK
const Mixpanel = require('mixpanel');
const mp = Mixpanel.init('YOUR_PROJECT_TOKEN');
mp.track('page_view', {
distinct_id: 'user-12345',
page_name: '/pricing'
});Managing distinct_id Without the SDK
Since server-side SDKs don't auto-generate IDs, you manage them yourself: [Server-Side Identity]
Anonymous users: Generate a UUID and store it in a cookie. Use it as $device_id.
Authenticated users: Use your internal user ID as $user_id.
Linking them: Send both $device_id and $user_id on the same event after login โ Mixpanel will merge the sessions automatically.
import uuid
def track_to_mp(request, event_name, properties):
properties["$device_id"] = request.cookies.get('SESSION_ID') # anonymous ID from cookie
if request.user.is_authenticated():
properties["$user_id"] = request.user.username # known user ID
mp.track("", event_name, properties) # leave distinct_id blank; Mixpanel resolves itPage View Best Practices
When tracking page views server-side: [Server-Side Best Practices]
Use a single event name (e.g., page_view) and differentiate pages via a property (e.g., page_name).
Fire the event only on successful responses to the client.
Parse headers for referrer and UTM parameters to capture marketing attribution.
Forward the client's IP address for correct geolocation (otherwise all events will appear to come from your server's location).
โน๏ธย Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.
