Download and Installation
Unzip the downloaded .zip and include this in your project (the files are located in the dist folder):
GameAnalytics.js include local logging to the console and is 65Kb in size.
GameAnalytics.min.js is without logging and is 53Kb in size.
It is recommended to initially use GameAnalytics.js while implementing the needed tracking. This will make it easier to verify correct SDK instrumentation. When done it is possible to switch to GameAnalytics.min.js in production if it is needed to save the extra kilobytes.
If you use node packages you can also install the SDK via npm:
npm install gameanalytics
And use it like this:
var gameanalytics = require('gameanalytics'); gameanalytics .GameAnalytics.setEnabledInfoLog(true);
⚠️ NOTE: The SDK still expects to be run in a browser environment where the navigator object is defined
It is also possible to use the following snippet to asynchronously load GameAnalytics SDK when your website loads and still be able to configure, initialize and send events before the SDK is fully loaded (just like you can do with Google Analytics). The code should be added near the top of the tag and before any other script or CSS tags:
The above code does four main things:
- Initializes a global GameAnalytics function (called the GameAnalytics() command queue) that allows you to schedule commands to be run once the GameAnalytics.js library is loaded and ready to go.
- Adds a command to the GameAnalytics() command queue to enable info logging.
- Adds another command to the GameAnalytics() command queue to initialize the SDK (replace GAME_KEY and SECRET_KEY with your actual keys).
The alternative async GA snippet below adds support for preloading, which will provide a small performance boost on modern browsers, but can degrade to synchronous loading and execution on IE 9 and older mobile browsers that do not recognize the async script attribute. Only use this tracking snippet if your visitors primarily use modern browsers to access your site.