If you ever need help, please email us at support@mixpanel.com
Back to topics

ActionScript

Updated Feb. 1, 2012

How to track Flash events with Mixpanel

It's easy to send data to Mixpanel directly from your Flash application. We have a native Actionscript 3 library, which will let you send data to Mixpanel no matter where your code is embedded.

To get started, download or clone (git clone git://github.com/mixpanel/mixpanel-as3.git) the flash library and add it to your project. Then, it's really simple to import the lib and start tracking things.

// import the library - this will change based on where you put it
import com.mixpanel.Mixpanel;

// initialize with your project token
internal var mpmetrics:Mixpanel = new Mixpanel("YOUR TOKEN");

// track events with ease
private function sendPhoto():void {
    // Do stuff
    mpmetrics.track("Sent photo", {"type": "png"});
}

Usage

Tracking things in Actionscript works exactly the same as it does in Javascript. Here is some example code.

// Track a page load. Very simple.
mpmetrics.track("Page load");

// Track a user that plays a game. We include the genre and game title.
mpmetrics.track("Play game", {"genre": "action", "title": "Tomb Raider"});

// Register some properties to include with all events sent, so you don not have
// to include them every time.
mpmetrics.register({"user type": 4, "account age": 234});

// Register some properties to include with only funnel events
mpmetrics.register({"origin": "Google"}, "funnels");

// Register properties *only* if they have not been registered before
mpmetrics.register_once({"origin": "Google"});

// Identify a user for all future events
mpmetrics.identify("unique string");

For more examples, see the Javascript integration page.