The Statsig C++ SDK for multi-user, server side environments. If you need a SDK for another language or single user client environment, check out our other SDKs.
Statsig helps you move faster with Feature Gates (Feature Flags) and Dynamic Configs. It also allows you to run A/B tests to validate your new features and understand their impact on your KPIs. If you're new to Statsig, create an account at statsig.com.
- Create a
.cmakefile that downloads the SDK at build time.
FetchContent_Declare(statsig
GIT_REPOSITORY https://github.com/statsig-io/private-cpp-server-sdk.git
GIT_TAG v0.1.0
)
FetchContent_MakeAvailable(statsig)
- Include the
.cmakefile in yourCMakeLists.txt
cmake_minimum_required(VERSION 3.11)
include(FetchContent)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/statsig.cmake)
- Configure build options (optional)
option(STATSIG_BUILD_TESTS "Compile with unit tests" OFF)
option(STATSIG_INCLUDE_MAXMINDDB "Include the 3rd party library maxminddb. (Disable if country lookup is not needed)" ON)
NOTE: Our SDK requires a minimum c++17 standard version
You can set the option set(STATSIG_BUILD_TESTS ON) in your CMakeLists.txt to include tests in your build.
To run the tests, use the command ctest --test-dir build/tests
See the ctest manual for more options.
- Pull requests are welcome!
- If you encounter bugs, feel free to file an issue.
- For integration questions/help, join our slack community.
This repo now includes a SwiftPM wrapper target Statsig that exposes a
pure Swift API while calling into the C++ SDK internally.
Important: per SwiftPM rules, any target that depends on Statsig must
enable C++ interoperability.
Install dependencies:
nlohmann-json and cpp-httplib are vendored under third_party/.
macOS (Homebrew):
brew install boost openssl@3
brew link boostLinux (apt):
sudo apt-get update
sudo apt-get install -y \
build-essential \
pkg-config \
libssl-dev \
libboost-all-dev \Minimal usage:
import Statsig
do {
try Statsig.initialize(sdkKey: "YOUR_SERVER_KEY")
let user = StatsigUser(userID: "demo-user")
let enabled = try Statsig.checkGate(user: user, gate: "gate_name")
print(enabled)
} catch {
print(error)
}Linux via Docker:
docker build -t statsig-swift-cpp .
docker run --rm statsig-swift-cpp