Skip to content

Instantly share code, notes, and snippets.

@boxmein
Last active May 28, 2018 19:52
Show Gist options
  • Save boxmein/e2679291f4b5e60e7e3d4b0f3d2c0809 to your computer and use it in GitHub Desktop.
Save boxmein/e2679291f4b5e60e7e3d4b0f3d2c0809 to your computer and use it in GitHub Desktop.
Merge data from one mixpanel project into another
#!/bin/bash
# This shell script can automatically merge two Mixpanel projects.
# Takes events from project A and puts it in project B.
# Depends on:
# curl
# jq
# base64
# Where to take data from?
A_API_SECRET='Take the project API secret to pull data FROM.'
# Date range (must be < 60 days)
START_DATE='2018-05-01'
END_DATE='2018-05-28'
# Where to put data?
B_PROJECT_TOKEN='Take the project token from the project where you want the data to be pushed to.'
B_API_SECRET='Take the API Secret from the project where you want the data to be pushed to.'
# Export
echo "Exporting"
curl https://data.mixpanel.com/api/2.0/export/ -u "$A_API_SECRET": -d "from_date=$START_DATE&to_date=$END_DATE" > mxpnl_export.json
# Import
echo "Importing"
while read x;
do
evt_with_token=$(echo $x | jq -rc '. * { "properties": { "token": "'$B_PROJECT_TOKEN'" } }')
base64_event=$(echo $evt_with_token | base64 -w0);
curl https://api.mixpanel.com/import -u "$B_API_SECRET:" -d "data=$base64_event" -d 'verbose=1';
done < mxpnl_export.json
echo "Done!"
echo "New file: mxpnl_export.json. Contains the exported data. Remove if it is not needed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment