Initialize the SDK
Initialize Gameball at app startup, typically in your root component or App.tsx:
import { GameballApp, GameballConfig } from 'gameball-react-native';
import { useEffect } from 'react';
function App() {
useEffect(() => {
const config: GameballConfig = {
apiKey: 'your-api-key', // Required
lang: 'en', // Required ('en' or 'ar')
shop: 'your-shop-id', // Optional
platform: 'react-native', // Optional
sessionToken: 'your-session-token', // Optional - for v4.1 endpoints
apiPrefix: 'custom-prefix', // Optional - custom API URL
};
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, defaults to “react-native”.
Session Token for secure authentication (enables automatic v4.1 endpoint routing).
Custom API base URL for enterprise configurations.
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 'gameball-react-native';
async function initializeGameball() {
try {
const config = {
apiKey: 'your-api-key',
lang: 'en',
};
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