Example: Basic Code to use Javascript Split SDK with React library and Next.js, the app has both Client side and Server side renderings, you can disable one or the other depending on business need.
Environment:
- npm 6.4.1
- next.js 9.2.2
- react 16.12.0
How to use:
- Download the attached zip file and unzip it, cd to the root folder and run the npm command below to download the dependencies:
npm install
- Open the file below in a text editor
./pages/_app.js
Locate the line below and replace BROWSER-API-KEY with a valid Browser type API Key
authorizationKey: 'BROWSER API KEY',
- Open file server/getServerSideSplitClient.js, locate the line below and replace SDK-API-KEY with a valid SDK type API Key
authorizationKey: 'SDK API KEY',
- The Server Side SDK will use the Split name in file ./constants.js under the serverFEATURE constant
export const serverFEATURE = 'test_split';
- The Client Side SDK will use the clientFEATURE constant
export const clientFEATURE = "sample_feature";
- Build the project with the command below
npm run build
- To start the server, run the command below
npm run start
-
Open `http://localhost:3000/ in your browser. The script will use load Split SDK on server side and Client (browser) side, and will show the treatments for both.
http://localhost:3000/
Comments
0 comments
Please sign in to leave a comment.