Sticky MPKnowledgeDrop

Use Node via Terminal to confirm data is sent to Mixpanel

  • 11 March 2020
  • 0 replies
  • 215 views
Use Node via Terminal to confirm data is sent to Mixpanel
Userlevel 6
Badge +4

Every week, we will release tips to help you get the most out of Mixpanel. Want to see more? Click here to see other #mpknowledgedrop articles.

 

Sometimes running a quick test can help us verify that everything is working as expected. With a testing mindset, I want to share a quick tutorial on how to confirm that events and user profiles are being sent to Mixpanel through node via your terminal.

 

Before we get started, here are some prerequisites you will need to go through this tutorial. 

 

Prerequisite:  Node installed, npm (this comes with node installation), Terminal (How to open Terminal on Mac or Windows.)

Systems I am using: MacOS Mojave, mac computer terminal

Reference Guide: Mixpanel-node 

 

Now let's get to the test!

 

  1. Open your terminal. Note, I will be running this in my Documents directory (folder), but you can run in any directory you would like. 
    5HFpSFrs_dQXc0mw0de3XE8CZDkgcShSKDhh4JtUiDV3wFek6Ks4zXnrfpFBItpRQCPPc9LW1-hnTfiu_lkslMoTi9c0AX63ACi_7zUSEfZ_AQvMxJX38lx7UME1Hwub9PLVA9uY

  2. Install Mixpanel Node.js npm library by running npm install mixpanel  on your terminal. OPBLoOWJD2YkqzJBcyOvqNL36yL_vIhASWGPGxd35ov4uqUaCyoMN43Xkqi5efFQP38EpnUIEi6csHqh46VT1lBf-18bgihByHSX2WJXHIl_b3idG920UILEFeAI1WfP6z9m-Jqq

  3. Once the library is installed, you will run node command on your terminal. This will allow the code to run locally on the terminal. 6u2mK8dPdQ-V7zi32CQrHWbMjzAnwQNuAJAGvFv1TV9jh00ocza3wpY0o-xwgUQkNzp2bhjn-Zk3F3Y_HiKIqR0_TFGLVFHKr9fchjSJUYIPwSS0FWpDUVqsWt1YYg9OkbVvoTrc

  4. Now that our library is loaded and we have run node, we will need to set the following variables below one at a time. If you try to insert them all at once, it will give you an error.
    Something to watch out for is to make sure you insert the correct project token - here is a help article on how to find your
    project token

    • // grab the Mixpanel factory
      var Mixpanel = require('mixpanel');

       

      // create an instance of the mixpanel client
      var mixpanel = Mixpanel.init('YOUR PROJECT TOKEN HERE');

       

      // initialize mixpanel client configured to communicate over https
      var mixpanel = Mixpanel.init('YOUR PROJECT TOKEN HERE', {
      protocol: 'https'
      });



      Below is a screenshot of what the end result should look like on your terminal - I have blocked my project token out in white :)gnPjcAjR97nUp-wMC0IQxv7rRPZ_mvpVhBZ7qHTTHI7Zm4qYlxsqZ9M0IjbCICr474ticG6jU71nNIc9O55KyZ_5u8t65ZFUX6sDTlfvWPwso4HCWOw2pcJ1x3CE2C7INUL8dIHKNote: You have to set all variable on the same terminal session that you set the Mixpanel Library. If you close the terminal and re-open it, try to run node, and then run the rest of variable Mixpanel steps it will not work. You will need to repeat step 2 & 3.

  5. Now we are ready to send in our first event and user profile.
    • To send an event, we need to call mixpanel.track(). Example below
      mixpanel.track('test event', {

          distinct_id: '123',

          $name: 'Stephanie',

          $email: 'stephanie@testteremail.com',

      });

      If you are trying to import events older than 5 days, we recommend you send them to Mixpanel through our endpoint. More instructions on importing old events here

      To send a user profile, we need to call people.set(). Example below

      mixpanel.people.set('123', {

          $name: 'Stephanie Cueto',

          $created: (new Date('jan 1 2013')).toISOString(),

          plan: 'premium',

          games_played: 1,

          points: 0

      });

      Below is a picture of how this would look like on your terminal. R5eU51J2MYYF-q0eSp-7vNZt3Ciwteayu6L7_LF21RmxSrXnxYlyupuktsc7VLultBXjTXuudbXKgU-99DzXoxVIQJTOHkLhZqWbIX9EdfOEwp-YekX6bp7zKkdBL4lqRp_kAuH5

  6. At this point, we can go into our Mixpanel project to see the event and user profile.

    • To check if the event came in, we can look at our Live View Report. Below is a screenshot of how the event displays in live view. o0sNbbmtx2aN3HbyPklcKOCgIBU889rJSiaQVf16mlwyhbh3V4CMB3dPlDMQ0025OYfW7JIDxkg45LyJagvwd28B9qpE_M-DsOW5y076r2cvys4FEaXSV-ubXogBLp6QOteBN_xy

      To check if your user profile has also been sent in, we can use the explore report to see this. Below is a screenshot of my tester profile. 

    • TD3VWUyF6lLZDnz4_JxeSzyI_z81WAJXsccAu4NW3aXArKSyo30_tWWy0t3DxdP7fxRNNbvIoKETf9r5mz_Cw79VGBypuYsnwJTLoNqEqNWm304X9mFWN2DAebVeiuYAB68Gp47K5RH7vmt9n7xTGbO0d_NzgJ-GiUzzAP7RHAxIX9lngwhUNEV7tLj9PjqgyWMJzwXCetJvwtW-AbwylWGRnA6K0p05Tbhz07Ej3-5E61cTxQm8VbZ-lRhD-Qyo9RFFyKGvm8i0R0L2

    • One thing I noticed while sending user profiles to Mixpanel is that it will take a couple of seconds for it show up on the Explore report. So do not fear if it does not show up right away - make sure to check in on it!

  7. Congrats! You can now be confident that everything is working.

Thanks for walking through with me on how to send events and user profiles to Mixpanel using Node via terminal. Have any tips and tricks you want to share? Did this work for you? Did you get stuck? Comment below! 


0 replies

Be the first to reply!

Reply