Mixpanel Community Icon

Understanding init vs. track_pageview for Custom Event Properties

·
·

What’s the difference between using init function to track pageview and using .track_pageview() function? Which is the better solution if we want to send custom event property under the page view event?

  • Avatar of kapa.ai
    kapa.ai
    APP
    ·
    ·

    Hi Sharon L., 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

  • Avatar of kapa.ai
    kapa.ai
    APP
    ·
    ·

    To answer your question about tracking page views in Mixpanel, let's look at the two methods you mentioned: 1. Using the init function with track_pageview option: LBKSmixpanel.init('YOUR_TOKEN', {track_pageview: true});LBKS2. Using the track_pageview() function: LBKSmixpanel.track_pageview();LBKSThe main differences are: 1. The init method with track_pageview: true will automatically track page views on every page load. This is a set-it-and-forget-it approach.2. The track_pageview() function allows you to manually trigger page view tracking when you want, giving you more control over when the event is sent.As for sending custom event properties with page views, the track_pageview() function is the better solution. Here's why: According to the Mixpanel JavaScript SDK documentation, you can add custom properties to the page view event using the track_pageview() function like this: LBKSmixpanel.track_pageview({ "page": "Pricing" });LBKSThis allows you to include any custom properties you want with the page view event.On the other hand, the init method with track_pageview: true doesn't provide a straightforward way to add custom properties to every page view event.So, if you want to send custom event properties with your page view events, using the track_pageview() function is the recommended approach as it gives you more flexibility and control over the data you send with each page view event.

    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.

  • Avatar of Sharon L.
    Sharon L.
    ·
    ·

    kapa.ai If we use the track_pageview() method, is the event name also $mp_web_page_view?

  • Avatar of kapa.ai
    kapa.ai
    APP
    ·
    ·

    Let me check the knowledge base for you again. One moment! 📚

  • Avatar of kapa.ai
    kapa.ai
    APP
    ·
    ·

    Yes, when you use the track_pageview() method, the event name is indeed $mp_web_page_view. This is consistent with the default page view event tracked by Mixpanel.According to the Mixpanel JavaScript SDK documentation: "The default page view event has the event name ($mp_web_page_view), and includes the event properties page title (current_page_title), URL components (current_domain, current_url_path, current_url_protocol, current_url_search), and marketing parameters."This means that whether you use the automatic page view tracking with track_pageview: true in the init function or manually call track_pageview(), the event name will be $mp_web_page_view. The advantage of using track_pageview() is that you can add custom properties to this event, as mentioned in the previous answer.For example: LBKSmixpanel.track_pageview({ "page": "Pricing" });LBKSThis will send a $mp_web_page_view event with the additional custom property "page" set to "Pricing", along with the default page view properties.

    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.