When I use set_config track_pageview the url tracking in a SPA isn't working mixpanel.set_config({ track_pageview: 'full-url', });
Hi Gastón D., 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
Based on the information provided in the knowledge sources, it appears that using set_config
with track_pageview
might not be the correct approach for tracking page views in a Single Page Application (SPA). Let me explain the correct way to set up page view tracking for SPAs using Mixpanel: According to the Mixpanel JavaScript SDK documentation, for tracking dynamic page views in single-page applications, you should set the track_pageview
option when initializing the Mixpanel object, not with set_config
. Here's the correct way to do it: LBKSmixpanel.init('YOUR_PROJECT_TOKEN', { track_pageview: "full-url" });LBKS
This configuration will track any URL changes in the path, query string, or hash for your SPA.If you've already initialized Mixpanel and want to enable page view tracking later, you should reinitialize Mixpanel with the correct configuration rather than using set_config
.It's important to note that the default track_pageview
setting does not auto-track page views in single-page applications, which is why you need to specify the tracking method explicitly.If you're still experiencing issues after making this change, you may want to enable debug mode to confirm that requests are being sent to Mixpanel correctly. You can do this by adding debug: true
to your initialization options: LBKSmixpanel.init('YOUR_PROJECT_TOKEN', { track_pageview: "full-url", debug: true });LBKS
This will allow you to see Mixpanel API calls in your browser's developer console, which can help you troubleshoot any remaining issues.
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! 📚
I understand that you want to track page views after a certain property is ready, rather than initializing Mixpanel with page view tracking enabled from the start. In this case, you're right to look for an alternative approach. Let me suggest a solution based on the Mixpanel documentation.According to the Mixpanel JavaScript SDK documentation, you can manually track page views using the track_pageview()
method. This allows you to control when the page view is tracked, which is perfect for your use case where you want to wait for a property to be ready.Here's how you can implement this: 1. First, initialize Mixpanel without enabling automatic page view tracking: LBKSmixpanel.init('YOUR_PROJECT_TOKEN');LBKS
2. Then, after your property is ready, you can manually track the page view: LBKS// Assuming your property is ready mixpanel.track_pageview();LBKS
This method will send a default page view event with the name $mp_web_page_view
. It includes event properties such as page title, URL components, and marketing parameters.If you want to add additional properties to your page view event, you can do so by passing an object to the track_pageview()
method: LBKSmixpanel.track_pageview({ "custom_property": "value" });LBKS
This approach gives you the flexibility to track page views exactly when you want, after your property is ready, while still using Mixpanel's built-in page view tracking functionality.Remember to call track_pageview()
every time the page changes in your SPA, or whenever you want to record a page view based on your application's logic.
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.