Context
Search…
Integration Steps
Adding experimentation to your application is as simple as sending Context your Segment events and adding our SDK to your application.

Add Context as a Segment destination

Things you'll need:

    Context API key (see "Organization" in your Context dashboard)
    A Segment Account

Steps:

    1.
    In Segment add a webhook destination to the application you want to run experiments on
    2.
    Under Connection Settings fill in:
      Webhook URL: https://gateway.dev.contextexperiments.com/segment
      Headers: Authorization > YOUR_CONTEXT_API_KEY
    3.
    Turn the destination on

Add the Context SDK to your React App

Things you'll need:

    Context API key (same as above)
    The Environment Id for the web application you are integrating with (see Organization > Application > Environment in the Context dashboard)
We recommend passing this in as an environment variable. This will be different for each environment e.g. Production, Staging, QA
    An existing Segment integration

Steps:

    1.
    Add our SDK to your React project using yarn add @context-experiments/react or npm install @context-experiments/react. The @context-experiments/core package will be included as a dependency.
We assume that you're using a module bundler like Parcel, Webpack, or Browserify. If you don't yet use npm/yarn or a modern module bundler, we don't support single-file UMD builds yet. We'll add support sometime in the future. Please let us know if that's something you'd like to see.
2. Create the decision engine in the root of your application, typically /src/index.js - this will automatically handle getting the data file, managing user identification, and traffic splitting.
1
import { create as createDecisionEngine } from "@context-experiments/core"
2
3
const decisionEngine = createDecisionEngine({
4
apiKey: 'YOUR_CONTEXT_API_KEY',
5
environmentUuid: 'CURRENT_ENVIRONMENT_KEY',
6
});
Copied!
3. Make it available to the application using the Context Provider
1
import { Provider as ContextProvider } from "@context-experiments/react";
2
3
ReactDOM.render(
4
<React.StrictMode>
5
<ContextProvider engine={decisionEngine}>
6
<App />
7
</ContextProvider>
8
</React.StrictMode>,
9
document.getElementById("root")
10
);
Copied!
That's it! You should now be able to create features and experiments as in the Usage Examples section above. For advanced integrations like server side rendering or capturing metadata from Context for use in your existing analytics stack, see the FAQ.
Last modified 8mo ago