Quick Start
Get started with the Ascend React Native SDK in just a few steps.
Initialize the SDK
Section titled “Initialize the SDK”import React, { useEffect } from 'react';import { Ascend } from '@dreamhorizonorg/ascend-react-native';
const App = () => { useEffect(() => { setupAscendSDK(); }, []);
const setupAscendSDK = async () => { // 1. Initialize with configuration const result = await Ascend.init({ // Client authentication and user settings clientConfig: { apiKey: 'your-api-key', // Required: Your Ascend API key userId: 'user-123', // Optional: Set user during initialization environment: 'production', // Optional: 'development' | 'staging' | 'production' enableDebugLogging: false, // Optional: Enable debug logs for troubleshooting },
// Base HTTP configuration httpConfig: { apiBaseUrl: 'https://your-api-url.com', // Required: Your API base URL },
// Enable experiments plugin for feature flags and A/B testing plugins: [ { name: 'EXPERIMENTS', config: { // HTTP settings specific to experiments httpConfig: { apiBaseUrl: 'https://your-api-url.com', apiEndpoint: '/v1/allocations/', headers: { 'x-experiment-keys': 'your-experiment-key', // Your experiment keys }, },
// Default values used as fallback when API is unavailable defaultValues: { 'button_color': { color: 'blue', enabled: true, size: 'medium', }, 'new_feature': { enabled: false, }, },
// Caching and behavior settings enableCaching: true, // Enable offline caching shouldFetchOnInit: true, // Fetch experiments on initialization shouldRefreshDRSOnForeground: false, // Auto-refresh when app comes to foreground }, }, ], });
// 2. Check initialization status if (result.success) { console.log('✅ Ascend SDK initialized successfully');
// 3. Set a user (required for experiments) await Ascend.setUser('user-123'); } else { console.error('❌ Failed to initialize Ascend SDK:', result.error); } };
return ( // Your app components );};Use Experiments
Section titled “Use Experiments”import { Experiments } from '@dreamhorizonorg/ascend-react-native';
// Get string valueconst buttonColor = await Experiments.getStringFlag('button_color', 'color');console.log('Button color:', buttonColor);
// Get boolean valueconst isEnabled = await Experiments.getBooleanFlag('feature_toggle', 'enabled');console.log('Feature enabled:', isEnabled);
// Get number valueconst maxRetries = await Experiments.getNumberFlag('retry_config', 'max_attempts');console.log('Max retries:', maxRetries);
// Get all variables for an experimentconst allVars = await Experiments.getAllVariables('button_color');console.log('All variables:', allVars);Fetch Experiments from API
Section titled “Fetch Experiments from API”import { Experiments } from '@dreamhorizonorg/ascend-react-native';
// Fetch experiments with new default valuesawait Experiments.fetchExperiments({ 'button_color': { color: 'blue' }});
// Refresh all experiments using predefined defaultsawait Experiments.refreshExperiment();Use Events
Section titled “Use Events”Coming soon…