Quick Start
Get started with the Ascend React Native SDK in just a few steps.
Initialize the SDK
Section titled “Initialize the SDK”- Create a file
initAscend.tsunder src folder next to your app’s index file. - Import this file to your index file and call the
initAscendmethod to initialise Ascend. - Read following section to understand how to import and configure Ascend.
Initialise Ascend
Section titled “Initialise Ascend”import Ascend from "@d11/ascend-react-native";import AscendExperiments from "@d11/ascend-experiments-react-native";
const headers: any = { // put all headers which are required for api.dream11.com 'Host': 'api.dream11.com', 'locale': 'en-US', // Add other required headers};
const httpConfig: THttpConfig = { headers, shouldRetry: true, apiBaseUrl: 'https://api.dream11.com'};
const defaultValues = { DUMMY_API_PATH_HERE_1: { value: true, }, DUMMY_API_PATH_HERE_2: { randomBool: false, randomString: 'random string', randomInt: -97, sports: ['cricket', 'football'], },};
/** ascend-experiments config.* It should have at least following three attributes*/const ascendExperimentsPlugin = { name: PLUGIN_LIST.EXPERIMENTS, config: { defaultValues, }, exec: AscendExperiments}
/** ascend's initialization with basic configuration and ascend-experiments plugin*/export const initAscend = async () => { return await Ascend.init({ httpConfig, plugins: [ascendExperimentsPlugin, ...otherPlugins], });};Use Experiments
Section titled “Use Experiments”Fetch experiment values
Section titled “Fetch experiment values”Use following code snippet to initialise Experiment Plugin once. This operation is async. So it depends upon the consumer whether they want to wait for this operation to complete or proceed further.
NOTE: By default, on initialisation of the experiment plugin, it fetches the values of API Paths configured with the plugin.
/** Get the experiment plugin instance*/const experimentPlugin = await Ascend.getPlugin<IExperiment>(PLUGIN_LIST.EXPERIMENTS);
// Get boolean flagconst boolVal = await experimentPlugin.getBooleanFlag('API_PATH', 'VARIABLE_NAME');
// Get string flagconst stringVal = await experimentPlugin.getStringFlag('API_PATH', 'VARIABLE_NAME');
// Get integer flagconst intVal = await experimentPlugin.getIntFlag('API_PATH', 'VARIABLE_NAME');
// Get double flagconst doubleVal = await experimentPlugin.getDoubleFlag('API_PATH', 'VARIABLE_NAME');
// Get all variables for an experimentconst allVars = await experimentPlugin.getAllVariables('API_PATH');Use Events
Section titled “Use Events”Coming soon…
Example Usage in React Component
Section titled “Example Usage in React Component”import React, { useEffect, useState } from 'react';import { View, Text, Button } from 'react-native';import { initAscend } from './initAscend';
const MyComponent = () => { const [experimentValue, setExperimentValue] = useState(false);
useEffect(() => { const initializeSDK = async () => { try { await initAscend(); console.log('Ascend initialized successfully'); } catch (error) { console.error('Failed to initialize Ascend:', error); } };
initializeSDK(); }, []);
const getExperimentValue = async () => { try { const experimentPlugin = await Ascend.getPlugin<IExperiment>(PLUGIN_LIST.EXPERIMENTS); const value = await experimentPlugin.getBooleanFlag('DUMMY_API_PATH_HERE_1', 'value'); setExperimentValue(value); } catch (error) { console.error('Failed to get experiment value:', error); } };
return ( <View> <Text>Experiment Value: {experimentValue.toString()}</Text> <Button title="Get Experiment Value" onPress={getExperimentValue} /> </View> );};
export default MyComponent;