Does Mixpanel automatically maintain and track the same session (distinctID) across different domains (e.g., landing page and other pages)?
When accessing a UTM-parameterized URL in a non-logged-in state, and then redirecting to another domain after OAuth login, the UTM parameters seem to be lost. What is the best practice to retain UTM parameters post-login? Is appending all searchParams to the redirection URL the optimal approach?
Hi jtw, 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
To answer your questions about Mixpanel:1. Mixpanel does not automatically maintain the same session (distinct_id) across different domains. By default, Mixpanel cookies work across subdomains of the same domain, but not across entirely different domains. For hosted subdomains, you can disable cross-subdomain cookies by setting the cross_subdomain_cookie
configuration option to false
. Mixpanel Cookie provides more details on this:"By default, Mixpanel cookie works across subdomain, keeping Mixpanel's Distinct ID and Super Properties consistent across your sub-domains. For hosted subdomains (see complete list of affected domains) that don't allow cross-subdomain cookies, disable cross-subdomain cookie by setting the cross_subdomain_cookie configuration option to false."2. Regarding UTM parameters across domains after login, you're correct that these parameters can be lost when redirecting to another domain. The best practice to retain UTM parameters post-login involves a few steps:a) Capture the UTM parameters on the initial landing page.
b) Store these parameters, either in your backend or as super properties in Mixpanel.
c) After login and redirection, reapply these stored UTM parameters to the user's profile or subsequent events.Appending all searchParams to the redirection URL is one approach, but it may not be optimal for all scenarios, especially if you have sensitive information in the URL.A more robust approach is to use Mixpanel's super properties feature to persist UTM parameters. The Last-Touch UTM tracking documentation provides a code snippet that you can use to automatically parse UTM tags from the current URL and register them as super properties:LBKSfunction campaignParams() { var campaign_keywords = 'utm_source utm_medium utm_campaign utm_content utm_term'.split(' ') , kw = '' , last_params = {} , first_params = {};LBKS var index;LBKS for (index = 0; index < campaign_keywords.length; ++index) { kw = getQueryParam(document.URL, campaign_keywords[index]); if (kw.length) { last_params[campaign_keywords[index] + ' [last touch]'] = kw; } }LBKS mixpanel.people.set(last_params); mixpanel.register(last_params); }LBKScampaignParams();LBKS
This approach ensures that UTM parameters are captured and persisted even when users navigate across different domains or log in. You can then access these parameters in subsequent events or user profiles.Remember to implement this solution in compliance with your privacy policies and user consent 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! đ
Based on the information provided in the knowledge sources, Mixpanel cookies are not automatically preserved across different domains. The behavior you're describing, where the Mixpanel cookie containing distinct_id
, $device_id
, and $user_id
is being preserved across three different domains, is not the default behavior of Mixpanel.According to the Mixpanel Cookie documentation:"By default, Mixpanel cookie works across subdomain, keeping Mixpanel's Distinct ID and Super Properties consistent across your sub-domains. For hosted subdomains (see complete list of affected domains) that don't allow cross-subdomain cookies, disable cross-subdomain cookie by setting the cross_subdomain_cookie configuration option to false."This indicates that Mixpanel cookies are designed to work across subdomains of the same domain, but not across entirely different domains.Given that you're observing this behavior across three different domains, there could be a few potential causes:1. Custom Implementation: Your development team might have implemented a custom solution to pass these identifiers across domains. This could involve manually passing the identifiers in URL parameters or using some form of server-side session management.2. Third-party Cookie Syncing: There might be a third-party service or a custom solution in place that's syncing cookies across domains.3. Single Sign-On (SSO) System: If you're using an SSO system across these domains, it might be preserving and passing along these identifiers.4. Misconfiguration: There could be a misconfiguration in your Mixpanel setup or in your domain settings that's causing this unexpected behavior.5. Browser Extension or Plugin: In some cases, browser extensions or plugins might interfere with normal cookie behavior.To determine the exact cause, you would need to:1. Review your Mixpanel implementation across all three domains.
2. Check for any custom code that might be handling these identifiers.
3. Inspect the network requests and cookies on each domain to see how these values are being set and transmitted.
4. Consult with your development team to understand if this behavior is intentional and how it's being achieved.Remember, preserving user identities across different domains can have privacy implications, so it's important to ensure that this behavior aligns with your privacy policies and user consent 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! đ
Based on the information provided in the knowledge sources, there isn't explicit documentation about Mixpanel cookies being named with the project token value or about this enabling cross-domain cookie sharing. However, I can provide some relevant information about Mixpanel's cookie behavior and project tokens.According to the Mixpanel Cookie documentation:"By default, Mixpanel cookie works across subdomain, keeping Mixpanel's Distinct ID and Super Properties consistent across your sub-domains."This suggests that Mixpanel cookies are not designed to work across different domains by default, only across subdomains of the same domain.Regarding project tokens, the Project Token documentation states:"Every Mixpanel project has a unique alphanumerical token for collecting data. A project's token is not a secret value. In front-end implementation, such as our javascript library, this token will be available to anyone visiting your page."It's important to note that the project token is used for identification, not authorization:"With that in mind, it is important to note that a project's token is not a form of authorization. It is an identification sent along with each piece of data you send to your project."Given this information, the fact that you're seeing cookies named with the Mixpanel token value across different domains is interesting, but it's not a standard Mixpanel feature. The project token being the same across different domains doesn't inherently mean that Mixpanel sessions or cookies should be maintained across these domains.If you're experiencing this behavior, it could be due to a custom implementation or configuration. To understand why this is happening and whether it's intentional, you should:1. Review your Mixpanel implementation across the different domains. 2. Check for any custom code that might be handling cookie creation or sharing. 3. Consult with your development team to understand if this behavior is intentional and how it's being achieved.Remember, sharing user identifiers across different domains can have privacy implications, so it's crucial to ensure that this behavior aligns with your privacy policies and user consent 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! đ
Based on the information provided in the knowledge sources and our previous conversation, using the same Mixpanel token across multiple domains could indeed be related to the behavior you're observing, but it's not the standard behavior Mixpanel intends.According to the Project Token documentation:"Every Mixpanel project has a unique alphanumerical token for collecting data. A project's token is not a secret value. In front-end implementation, such as our javascript library, this token will be available to anyone visiting your page."However, the documentation also states:"With that in mind, it is important to note that a project's token is not a form of authorization. It is an identification sent along with each piece of data you send to your project."This means that while using the same token across multiple domains will send data to the same Mixpanel project, it shouldn't inherently cause cookies or sessions to be shared across these domains.The Mixpanel Cookie documentation indicates that by default, Mixpanel cookies only work across subdomains of the same domain, not across entirely different domains.Given that you're using the same token across multiple domains and observing shared cookies, it's possible that:1. There's a custom implementation in place that's using the token to name and share cookies across domains. 2. The Mixpanel library is being initialized in a non-standard way that's causing this behavior.To understand and potentially resolve this situation:1. Review your Mixpanel implementation across all domains. 2. Check for any custom code that might be handling cookie creation or sharing. 3. Consider using separate tokens for each domain if you want to keep the data separate. 4. If you intend to track users across domains, look into Mixpanel's cross-domain tracking best practices, which typically involve passing identifiers explicitly rather than relying on shared cookies.Remember, sharing user identifiers across different domains can have privacy implications, so ensure that your implementation aligns with your privacy policies and user consent 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! đ
Based on the information provided in the knowledge sources, there is no explicit indication that using the same token with mixpanel.init()
across different domains automatically maintains the session. According to the Mixpanel Cookie documentation:"By default, Mixpanel cookie works across subdomain, keeping Mixpanel's Distinct ID and Super Properties consistent across your sub-domains."This suggests that Mixpanel's default behavior is to maintain sessions across subdomains of the same domain, but not across entirely different domains, even when using the same token.The Project Token documentation states:"Every Mixpanel project has a unique alphanumerical token for collecting data. A project's token is not a secret value. In front-end implementation, such as our javascript library, this token will be available to anyone visiting your page."It also mentions:"With that in mind, it is important to note that a project's token is not a form of authorization. It is an identification sent along with each piece of data you send to your project."This indicates that the token is primarily used for identifying which project the data should be sent to, not for maintaining sessions across domains.If you're observing that sessions are being maintained across different domains when using the same token, it's likely due to a custom implementation or configuration rather than Mixpanel's standard behavior. To maintain sessions across different domains, you would typically need to implement a custom solution, such as passing identifiers explicitly between domains or using a server-side approach to track users across domains.Remember, if you are implementing any cross-domain tracking, it's crucial to ensure that it aligns with your privacy policies and user consent 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.