Skip to main content
This document gives tips for implementing scalable, maintainable server-side tracking. If you’re just getting started, check out the quickstart.

Tracking Browser, Device, and OS

Mixpanel’s Web and Mobile SDKs parse User-Agent into a set of properties about the user’s browser, device, and OS. This doesn’t happen automatically with server-side tracking, but it’s easy to add these properties yourself. User-Agent is a header sent on all requests to your server. Most server frameworks provide a way to access your headers:
  • Django exposes this as request.headers["User-Agent"].
  • Flask exposes this as request.headers["User-Agent"].
  • Go exposes this in Headers["User-Agent"] on the http.Request struct.
  • Nginx exposes this as $http_user_agent.
Parse the user agent using a library for your language and send the browser, device, and OS properties to Mixpanel. Here’s an example using Python and uaparser:

Tracking UTMs and Referrer

Mixpanel’s Web SDK parses UTM parameters from the current URL and obtains referrer information from the browser’s document.referrer property to enable easy marketing analytics. Since this is not automatic for server-side implementations, these properties will need to be added manually to tracked events. Below is an example in Python:

Tracking Geolocation (Server-side)

By default, Mixpanel uses the IP address of the request to set geolocation properties. If you’re tracking from your server, you need to override the IP property of your events and profile updates from your server’s IP address to the client’s IP address. Read our full guide on managing geolocation.

Tracking Page Views

Page view tracking must be done manually for server-side implementations. Here are some general guidelines for tracking page views.
  • Track page views as a single event type by using a constant event_name
  • Track different pages as an event property and not as different events for better analysis
  • Plan ahead for handling page views from anonymous users, identified users, and connecting them to merge a user’s journey
  • Fire page view events only on successful responses to the client
  • Parse headers and the request URL for common web analytics properties such as referrer and UTM parameters

Identifying Users

Mixpanel’s server-side SDKs and HTTP API do not generate IDs automatically, meaning your server is responsible for generating IDs and maintaining ID persistence. Read our full guide on Server-side ID Management.