Question

Mixpanel Not Receiving Some Page Load Events From Segment

  • 17 June 2020
  • 3 replies
  • 744 views

Badge

I set up Segment to track page loads and specific events on my website with Mixpanel as one of my destinations. I’ve set up page load tracking with the code snippet suggested in the Segment docs (i am using react so this is in my index.js file and is loaded every time a page is loaded):

    <script>
      !function(){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","once","off","on"];analytics.factory=function(t){return function(){var e=Array.prototype.slice.call(arguments);e.unshift(t);analytics.push(e);return analytics}};for(var t=0;t<analytics.methods.length;t++){var e=analytics.methods[t];analytics[e]=analytics.factory(e)}analytics.load=function(t,e){var n=document.createElement("script");n.type="text/javascript";n.async=!0;n.src="https://cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(n,a);analytics._loadOptions=e};analytics.SNIPPET_VERSION="4.1.0";
      analytics.load("xxxxx");
      analytics.page();
      }}();
    </script>

 

My page load events are being received by Mixpanel but they don’t come through with a name property and therefore Mixpanel doesn’t know what page is being loaded. Can anyone suggest a way to dynamically include a name property in the event sent to Mixpanel for each page? Thank you!


3 replies

Badge

problem solved

How did you solve this problem?

Badge

Hey DesignNub, 

 

I hope this helps. We are working on a single page application in ReactJS and we imported the node package ‘history’, created a history object with createBrowserHistory( ) and then used the following to dynamically pass in the url in our index.js file:

 

history.listen((location, action) => {
     window.analytics.page(location.pathname);
});

 

Every time the URL changes, it sends a segment page event containing the location. 

 

We also added the following in the same file to capture instances where people are actually loading a page (when they first arrive at the site or if they refresh the page at any time): 

window.analytics.page();

 

Let me know if you need any further help and I’ll do my best.

Cheers,

Harley

Reply


Mixpanel