Last Updated: February 25, 2016
· dayweek
0 x9j4kp5uetcspefta wikan1eqatpfntgcdbkanpbclliwt 1rdqolggqylyxhbyyzr6xnkfn5kn

Fixing wrong event names in Mixpanel

You had a bad day and you accidentaly started to track events with wrong name.

Yesterday you tracked your landing page with this
javascript mixpanel.track('Landing Page Visit');

Today you changed accidentaly the name of the event:
javascript mixpanel.track('Home Page Visit');

How can you rename Home Page Visit to Landing Page Visit?

I have two news for you:

The bad one: you cannot change mixpanel data once you pushed them

The good one: you can export the events with wrong name, manually rename it, and import with correct name.

Renaming the data

What you are doing is that you basically replay the already sent events, but with different name. The old events with Home Page Visit name will stay there but at least Landing Page Visit will be correct.

The code

This simple Ruby script uses import and export API of Mixpanel. I had to use two client libraries mixpanel_client and mixpanel. Please read the rest of the article before using it.
You should edit api_key, api_secret, old event name, new event name, token, from_date, to_date and add_zone

config = {api_key: 'XX', api_secret: 'YY'}
client =

data = client.request('export', {
  event:     ['Home Page Visit'],
  from_date: '2013-10-13',
  to_date: '2013-10-13'

def rename(data, old_name, new_name)
  data = do |row|
    # make sure we have only old_name events
    if row['event'] != old_name
      raise "The data contains another event name #{row['event']}"
    row['event'] = new_name

rename(data, 'Home Page Visit', 'Landing Page Visit')

@mixpanel =  'token', api_key: 'XX'

add_zone = 3600 * 7 # 7 hours

data.each.with_index do |row, i|
  puts "Importing row #{i} #{row['event']}"
  puts @mixpanel.import row['event'], row['properties'].merge('time' => (row['properties']['time'].to_i + add_zone).to_s)

Check time zones

Beware of time zones. You can set project time zone but it is not recommened to change Mixpanel time zone. Which means there is no timezone info in events in the past, they are stored as local times.


In my case I had US/Pacific time zone in my Mixpanel project settings. However the old events were in UTC time zone because when exported and printed as UTC, the times were equal to times in Mixpanel UI. You can take a look at Mixpanel export documentation but I think there is false sentence Timestamps are in project time but expressed as Unix time codes. No matter what project time zone was, the exported time stamps were the same - UTC. Which supported the fact that times are stored as local times, without time zone.

When I imported data with UTC to Mixpanel with US/Pacific time, it converted my time to the US/Pacific time before saving. Which resulted in 7 hours shift. This is not what I wanted.

Therefore I compensated the shift be adding 7 hours to my UTC time before importing. Since US/Pacific time was in -7 hours timezone the time which was saved was exactly what I imported.

Note that I could not change the US/Pacific time in project settings to UTC before import because new events which were being tracked would be shown with 7 hours shift with respect to the previous events.

To make it even more complicated, watch for daylight saving time -> standard (winter) time. In one country they shift time by 1 hour, but in other country they will shift time one week later. Mixpanel knows that so when some event data are imported before date X the other data imported after date X will be saved with 1 hour shift.

Try it on test account with same time zone

First run the code with different API key to make sure it works. Look at Formulas section in Mixpanel UI and compare numbers of old and new events and make sure the times align in hour intervals. e.g. both the old event and new event were tracked 11 times at 6PM. Now you can run it on the desired Mixpanel account.

Hide old event data

Of course the event data (Home Page Visit) will stay in mixpanel, but you hide the event in your settings.


Test and test. I'm not 100% sure how the Mixpanel time zones work so make sure it works on your test account. Playing with raw data in Mixpanel can be a little bit dangerous especially the time zones since there is no way back.

Say Thanks

1 Response
Add your response

0 mlnj 0i3xtkhcp6k2c9m gmm0ntlrpbk2bcc gzlhvqzxc8rgiqayj2xao vznny76nijv6 hvfe

Thanks Very helpful!

over 1 year ago ·