Uncategorized

Tapping into advanced data types

Most Mixpanel users are used to treating properties as strings of text, but
some data is more suitable to be treated as a number, or other data type.

Numbers

Let’s say you were instrumenting a music sharing site, and you sent a property
with every “song played” event called “length” that was a “number” the length
of the song in seconds. If you send the property as an integer or decimal (122
or 3.45) Mixpanel will detect it as a number, and will build a histogram
showing what song lengths people typically listened to in the segmentation
report:

Code Sample:
mixpanel.track("Song Played", {"Length" : 122 });

Chart in Mixpanel:

In the above case, 60 – 90 second movies were clearly the favorite! You can
also build segments with greater than and less than operators on numeric data.
This would let you examine the 60-90 second songs in more detail:

It looks like 77 and 78 second songs are the most popular within this segment.

Sometimes a histogram isn’t enough though – you just want an average. If your
data is a number, and you’ve set at least one filter on it, you can have
Mixpanel perform the following mathematical calculations on it for a given
time frame:

  • Average
  • Sum
  • Minimum Value
  • Maximum Value

The average song length for songs between 60 and 90 long hovers around 75
seconds:

If you don’t want to put a filter around it and calculate the overall averages
or sums, just choose a filter that wouldn’t eliminate any results. In this
case “length is greater than 0” will do the trick. However, most of the time
you will want to filter to eliminate extremes that represent bad data that
will skew your averages.

If you are sending an event as a number but Mixpanel is not detecting it as a
number, you can type cast it by hovering your mouse over the property in the
segmentation report, moving it to the right, and selecting the “number”
variable type. This will actually work for any property type:

Dates

You can also send dates to Mixpanel. Let’s say you wanted to break down your
song plays only to videos that had been uploaded to your site in the past
week. If you send a property formatted like a date, Mixpanel will
automatically treat it as such, and let you build segments based on date
logic.

Code Sample:

mixpanel.track("Song Played", {"Date Added" : '2011-10-27'});

Segment Example:

The above example would limit your report to plays of new songs that were
added in the past month.

Mixpanel accepts a wide variety of date formats. If any of the following
appear in a property value, Mixpanel will treat that value as a date:

  • yyyy-mm-dd
  • dd-mm-yyyy
  • yyyy/mm/dd
  • dd/mm/yyyy
  • a three letter month like Jan,Feb,Dec etc
  • a three letter day like Mon,Tue,Wed, etc

You can also include a time after the date, so “yyyy-mm-dd HH:MM:SS.” If you
are including time, please use UTC time.

Lists

Often you might want to set a property with more than one value. Some examples
might be:

  • Products purchased in a “Order Placed” event
  • Multiple authors in an “Article Viewed” event
  • Different genre tags in a “Song Played” event.

If you send a JSON array as a property value, Mixpanel will know that it is a
list, and allow you to build segments that query for individual list items.

Code Sample:
mixpanel.track("Song Played", {"Mood Tags" : ['happy','exciting','romantic'] });

Segmentation Sample:

You can type in any item in the Segmentation report, and it will return the
number of times the event was sent with that item as a member of the list.

Feel free to ask follow-up questions in the comments. I’ll answer every single
one!

Get the latest from Mixpanel
This field is required.