Analytics (Flash)

Hello, I’m working on a Flash game and I want to know if there is a library for analytics (like google analytics, mochibot etc)

What is it for? Page views? Demographics? Downloads?

If it’s for page views, then you can use Google Analytics for developers, including demographics. Downloads also useful.

If it’s for a mechanic inside the game, now that’s a different question entirely. But because you have provided so little information, I really don’t know what you intend to do.

Well I want to know where is the game hosted, how many gameplays; how many clicks is receiving some buttons… and of course it should be compatible with OpenFL

That’s not normally something that can be done in Flash… you do have access to the openfl.external.ExternalInterface class which allows you to call JavaScript functions on the same page, but it requires the page to have that function in the first place.

Game websites such as Newgrounds already have that functionality, so I see no reason why you wouldn’t use their analytics. Also, I don’t see any reason why you would want a library to do analytics INSIDE of your game, that’s more something you would do on a website using JavaScript and some server-side code.

That makes no sense :stuck_out_tongue: Do you mean “how many clicks buttons receive”?

If you’re just targeting Flash then you shouldn’t have any trouble using any existing AS3 solutions.

For our game Velocity Wings we used the Newgrounds API to track total views, where it is hosted and some custom events. It also provided our advertising in the preloader and allowed us to post to a high score board on our games page on Newgrounds. They let you add unlockable achievements too!

The Newgrounds API is distributed as an SWC you can include in your project.
Stick this in your project.xml

<compilerflag name="-swf-lib" value="Assets/NewgroundsAPI.swc" if="flash" />

You can then just use it as normal. Easy, right?

// example stuff     
import com.newgrounds.components.FlashAd;
import com.newgrounds.API;
import com.newgrounds.APIEvent;

// add the flash advertisement to the stage 
private function onApiConnected(e:APIEvent):Void {
    if (e.success == true) {
        ad = new FlashAd();

        ad.x = 100;
        ad.y = 100;

// somewhere in the in-game code 
// submit the score to Newgrounds here 
if (API.connected == true) {
    API.postScore("Total Rings", score);

Of course you don’t have to use their solution if you can find something else you like, if they distribute an SWC then this will still apply :slight_smile:

Good luck!

I think this will work for Google Analytics:

Thank you! I followed @bumblebirds advice and now I have Google Analytics For Flash (analytics.swc) working on my project