Skip to content

Instantly share code, notes, and snippets.

@ak--47
Last active August 4, 2025 14:18
Show Gist options
  • Select an option

  • Save ak--47/05d73181bf85d4b47317dee9d16aed4d to your computer and use it in GitHub Desktop.

Select an option

Save ak--47/05d73181bf85d4b47317dee9d16aed4d to your computer and use it in GitHub Desktop.
reload mixpanel data
# reload all EVENTS from one project to another
# environment variables
# CUSTOMIZE THESE πŸ‘‡
export START=2023-01-01
export END=2023-05-31
export SOURCE_SECRET=my-source-project-secret
export TARGET_SECRET=my-target-project-secret
# export β†’ import
npx --yes mixpanel-import --type export --start $START --end $END --secret $SOURCE_SECRET && npx --yes mixpanel-import ./mixpanel-exports/ --secret $TARGET_SECRET
##############################
# reload all USER PROFILES from one project to another
# environment variables
# CUSTOMIZE THESE πŸ‘‡
export SOURCE_SECRET=my-source-project-secret
export TARGET_SECRET=my-target-project-secret
export TARGET_TOKEN=my-target-project-token
# export β†’ import
npx --yes mixpanel-import --type profile-export --secret $SOURCE_SECRET && npx --yes mixpanel-import ./mixpanel-exports/ --type user --token $TARGET_TOKEN --secret $TARGET_SECRET --fixData --format json
@ak--47
Copy link
Copy Markdown
Author

ak--47 commented Jul 4, 2024

please note... if either your source OR your target projects are using EU residency, please pass the:

--region EU

flag to the corresponding project

@BasilMVarghese
Copy link
Copy Markdown

@ak--47 While trying the script (EU region), Events were migrated succesfully. But for user profile migration, final exporting fails. Attaching the error trace.

`... streamer of data... to mixpanel! (v2.7.049)
by AK (ak@mixpanel.com)

node:events:496
throw er; // Unhandled 'error' event
^

Error: Parser cannot parse input: expected a value
at Parser._processBuffer (/Users/basilmacpro/.npm/_npx/d93516675bc9874c/node_modules/stream-json/Parser.js:111:64)
at Parser._transformBuffer (/Users/basilmacpro/.npm/_npx/d93516675bc9874c/node_modules/stream-json/utils/Utf8Stream.js:24:10)
at Parser._transform (/Users/basilmacpro/.npm/_npx/d93516675bc9874c/node_modules/stream-json/utils/Utf8Stream.js:19:10)
at Transform._write (node:internal/streams/transform:171:8)
at writeOrBuffer (node:internal/streams/writable:572:12)
at _write (node:internal/streams/writable:501:10)
at Writable.write (node:internal/streams/writable:510:10)
at Chain._write (/Users/basilmacpro/.npm/_npx/d93516675bc9874c/node_modules/stream-chain/index.js:152:18)
at writeOrBuffer (node:internal/streams/writable:572:12)
at _write (node:internal/streams/writable:501:10)
Emitted 'error' event on Chain instance at:
at Chain.onerror (node:internal/streams/readable:1028:14)
at Chain.emit (node:events:518:28)
at emitErrorNT (node:internal/streams/destroy:169:8)
at emitErrorCloseNT (node:internal/streams/destroy:128:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Node.js v20.18.1`

@ak--47
Copy link
Copy Markdown
Author

ak--47 commented Apr 22, 2025

@BasilMVarghese did you ever get pas this?

@jblifestyles
Copy link
Copy Markdown

@ak--47 Is there a way to do this on selective events? E.g. we don't want to do this with warehouse events (as we can need to make an adjustment for identify handling and reimport anyway) ... We want to do this on the mixpanel specific events only like pageviews, experiment, etc.. (posted from standard GTM implementation), and we want to import their original raw event data, not the reshuffled data, etc.

How can we accomplish this?

FYI @aulgen

@ak--47
Copy link
Copy Markdown
Author

ak--47 commented Aug 4, 2025

@jblifestyles hey! the mixpanel-import package supports a whereClause option.

this passes mixpanel's "segmentation expressions" to the /export API under the where searchParam:

https://github.com/ak--47/mixpanel-import/blob/main/index.d.ts#L444

read more about segmentation expression here:
https://developer.mixpanel.com/reference/segmentation-expressions

example:

npx --yes mixpanel-import --type export --start $START --end $END --secret $SOURCE_SECRET --whereClause 
defined(properties["My Prop"])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment