how to add the default Mixpanel events for server side tracking is there a specific library to call, how does this work and what instruction is required to inform the developer so they can complete this deliverable?
Hi event, Please stand by as I search the Mixpanel knowledge base for an AI-powered answer. I normally take about 15 seconds or so. In case AI cannot answer your question, feel free to reach out to Mixpanel support at mixpanel.com/get-support. If you have follow-up questions for this thread, please tag me again with your question: @kapa.ai <follow-up question> 👋
Feel free to ask a follow-up question once I've answered by mentioning me with @kapa.ai
Mixpanel’s default (automatically tracked) events—such as page views, clicks, device info, and UTM parameters—are only collected automatically when using Mixpanel’s client-side SDKs (e.g., JavaScript, iOS, Android). When tracking events server-side, these default events and properties are not collected automatically. There is no server-side library or function that will add these default events for you.
How does this work? - With server-side tracking, you are responsible for sending all events and properties explicitly. The server-side SDKs (e.g., Python, Node.js, Ruby) do not automatically capture browser, device, OS, UTM, or referrer information, nor do they generate default events like page views or clicks. - If you want to capture the same data as the client-side SDKs, you must extract this information from incoming requests (e.g., parse the User-Agent header, extract UTM parameters from URLs, etc.) and include them as properties when sending events to Mixpanel.
Instructions for Developers:
1. Manually collect default properties:
- Parse the User-Agent header to get browser, device, and OS info.
- Extract UTM parameters and referrer from request URLs and headers.
- If you want to track page views or similar events, you must define and send these events yourself.
2. Add these properties to your event payloads: Example in Python:
from mixpanel import Mixpanel
from ua_parser import user_agent_parser
mp = Mixpanel("YOUR_TOKEN")
def track_to_mp(request, event_name, properties):
parsed = user_agent_parser.Parse(request.headers["User-Agent"])
properties.update({
"$browser": parsed["user_agent"]["family"],
"$device": parsed["device"]["family"],
"$os": parsed["os"]["family"],
})
Add UTM and referrer if available
if "Referrer" in request.headers: properties.update({ "$referrer": request.headers["referrer"], "$referring_domain": urlparse(request.headers["Referrer"]).hostname }) utm_keys = ["utm_source", "utm_medium", "utm_campaign", "utm_content", "utm_term"] utm_values = {key: request.args[key] for key in utm_keys if request.args.get(key)} properties.update(utm_values) properties["ip"] = request.remote_addr mp.track(request.user_id, event_name, properties)
[See full example and best practices](https://docs.mixpanel.com/docs/tracking-best-practices/server-side-best-practices)
3. **Communicate to developers:**
- There is no automatic collection of default events or properties server-side.
- Developers must manually extract and send any desired properties/events.
- Reference Mixpanel’s [server-side best practices](https://docs.mixpanel.com/docs/tracking-best-practices/server-side-best-practices) for guidance.
**Summary:**
There is no server-side Mixpanel library or function that will automatically add default events or properties. Developers must manually collect and send this data as part of each event payload when using server-side tracking. This is a key difference from client-side SDKs, which handle much of this automatically.
[Source: Server-Side Best Practices](https://docs.mixpanel.com/docs/tracking-best-practices/server-side-best-practices)
kapa.ai is still learning and improving, please let me know how I did by reacting below.
ℹ️ Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.
Let me check the knowledge base for you again. One moment! 📚
When using server-side tracking with Mixpanel, default events and properties (like page views, device info, UTM parameters, etc.) are not collected automatically as they are with client-side SDKs. There is no server-side library or function that will automatically generate these default events for you.
To get the equivalent of default Mixpanel events and properties on the server side, you must:
1. Manually track events: You need to explicitly send events such as page views or signups from your server code.
2. Manually collect and add default properties:
- User-Agent parsing: Extract browser, device, and OS information from the User-Agent header using a parsing library.
- UTM parameters and referrer: Extract UTM parameters and referrer information from the request URL and headers.
- Geolocation: Use the client’s IP address (not your server’s) if you want accurate location data.
Example (Python):
from mixpanel import Mixpanel
from ua_parser import user_agent_parser
from urllib.parse import urlparse
mp = Mixpanel("YOUR_TOKEN")
def track_to_mp(request, event_name, properties):
parsed = user_agent_parser.Parse(request.headers["User-Agent"])
properties.update({
"$browser": parsed["user_agent"]["family"],
"$device": parsed["device"]["family"],
"$os": parsed["os"]["family"],
})
if "Referer" in request.headers:
properties.update({
"$referrer": request.headers["Referer"],
"$referring_domain": urlparse(request.headers["Referer"]).hostname
})
utm_keys = ["utm_source", "utm_medium", "utm_campaign", "utm_content", "utm_term"]
utm_values = {key: request.args[key] for key in utm_keys if request.args.get(key)}
properties.update(utm_values)
properties["ip"] = request.remote_addr
mp.track(request.user_id, event_name, properties)
You must implement similar logic in your server code for each event you want to track, adding the properties you care about.
Key points to inform your team: - There is no automatic collection of default events/properties server-side. - Developers must extract and send these properties manually with each event. - Refer to Mixpanel’s server-side best practices for more details and code examples.
In summary: You must manually implement the collection and sending of default events and properties when using server-side tracking with Mixpanel. This is a key difference from client-side SDKs, which handle this automatically for you.
kapa.ai is still learning and improving, please let me know how I did by reacting below.
ℹ️ Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.
