Getting Started with GameAnalytics CPP SDK
This guide explains how to integrate the GameAnalytics SDK into your C++ project (C17 standard or newer).
The GameAnalytics C++ SDK code is open-source. Please check out our github repo. Stay updated with the latest changes by checking the GameAnalytics C++ SDK Changelog.
1. Before you start
1.1. Pre-requisites for building the SDK
If you want to build the SDK from source, you will need the following:
- python (3.6 or higher)
- cmake (3.20 or higher)
- XCode (15.0 or newer) for Mac or Visual Studio 2019 or newer + VS Common Tools (for Windows)
1.2. Supported platforms
The C++ SDK supports following platforms:
- MacOS
- Windows (32-bit and 64-bit)
- Universal Windows Platform (UWP)
- Linux (tested on Ubuntu 16.04),
2. Install the SDK
You can choose to install the SDK by downloading the pre-built SDK or by building the SDK from source.
- Download SDK as binary
- Build from source
2.1. Download the SDK binaries
To download the cpp SDK binaries, please visit the GameAnalytics C++ SDK releases page and download the latest release.
The asset archive for each release contains the binaries for all supported platforms.
2.2. Build the SDK from source
To build the SDK from source, run setup.py
with the required argument for your platform:
python setup.py --platform {linux_x64,linux_x86,osx,win32,win64,uwp} [--cfg {Release,Debug}] [--build] [--test] [--coverage]
The following arguments are supported:
linux_x64
linux_x86
osx
win32
win64
The generated project can be found inside the build
folder.
3. Integrate the SDK
3.1. Add the SDK to your project
To integrate the SDK into your project, you need to download the SDK in the folder where you keep all your game's project external dependencies.
Make sure the following headers are accesible from your include paths (either add include/GameAnalytics
to your include paths):
GameAnalytics.h
GATypes.h
Remember to include the GameAnalytics header file wherever you are using the SDK:
#include "GameAnalytics/GameAnalytics.h"
3.2. Link the SDK
To link the SDK to your project, you need to link the static library GameAnalytics.lib
(Windows) or GameAnalytics.a
(Mac) to your project.
You need to link the following external libraries depending on your platform:
- Windows:
- libcurl.lib
- libeay32.lib
- ssleay32.lib
- MacOS/Linux:
- libcurl.a
- libssl.a
- libcrypto.a
For macOS you will also need to link the following system frameworks:
- CoreFoundation
- Foundation
- SystemConfiguration
3.3. Configure the SDK
Example:
gameanalytics::GameAnalytics::setEnabledInfoLog(true);
gameanalytics::GameAnalytics::setEnabledVerboseLog(true);
gameanalytics::GameAnalytics::configureBuild("0.10");
{
std::vector<std::string> list;
list.push_back("gems");
list.push_back("gold");
gameanalytics::GameAnalytics::configureAvailableResourceCurrencies(list);
}
{
std::vector<std::string> list;
list.push_back("boost");
list.push_back("lives");
gameanalytics::GameAnalytics::configureAvailableResourceItemTypes(list);
}
{
std::vector<std::string> list;
list.push_back("ninja");
list.push_back("samurai");
gameanalytics::GameAnalytics::configureAvailableCustomDimensions01(list);
}
{
std::vector<std::string> list;
list.push_back("whale");
list.push_back("dolphin");
gameanalytics::GameAnalytics::configureAvailableCustomDimensions02(list);
}
{
std::vector<std::string> list;
list.push_back("horde");
list.push_back("alliance");
gameanalytics::GameAnalytics::configureAvailableCustomDimensions03(list);
}
3.4. Initialize the SDK
To initialize the SDK, you need to call the initialize
method with your Game Key and Secret Key:
gameanalytics::GameAnalytics::initialize("<your game key>", "<your secret key>");
3.5. Custom log handler
If you want to use your own custom log handler here is how it is done:
void logHandler(std::string const& message, gameanalytics::EGALoggerMessageType type)
{
// add your logging in here
}
gameanalytics::GameAnalytics::configureCustomLogHandler(logHandler);
3.6. Swift (Mac)
If you are using Swift for a Mac application copy the following files into your project:
wrapper/GameAnalyticsWrapper.h
wrapper/GameAnalyticsWrapper.cpp
You should now be able to call the functions in the wrapper header file inside your swift files.
4.0. Sending events
Example:
gameanalytics::GameAnalytics::addDesignEvent("testEvent");
gameanalytics::GameAnalytics::addBusinessEvent("USD", 100, "boost", "super_boost", "shop");
gameanalytics::GameAnalytics::addResourceEvent(gameanalytics::Source, "gems", 10, "lives", "extra_life");
gameanalytics::GameAnalytics::addProgressionEvent(gameanalytics::Start, "progression01", "progression02");