Mixpanel Community Icon

Calculating Product Page Views Before Purchase in Mixpanel Analysis

·
·

How can I accurately calculate and compare the average number of product page views for users who eventually make a purchase versus those who do not, considering only events that occurred before the purchase event? I want to ensure that any product page views happening after a user completes a purchase are excluded from the calculation. Is there a way to accomplish this using Mixpanel’s standard reports or JQL

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

    To accurately calculate and compare the average number of product page views for users who eventually make a purchase versus those who do not, while considering only events that occurred before the purchase event, you can use Mixpanel's JQL (JavaScript Query Language) feature. This approach allows for more complex custom queries that are not easily achievable through standard reports.Here's how you can accomplish this using JQL:1. First, navigate to the JQL interface in Mixpanel. As mentioned in the JQL documentation, JQL is in maintenance mode, but it's still available for complex queries like this one.2. You can use a JQL query similar to the following structure:LBKSfunction main() { return Events({ from_date: "2023-01-01", to_date: "2023-12-31" }) .groupBy(["distinct_id", "name"], mixpanel.reducer.null()) .groupBy("distinct_id") .map(function(user) { var hasPurchased = false; var pageViews = 0; for (var i = 0; i < user.value.length; i++) { if (user.value[i].key[1] === "purchase") { hasPurchased = true; break; } if (user.value[i].key[1] === "product_page_view") { pageViews++; } } return { distinct_id: user.key, hasPurchased: hasPurchased, pageViews: pageViews }; }) .groupBy("hasPurchased") .reduce(function(acc, user) { acc.totalUsers = (acc.totalUsers || 0) + 1; acc.totalPageViews = (acc.totalPageViews || 0) + user.pageViews; return acc; }) .map(function(result) { return { hasPurchased: result.key, averagePageViews: result.value.totalPageViews / result.value.totalUsers }; }); }LBKSThis query does the following: - Groups events by user and event name - For each user, counts product page views until a purchase event is encountered - Separates users into two groups: those who purchased and those who didn't - Calculates the average number of product page views for each groupNote that you'll need to adjust the date range and ensure that your event names match your actual implementation (e.g., "purchase" and "product_page_view").This approach ensures that only product page views occurring before a purchase are counted, addressing your requirement to exclude post-purchase page views from the calculation.Remember that JQL is a more advanced feature and requires some JavaScript knowledge. If you're not comfortable with JQL, you might need to consult with your data team or a Mixpanel expert to implement this query correctly.<https://docs.mixpanel.com/docs/reports/apps/jql|JQL: Create custom queries using Javascript code> provides more details on using JQL in Mixpanel, including the full API reference and more examples.

    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 Alex
    Alex
    ·
    ·

    kapa.ai I want to see it in a standard report

  • 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
    ·
    ·

    I understand you'd prefer to see this analysis in a standard Mixpanel report rather than using JQL. While the exact analysis we discussed earlier is complex and best suited for JQL, we can approximate it using some of Mixpanel's standard reports. Here's how you can approach this using Funnels and Insights:1. Use the Funnels report:You can create a funnel to compare users who view product pages and then make a purchase versus those who don't. Funnels: Measure conversions through a series of events explains how to set this up:- Set up a two-step funnel: "Product Page View" followed by "Purchase" - Use the "Conversion Over Time" view to see how many users progress from viewing products to purchasing - The drop-off will show you users who viewed products but didn't purchase2. Use the Insights report:You can create two separate queries in Insights to compare the average number of product page views for purchasers vs. non-purchasers.Insights: Visualize trends and compositions within your data details how to use different measurements:- Create a segment for users who have made a purchase - Create two queries: 1. Average number of "Product Page View" events for users who have purchased 2. Average number of "Product Page View" events for users who haven't purchased - Use the "Average per User" measurement for both queriesKeep in mind that this method won't perfectly exclude post-purchase page views, but it will give you a good approximation.3. Use Exclusion Steps in Funnels:As described in Exclusion Steps (Exclude users who did…), you can use exclusion steps to refine your funnel:- Create a funnel with "Product Page View" followed by "Purchase" - Add an exclusion step for "Purchase" between the two main steps - This will show you product page views that occurred before a purchase, excluding those that happened afterWhile these standard report methods won't be as precise as the JQL query we discussed earlier, they can provide valuable insights using Mixpanel's user-friendly interface. If you need the exact analysis we initially discussed, JQL remains the most accurate method.

    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.