Part 3 - Initialize the SDK

By Richard Davey on 24th November 2017   @photonstorm

4. Initialize the integration

Call this method to initialize using the game key and secret key for your game.

<!-- Traditional way -->
gameanalytics.GameAnalytics.initialize("[game key]", "[secret key]");

<!-- Command queue -->
GameAnalytics("initialize", "[game key]", "[secret key]");

Don’t have any keys yet?

Head over here and register your game at the GameAnalytics website. Below is a common example of the code placed in a script that lets it call main.js.

function onStart(){
    // ... other code from your project ...

    <!-- Traditional way -->
    gameanalytics.GameAnalytics.setEnabledInfoLog(true);
    gameanalytics.GameAnalytics.setEnabledVerboseLog(true);

    gameanalytics.GameAnalytics.configureBuild("0.10");

    gameanalytics.GameAnalytics.configureAvailableResourceCurrencies(["gems", "gold"]);
    gameanalytics.GameAnalytics.configureAvailableResourceItemTypes(["boost", "gold"]);
    gameanalytics.GameAnalytics.configureAvailableCustomDimensions01(["ninja", "samurai"]);
    gameanalytics.GameAnalytics.configureAvailableCustomDimensions02(["whale", "dolphin"]);
    gameanalytics.GameAnalytics.configureAvailableCustomDimensions03(["horde", "alliance"]);

    gameanalytics.GameAnalytics.initialize([game key]", "[secret key]);

    <!-- Command queue -->
    GameAnalytics("setEnabledInfoLog", true);
    GameAnalytics("setEnabledVerboseLog", true);

    GameAnalytics("configureBuild", "0.10");

    GameAnalytics("configureAvailableResourceCurrencies", ["gems", "gold"]);
    GameAnalytics("configureAvailableResourceItemTypes", ["boost", "gold"]);
    GameAnalytics("configureAvailableCustomDimensions01", ["ninja", "samurai"]);
    GameAnalytics("configureAvailableCustomDimensions02", ["whale", "dolphin"]);
    GameAnalytics("configureAvailableCustomDimensions03", ["horde", "alliance"]);

    GameAnalytics("initialize", [game key]", "[secret key]);
};

5. Build your game

You can find detailed documentation for analytics setup and event tracking in Phaser with this JS SDK setup guide from GameAnalytics.

You can also connect to the service using their Rest API.