kapa.ai i With custom properties, I’m trying to extract utm_campaign from the first page visited by a user. How do I do that?
To extract the utm_campaign from the first page a user visits, you should use the initial_utm_campaign property. Mixpanel’s JavaScript SDK automatically captures UTM parameters from the landing page URL and stores the first-seen values as user profile properties prefixed with initial_ (e.g., initial_utm_campaign). This represents the first-touch attribution and persists on the user profile for future reference. No extra configuration is needed if you’re using the default SDK settings and identifying users normally — the property will be set automatically for you see details.If you want to use this value in a custom property or report, simply reference initial_utm_campaign. For example, you can break down conversions or other events by this property to analyze which campaigns are driving first-time visits and conversions see more.If you are using a server-side implementation, you must manually extract the UTM parameters from the request and set them as event or user properties see server-side best practices.Summary: - Use initial_utm_campaign for first-touch campaign attribution. - It is set automatically by the JavaScript SDK for client-side tracking. - For server-side, you must extract and set it manually.Learn more in the Mixpanel documentation on UTM tracking and attribution.
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! 📚
If you are using an earlier version of the Mixpanel SDK that does not automatically capture initial_utm_campaign, you will need to manually extract the utm_campaign parameter from the URL on the user's first page visit and store it as a custom user property.Here’s a general approach based on the knowledge sources: 1. Extract utm_campaign from the URL On the first page load, use JavaScript to parse the URL and get the value of utm_campaign.2. Store it as a user property Use Mixpanel’s identify and people.set (or mixpanel.get_distinct_id() and mixpanel.people.set() in older SDKs) to set this value as a custom property, such as initial_utm_campaign, only if it hasn’t been set before.Example (pseudocode):Note: You must ensure this logic only runs on the user's first visit, as subsequent visits should not overwrite the initial value. Using localStorage or a cookie is a common approach.This approach is consistent with Mixpanel’s recommendation to manually set UTM properties if you are not using the latest SDK or are tracking server-side see details see best practices.If you need to do this server-side, you would extract the UTM parameters from the request and set them as user properties in a similar "set once" fashion see example.
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! 📚
Let me check the knowledge base for you again. One moment! 📚
To manually extract utm_campaign from the first page visited and store it as a custom property using an earlier Mixpanel SDK, you need to: 1. Parse the utm_campaign parameter from the URL on the first page load.
2. Set it as a user profile property using people.set_once (or equivalent), so it only records the first value seen.The knowledge sources confirm that if you are not using the latest SDK, you must handle this process yourself — Mixpanel does not automatically set initial_utm_campaign for you in older SDKs. Here’s how you can do it: LBKS// Example: Extract utm_campaign from URL and set as a user property only once function getQueryParam(param) { var params = new URLSearchParams(window.location.search); return params.get(param); }LBKSvar utmCampaign = getQueryParam('utm_campaign'); if (utmCampaign) { mixpanel.people.set_once({ "initial_utm_campaign": utmCampaign }); }LBKS- This code checks for utm_campaign in the URL and sets it as a user property only if it does not already exist.
- The use of set_once ensures the property is only set the first time, which matches the first-touch attribution logic.You may want to add logic to ensure this only runs on the user's first visit (e.g., by checking a cookie or localStorage), as the SDK will not do this automatically for you in older versions see guidance.If you are tracking server-side, you must also extract UTM parameters from the request and set them as user properties manually see server-side attribution.> If you are not using the default SDK settings and identifying users normally, you must manually set these UTM properties see FAQ.Let me know if you need a server-side example or further clarification!
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.
To manually extract utm_campaign from the first page visited and store it as a custom property using an earlier Mixpanel JavaScript SDK, you need to: 1. Parse the utm_campaign parameter from the URL.
2. Set it as a user profile property using .people.set_once() so it only records the first value seen.Here’s how you can do this, based on the knowledge sources: LBKS// Extract utm_campaign from the URL function getQueryParam(param) { var params = new URLSearchParams(window.location.search); return params.get(param); }LBKSvar utmCampaign = getQueryParam('utm_campaign'); if (utmCampaign) { // Set as a user property only if it doesn't already exist mixpanel.people.set_once({ "initial_utm_campaign": utmCampaign }); }LBKS- The use of .people.set_once() ensures the property is only set the first time, matching first-touch attribution logic.
- You may want to add logic to ensure this only runs on the user's first visit (e.g., by checking a cookie or localStorage), as the SDK will not do this automatically for you in older versions.This approach is recommended if you are not using the latest SDK, as you must manually set these UTM properties yourself see FAQ see web attribution.If you need to do this server-side, you must also extract UTM parameters from the request and set them as user properties manually.
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.
