Actionscript 3 API Integration

Support for the Actionscript 3 library will cease as of April 21st, 2018. If you have any questions about the deprecation of this library please contact our support team.

Installing the library

You can get the Mixpanel Actionscript 3 library by downloading the the latest mixpanel-as3-lib.swc archive from the mixpanel-a3 github.

To add the mixpanel-as3-lib.swc to your Flexbuilder project, create a directory named libs in the root directory of your application project and copy the mixpanel-as3-lib.swc file into that directory.

To use the Mixpanel Actionscript library from Flash, go to

File > Actionscript Settings... > Library Path

click the "Browse to SWC" button, and select the mixpanel-as3-lib.swc file.

Initializing the library

To use the Mixpanel library, construct an instance using of the Mixpanel class using your Mixpanel project token. You can find your token by clicking your name in the upper righthand corner of your Mixpanel project and selecting Settings from the dropdown.

private var mixpanel:Mixpanel = new Mixpanel("YOUR TOKEN");

Sending events

Once you've constructed an instance, you can track an event by calling Mixpanel.track with the event name and properties.

// Send a "Clicked Ad" event to Mixpanel
// with a property "Banner Color"
    'Clicked Ad',
    { 'Banner Color': 'Blue' }

Super properties

It's very common to have certain properties that you want to include with each event you send. Generally, these are things you know about the user rather than about a specific event - for example, the user's age, gender, source, or initial referrer.

To make things easier, you can register these properties as super properties. If you tell us just once that these properties are important, we will automatically include them with all events sent. Super properties are stored either in browser cookies or Flash local storage, and will persist between visits and invocations of your app.

To set super properties, call Mixpanel.register.

    'User Type': 'paid',
    'source': 'facebook'

The next time you track an event, the super properties you just set will be included as properties. If you call


after making the previous call to mixpanel.register, it is just like adding the properties directly:

mixpanel.track("signup", {
    'User Type': 'paid',
    'source': 'facebook'

Setting super properties once and only once

If you want to store a super property only once (often for things like initial referrer, ad campaign, or source), you can use Mixpanel.register_once. This function behaves like Mixpanel.register and has the same interface, but it doesn't override super properties you've already saved.

    ad_campaign: 'fb-01'

This means that it's safe to call Mixpanel.register_once with the same property on every page load, and it will only set it if the super property doesn't exist.

Managing user identity

The Mixpanel library will assign a default unique identifier (we call it "distinct_id") to each unique user who comes to your website. This distinct_id is saved as a cookie so that it will persist across sessions.

If you choose, you can assign your own user IDs. This is particularly userful if a user is using your app on multiple platforms (both web and mobile, for example). To assign your own distinct_ids, you can use Mixpanel.identify.

// Associate all future events sent from
// the library with the distinct_id 13793

In general, if you use Mixpanel.identify, you should call it as soon as the user logs in to your application. This will track all of their actual application usage to the correct user ID.

Calling Mixpanel.identify with a new ID will change the ID being sent with future events. If you change the ID in the middle of a funnel, the funnel will break - we won't be able to associate the old ID with the new.

Storing user profiles

In addition to events, you can store user profiles in Mixpanel's People Analytics product. Profiles are persistent sets of properties that describe a user - things like name, email address, and signup date. You can use profiles to explore and segment users by who they are, rather than what they did. You can also use profiles to send messages, such as emails, SMS, or push messages.

Before you send profile updates, you must call Mixpanel.identify. The Mixpanel library will not send updates with the automatically generated id, so you have to explicitly set your own. This ensures that you only have actual registered users saved in the system.

Setting profile properties

You can set properties on a user profile with Mixpanel.people_set.

// identify must be called before any
//  profile updates can be sent

    'Plan': 'Premium'

This will set a "Plan" property, with a value "Premium", on user 13793's profile. If there isn't a profile with distinct_id 13793 in Mixpanel already, a new profile will be created. If user 13793 already has a property named "Plan" in their profile, the old value will be overwritten with "Premium".

Incrementing numeric properties

You can use Mixpanel.people_increment to change the current value of numeric properties. This is useful when you want to keep a running tally of things, such as games played, messages sent, or points earned.

// If no number is passed, the default is to increment by 1
mixpanel.people_increment("games played");

// You can also pass a number to increment
// Here we increment the user's point count by 500.
mixpanel.people_increment("points earned", 500);

// Pass an object to increment multiple properties
    "dollars spent": 17,
    // Subtract by passing a negative value
    "credits remaining": -34

Tracking revenue

Mixpanel makes it easy to analyze the revenue you make from individual customers. By associating charges with user profiles, you can compare revenue across different customer segments and calculate things like lifetime value.

You can track a single transaction with Mixpanel.people_track_charge. This call will add transactions to the individual user profile, which will also be reflected in the Mixpanel Revenue report.

// Make sure identify has been called
// before making revenue updates

// Tracks $100 in revenue for user 13793

// Refund this user 50 dollars

// Tracks $25 in revenue for user 13793
// on the 2nd of january
    { '$time': '2012-01-02T00:00:00' }