Setup
The GameAnalytics C# SDK code is open-source and can be built to:
- Mono / .Net 4.5
- Universal Windows Platform (UWP)
- Universal Windows 8.1 (Windows 8.1 and Windows Phone 8.1)
Check out our Github Repository to download the SDK.
Requirements
Mono / .Net 4.5
Supported platforms:
- Windows
- Mac OS X
- Linux
Installation
Using Nuget
Add GameAnalytics.Mono.SDK
package from Nuget package manager
Nothing further needs to be done
Manual installation to local Nuget locally
Open GA-SDK-MONO.sln
and compile the GA_SDK_MONO
project
Create a Nuget package: nuget pack GA_SDK_MONO/GA_SDK_MONO.nuspec
Copy the resulting GameAnalytics.Mono.SDK.[VERSION].nupkg
(where [VERSION] is the version specified in the .nuspec file) into for example C:Nuget.Local
(the name and location of the folder is up to you)
Add C:Nuget.Local
(or whatever you called the folder) to the Nuget package sources (and disable Official Nuget source)
Add GameAnalytics.Mono.SDK package from Nuget package manager
.Net Core
Using Nuget (.Net Core)
Add GameAnalytics.Net.Core.SDK
package from Nuget package manager
Nothing further needs to be done
UWP
Dependencies
You will need SQLite
for Universal Windows Platform.
Install this through Tools -> Extensions and Updates… -> Online
and search for SQLite
for Universal Windows Platform.
Using Nuget (UWP)
Add GameAnalytics.UWP.SDK package from Nuget package manager Make sure you have installed the following Extension SDKs and added references to them in your project:
SQLite
for Universal Windows Platform (>= 3.15.0)Visual C++ 2015 Runtime
for Universal Windows Platform Apps (>= 14.0)
Manual installation
Open GA-SDK-UWP.sln
and compile the GA_SDK_UWP
project
Create a Nuget package: nuget pack GA_SDK_UWP/GA_SDK_UWP.nuspec
Copy the resulting GameAnalytics.UWP.SDK.[VERSION].nupkg
(where [VERSION] is the version specified in the .nuspec file) into for example C:Nuget.Local
(the name and location of the folder is up to you)
Add C:Nuget.Local
(or whatever you called the folder) to the Nuget package sources (and disable Official Nuget source)
Add GameAnalytics.UWP.SDK
package from Nuget package manager
Universal Windows 8
Dependencies (Windows 8)
SQLite
for Windows Runtime (Installed throughTools -> Extensions and Updates… -> Online
(Search for SQLite for Windows Runtime)SQLite
for Windows Phone (Installed through Tools -> Extensions and Updates… -> Online -> Search for SQLite for Windows Phone)SQLite
for Windows Phone 8.1 (Installed through Tools -> Extensions and Updates… -> Online -> Search for SQLite for Windows Phone 8.1)
-
Using Nuget
Add GameAnalytics.WSA.SDK package from Nuget package manager. Nothing further needs to be done
-
Manual installation
Open
GA-SDK-WSA.sln
and compile theGA-SDK-WSA
project Create a Nuget package:nuget pack GA-SDK-WSA/GA-SDK-WSA
-
Using nuspec
- Copy the resulting GameAnalytics.WSA.SDK.[VERSION].nupkg (where [VERSION] is the version specified in the
.nuspec
file) into for exampleC:Nuget.Local
(the name and location of the folder is up to you) - Add
C:Nuget.Local
(or whatever you called the folder) to the Nuget package sources (and disable Official Nuget source) - Add
GameAnalytics.WSA.SDK
package from Nuget package manager
- Copy the resulting GameAnalytics.WSA.SDK.[VERSION].nupkg (where [VERSION] is the version specified in the
Initialize the SDK
Now we should be ready for adding code to activate the SDK! There are 3 phases the SDK will go through.
- configuration
- initialization
adding events or changing dimensions
Configuration calls configure settings for the SDK and some will not be able to be altered after initialize has been called.
The initialize
call will start the SDK and activate the first session.
The configuration and initialization steps should be called at the beginning of the game for example inside the GameInit method.
Once step 1 & 2 is done you can add events at different parts of the game code where some relevant action is happening.
Remember to import the GameAnalytics package whenever you need to call the SDK.
using GameAnalyticsSDK.Net;
Configuration
The configuration phase happens before initialization is called. The available configuration options are listed here:
- build
- custom userId
- available (allowed) custom dimensions
- available (allowed) resource currencies
- available (allowed) resource item types
Build
Build is used to specify the current version of your game. Specify it using a string. Recommended to use a 3 digit version like [major].[minor].[patch]:
// Set build version
GameAnalytics.ConfigureBuild("android 1.0.0");
Custom userId
The SDK will automatically generate a user ID and this is perfectly fine for almost all cases.
Sometimes it is useful to supply this user_id
manually – for example if you download raw data for processing and need to match your internal user id (could be a database index on your user table) to the data collected through GameAnalytics.
Do not use a custom userId unless you have a specific need for using it.
Note that if you introduce this into a game that is already deployed (using the automatic id) it will start counting existing users as new users and your metrics will be affected. Use this from the start of the game lifetime.
GameAnalytics.ConfigureUserId("user1234567879");
Specifying allowed values
For certain types it is required to define a whitelist containing possible unique values during the configuration phase. When the SDK is being used (after initialization) only the specified values will be allowed. 20 values are allowed for each list.
Processing many unique dimension values can be taxing for our servers. A few games with a poor implementation can seriously increase our cost and affect stability. Games will be blocked if they submit too many unique dimension values. We have this configuration requirement to guide users into planning what dimension values can be used.
GameAnalytics.ConfigureAvailableResourceCurrencies("gems", "gold");
GameAnalytics.ConfigureAvailableResourceItemTypes("boost", "lives");
GameAnalytics.ConfigureAvailableCustomDimensions01("ninja", "samurai");
GameAnalytics.ConfigureAvailableCustomDimensions02("whale", "dolpin");
GameAnalytics.ConfigureAvailableCustomDimensions03("horde", "alliance");
Each resource currency string should only contain [A-Za-z] characters.
Enable/disable event submission
If you for GDPR purposes need to disable event submission you can call the following:
GameAnalytics.SetEnabledEventSubmission(false);
By default event submission is of course enabled. You will still receive configs if you have set any for your game even after disabling event submission.
Initializing
Call this method to initialize using the game key and secret key for your game.
// Initialize
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 method lets call it OnStart (which is called at the beginning of the game).
using GameAnalyticsSDK.Net;
namespace MyGame
{
public class MyGameClass
{
// ... other code from your project ...
void OnStart()
{
GameAnalytics.SetEnabledInfoLog(true);
GameAnalytics.SetEnabledVerboseLog(true);
GameAnalytics.ConfigureBuild("0.10");
GameAnalytics.ConfigureAvailableResourceCurrencies("gems", "gold");
GameAnalytics.ConfigureAvailableResourceItemTypes("boost", "lives");
GameAnalytics.ConfigureAvailableCustomDimensions01("ninja", "samurai");
GameAnalytics.ConfigureAvailableCustomDimensions02("whale", "dolpin");
GameAnalytics.ConfigureAvailableCustomDimensions03("horde", "alliance");
GameAnalytics.Initialize("[game key]", "[secret key]");
}
}
}