You can write a one-off script to send your events to Mixpanel.
To do this, for every event in your database you would make a POST request that looks like this:
curl https://api.mixpanel.com/import \
-u YOUR_API_SECRET: \
-d data=eyJldmVudCI6ICIkc2lnbnVwIiwgInByb3BlcnRpZXMiOiB7ImRpc3RpbmN0X2lkIjogIjQ4MSIsICJ0aW1lIjogMTMyMTQ5OTM3MSwgInRva2VuIjogIjEzZmUzZGRjODZlYjZmOTBjNGVlN2QwZDQ3NTYzMTUwIn19 \
-d verbose=1
This request is very similar to our standard HTTP API. The data parameter is a Base64 encoded JSON array with the event you are importing ($signup) and the associated properties.
By decoding the Base64 data parameter from the above request, you can see the raw JSON:
{ "event": "$signup",
"properties": {"distinct_id": "481",
"time": 1321499371,
"token": "13fe3ddc86eb6f90c4ee7d0d47563150"}}
- Event: You can set this to any event, but $signup is particularly useful for retention analysis.
- Distinct_id: The user ID you have been sending to Mixpanel up to this point for that user. In general, this is the value you pass into the identify method.
- Time: A unix epoch style timestamp in UTC that tells Mixpanel when the event fired. This can be any time in the last 5 years. The above example, 1321499371, represents November 17th, 2011 at 3:09 AM GMT.
- Token: The token property is your Mixpanel project token, which you can find by clicking your name in the upper righthand corner of your Mixpanel project and selecting Settings from the dropdown. Don’t confuse your API Secret with your project token!
Batching Requests
Using the /import endpoint, you can also batch requests to Mixpanel instead of sending one event per request. The endpoint will accept up to 50 messages in a single batch.
You can read more about batching requests to Mixpanel in our HTTP API documentation.
Comments
Article is closed for comments.