title: “Initialize SDK”
description: “Initialize Gameball React Native SDK with your configuration”
Initialize the SDK
Initialize Gameball at app startup, typically in your root component or App.tsx:
import { GameballApp, GameballConfig } from 'react-native-gameball';
import { useEffect } from 'react';
function App() {
useEffect(() => {
const config: GameballConfig = {
apiKey: 'your-api-key', // Required
lang: 'en', // Required
shop: 'your-shop-id', // Optional
platform: 'your-platform-id', // Optional
sessionToken: 'your-session-token', // Optional - secure authentication
};
GameballApp.getInstance().init(config);
}, []);
return (
// Your app components
);
}
Configuration Parameters
The client API key available in your Gameball dashboard (required).
Language code: ‘en’ or ‘ar’ (required).
Your Gameball shop identifier for multi-shop configurations.
Platform identifier (optional, set if you manage multiple platforms).
Session Token for secure authentication (enables automatic v4.1 endpoint routing).
Validation Rules
GameballConfig requires:
- API key is required (cannot be null)
- Language is required (cannot be null)
Using Async/Await
You can use async/await for initialization if needed:
import { GameballApp } from 'react-native-gameball';
async function initializeGameball() {
try {
const config: GameballConfig = {
apiKey: 'your-api-key',
lang: 'en',
shop: 'your-shop-id',
platform: 'your-platform-id',
sessionToken: 'your-session-token',
};
await GameballApp.getInstance().init(config);
console.log('Gameball SDK initialized successfully');
} catch (error) {
console.error('Failed to initialize Gameball:', error);
}
}
Initialize the SDK as early as possible in your app’s lifecycle to ensure it’s ready when you need to track events or show the profile widget.
Make sure to use your actual API key from the Gameball dashboard. Test keys are for development, production keys are for live deployment.
Next Steps