Solved

Is it possible to export events list by users?

  • 21 October 2019
  • 1 reply
  • 167 views

Badge

I'm working on a third-party app to track the users by time and I need to export the events list like the below table, Is this possible?

userIdDateEvent
1130-01-2018view_page
2129-01-2018view_page
3329-01-2018view_page
3329-01-2018view_page
4329-01-2018view_page
5328-01-2018view_page
6329-01-2018view_page

icon

Best answer by monicaerdmann 25 October 2019, 20:31

Hi @Abdelhadi,

You can export your events via CSV format using Mixpanel's API Module. This should give you all the properties you shared, along with the users distinct ID to identify them. The only thing that might be different is the time from your example is the time - time will be in unix/epoch, which means you might need to convert some epoch times into the format you want.


To export your events, I have outlined some steps for you below 🙂


1. You will need a Python script that looks something like this:

from mixpanel_api import Mixpanel

if __name__ == '__main__':

api_secret = 'FILLTHISIN'
project_token = 'FILLTHISIN'

m = Mixpanel(api_secret,token=project_token, debug=True, pool_size=4)
m.export_events('events.csv',{'from_date':'2019-10-01','to_date':'2019-10-25'}, timezone_offset=-8, format='csv')

Tips:

A. You will need to fill out the section 'FILLTHISIN', between the quotes, with your API secret and Project Token from Mixpanel. To find these two things, you can take a look in your project settings. You will also need to put the dates you are looking for, note that your data history does correspond to the type of plan you have.

B. You can save this script on your preferred code editor. I use Visual Studio Code or Atom. When you save this file via your text editor, make sure your save it with .py at the end the file name. Example: dataexport.py

D. I set debug=True in the module initialization, so you can see if the script is working or failing. Also, if you are using behaviors in your query_params you must specify a timezone_offset. Your project timezone can be found in Project settings.

2. You will need to install the Mixpanel API module on your machine via the terminal, by running the following command:

pip install mixpanel-api

Tips:

A. How to pull up Terminal on Mac or Windows.

3. After installing the Mixpanel API module, you will need to run the python command along with the file you saved for the coding script via terminal. For example,python dataexport.py

Tips: make sure you run the python command in the same directory that your saved script file lives in. For example, if you saved your dataexport.py file inside of your Documents directory, you will need to run both pip install mixpanel-api and python dataexport.py commands in the directory of Documents.

4. If all goes well, you should have a new file pop up with a .csv ending in it.


I would test this out on a dummy project just to practice first. Hope this helps you out!


View original

1 reply

Userlevel 3
Badge

Hi @Abdelhadi,

You can export your events via CSV format using Mixpanel's API Module. This should give you all the properties you shared, along with the users distinct ID to identify them. The only thing that might be different is the time from your example is the time - time will be in unix/epoch, which means you might need to convert some epoch times into the format you want.


To export your events, I have outlined some steps for you below 🙂


1. You will need a Python script that looks something like this:

from mixpanel_api import Mixpanel

if __name__ == '__main__':

api_secret = 'FILLTHISIN'
project_token = 'FILLTHISIN'

m = Mixpanel(api_secret,token=project_token, debug=True, pool_size=4)
m.export_events('events.csv',{'from_date':'2019-10-01','to_date':'2019-10-25'}, timezone_offset=-8, format='csv')

Tips:

A. You will need to fill out the section 'FILLTHISIN', between the quotes, with your API secret and Project Token from Mixpanel. To find these two things, you can take a look in your project settings. You will also need to put the dates you are looking for, note that your data history does correspond to the type of plan you have.

B. You can save this script on your preferred code editor. I use Visual Studio Code or Atom. When you save this file via your text editor, make sure your save it with .py at the end the file name. Example: dataexport.py

D. I set debug=True in the module initialization, so you can see if the script is working or failing. Also, if you are using behaviors in your query_params you must specify a timezone_offset. Your project timezone can be found in Project settings.

2. You will need to install the Mixpanel API module on your machine via the terminal, by running the following command:

pip install mixpanel-api

Tips:

A. How to pull up Terminal on Mac or Windows.

3. After installing the Mixpanel API module, you will need to run the python command along with the file you saved for the coding script via terminal. For example,python dataexport.py

Tips: make sure you run the python command in the same directory that your saved script file lives in. For example, if you saved your dataexport.py file inside of your Documents directory, you will need to run both pip install mixpanel-api and python dataexport.py commands in the directory of Documents.

4. If all goes well, you should have a new file pop up with a .csv ending in it.


I would test this out on a dummy project just to practice first. Hope this helps you out!


Reply