Skip to content

Commit

Permalink
Merge branch 'main' into monorepo-3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-statsig authored Sep 6, 2024
2 parents 6e2b7d8 + d409e2f commit c061df0
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 35 deletions.
6 changes: 3 additions & 3 deletions docs/client/javascript-mono/NextJsAppRouterUsage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export const NextJsInstall = _nextJsInstall;
import * as _nextJsBootstrap from "./_nextJsBootstrap.mdx";
export const NextJsBootstrap = _nextJsBootstrap;

import * as _nextJsSimpleProvider from "./_nextJsAppRouterSimpleProvider.mdx";
export const NextJsSimpleProvider = _nextJsSimpleProvider;
import * as _nextJsAppRouterSimpleProvider from "./_nextJsAppRouterSimpleProvider.mdx";
export const NextJsAppRouterSimpleProvider = _nextJsAppRouterSimpleProvider;

import * as _nextJsApiProxy from "./_nextJsApiProxy.mdx";
export const NextJsApiProxy = _nextJsApiProxy;
Expand All @@ -53,7 +53,7 @@ export const Builder = SDKDocsBuilder({
},
],
[NextJsInstall, {}],
[NextJsSimpleProvider, {}],
[NextJsAppRouterSimpleProvider, {}],
[NextJsBootstrap, {}],
[NextJsApiProxy, {}],
]
Expand Down
4 changes: 4 additions & 0 deletions docs/client/javascript-mono/NextJsPageRouterUsage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export const NextJsInstall = _nextJsInstall;
import * as _nextJsPageRouterBootstrap from "./_nextJsPageRouterBootstrap.mdx";
export const NextJsBootstrap = _nextJsPageRouterBootstrap;

import * as _nextJsPageRouterSimpleProvider from "./_nextJsPageRouterSimpleProvider.mdx";
export const NextJsPageRouterSimpleProvider = _nextJsPageRouterSimpleProvider;

import * as _nextJsPageRouterApiProxy from "./_nextJsPageRouterApiProxy.mdx";
export const NextJsApiProxy = _nextJsPageRouterApiProxy;

Expand All @@ -50,6 +53,7 @@ export const Builder = SDKDocsBuilder({
},
],
[NextJsInstall, { isPageRouter: true }],
[NextJsPageRouterSimpleProvider, {}],
[NextJsBootstrap, {}],
[NextJsApiProxy, {}],
]
Expand Down
24 changes: 24 additions & 0 deletions docs/client/javascript-mono/_nextJsAppRouterSimpleProvider.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,28 @@ export default function Home() {
</div>
);
}
```

## Updating user properties

Sometimes you'll need to update user properties, say when the user logs in and a `userID` is assigned, or a set of new properties have been identified. This would require Statsig to go fetch new values for all the gates, experiments and config evaluations. This is achieved by the `useStatsigUser` hook.

Create the file `src/app/login/page.tsx` and put this code in. Click on the Login button to update the user.

```js
// login/page.tsx
import { useGateValue, useStatsigUser } from "@statsig/react-bindings";

export default function LoginPage() {
const gateValue = useGateValue("check_user");
const { updateUserAsync } = useStatsigUser();
return (
<div>
<div>Gate is {gateValue ? 'passing' : 'failing'}.</div>
<button onClick={() => updateUserAsync({ userID: "2" })}>
Login
</button>
</div>
);
}
```
32 changes: 31 additions & 1 deletion docs/client/javascript-mono/_nextJsBootstrap.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,37 @@ import TabItem from "@theme/TabItem";

## Server Side Rendering (SSR)

Since Next.js supports Server Side Rendering (SSR), we should setup Statsig to take advantage of this.
Since Next.js supports Server Side Rendering (SSR), we could setup Statsig to take advantage of this.

### Install

If you intend to use fully utilize Statsig across Next.js, you will need both Server and Client SDKs installed.
[`@statsig/js-client`](/client/javascript-sdk) and [`@statsig/react-bindings`](/client/javascript-sdk/react) for the client side and [`statsig-node`](/server/nodejsServerSDK) for the server side.


<Tabs
defaultValue="npm"
groupId="js-install-choice"
values={[
{label: 'NPM', value: 'npm'},
{label: 'Yarn', value: 'yarn'},
]}>

<TabItem value="npm">

```shell
npm install @statsig/js-client @statsig/react-bindings statsig-node
```

</TabItem>
<TabItem value="yarn">

```shell
yarn add @statsig/js-client @statsig/react-bindings statsig-node
```

</TabItem>
</Tabs>

### Create layout.tsx

Expand Down
30 changes: 0 additions & 30 deletions docs/client/javascript-mono/_nextJsInstall.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -57,33 +57,3 @@ yarn add @statsig/js-client @statsig/react-bindings
</TabItem>
</Tabs>

### Server side rendering

If you intend to use ServerTo fully utilize Statsig across Next.js, you will need both Server and Client SDKs installed.
[`@statsig/js-client`](/client/javascript-sdk) and [`@statsig/react-bindings`](/client/javascript-sdk/react) for the client side and [`statsig-node`](/server/nodejsServerSDK) for the server side.


<Tabs
defaultValue="npm"
groupId="js-install-choice"
values={[
{label: 'NPM', value: 'npm'},
{label: 'Yarn', value: 'yarn'},
]}>

<TabItem value="npm">

```shell
npm install @statsig/js-client @statsig/react-bindings statsig-node
```

</TabItem>
<TabItem value="yarn">

```shell
yarn add @statsig/js-client @statsig/react-bindings statsig-node
```

</TabItem>
</Tabs>

30 changes: 30 additions & 0 deletions docs/client/javascript-mono/_nextJsPageRouterBootstrap.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,36 @@ import TabItem from "@theme/TabItem";

Since Next.js supports Server Side Rendering (SSR), we could setup Statsig to take advantage of this.

### Install

If you intend to use fully utilize Statsig across Next.js, you will need both Server and Client SDKs installed.
[`@statsig/js-client`](/client/javascript-sdk) and [`@statsig/react-bindings`](/client/javascript-sdk/react) for the client side and [`statsig-node`](/server/nodejsServerSDK) for the server side.


<Tabs
defaultValue="npm"
groupId="js-install-choice"
values={[
{label: 'NPM', value: 'npm'},
{label: 'Yarn', value: 'yarn'},
]}>

<TabItem value="npm">

```shell
npm install @statsig/js-client @statsig/react-bindings statsig-node
```

</TabItem>
<TabItem value="yarn">

```shell
yarn add @statsig/js-client @statsig/react-bindings statsig-node
```

</TabItem>
</Tabs>

### Create StatsigServerUtil.ts

Let's start by create a util function to get values from the Statsig Node SDK.
Expand Down
81 changes: 81 additions & 0 deletions docs/client/javascript-mono/_nextJsPageRouterSimpleProvider.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
## Usage

In the Page Router model, you will need to wrap your app in `StatsigProvider` which will provide Statsig context throughout your NextJS app.

Modify your `_app.tsx` to match the following

```js
// _app.tsx
import type { AppProps } from "next/app";
import { StatsigProvider } from "@statsig/react-bindings";

export default function App({ Component, pageProps }: AppProps) {
return (
<StatsigProvider sdkKey="client-KEY" user={{ userID: "20" }}>
<Component {...pageProps} />
</StatsigProvider>
);
}
```

With that wrapper, you're all set to use Statsig gates, experiments and configs.

## Gates

You can check gates by using `useGateValue` hook in any client side rendered page. In this case, let's modify `page.tsx` to check for a gate value:

```js
// index.tsx
import { useGateValue } from "@statsig/react-bindings";

export default function Home() {
const gate = useGateValue("check_user")
return (
<div>
Gate Value: {gate ? 'PASSED' : 'FAILED'}
</div>
);
}
```

## Experiments

You can reach into the experiment variant and access parameters that are assigned to the specific user by using the useExperiment hook like this:

```js
// index.tsx
import { useExperiment } from "@statsig/react-bindings";

export default function Home() {
const experiment = useExperiment("headline_test")
return (
<div>
Headline Parameter: {experiment.get('headline', 'Default')}
</div>
)
}
```

## Updating user properties

Sometimes you'll need to update user properties, say when the user logs in and a `userID` is assigned, or a set of new properties have been identified. This would require Statsig to go fetch new values for all the gates, experiments and config evaluations. This is achieved by the `useStatsigUser` hook.

Create the file `pages/login.tsx` and put this code in. Click on the Login button to update the user.

```js
// pages/login.tsx
import { useGateValue, useStatsigUser } from "@statsig/react-bindings";

export default function LoginPage() {
const gateValue = useGateValue("check_user");
const { updateUserAsync } = useStatsigUser();
return (
<div>
<div>Gate is {gateValue ? 'passing' : 'failing'}.</div>
<button onClick={() => updateUserAsync({ userID: "2" })}>
Login
</button>
</div>
);
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ To monitor the status of your experiment,
- **Crossover users** monitors the percentage of units which are exposed to more than one experiment group for a given experiment. Statsig discards crossover users from the experiment analysis, which may reduce your sample size and statistical power. The following thresholds are used for displaying crossover users alerts:
- **Crossover user percentage between 1% and 10%**: Warning (yellow) meaning that the presence of a number of crossover users has been detected, but the impact on the experiment is expected to be relatively small.
- **Crossover user percentage over 10%**: Alert (red) indicating that there are a substantial number of crossover users, which can indicate a problem with you experiment setup.
- **User metrics were computed** This check confirms that we were able to join exposure data to metric data and produce experiment results.
- **User metrics were computed** confirms that we were able to join exposure data to metric data and produce experiment results.
- **Metrics Available for Topline Impact** checks whether there is sufficient metric data to calculate topline impacts for each metric. Click [here](https://docs.statsig.com/stats-engine/topline-impact) to learn more information about topline impact.
- **Differential Impact Detection completed** checks whether the differential impact detection has finished and flags if extreme differential impacts are detected for any sub-population per your configuration. Click [here](https://docs.statsig.com/experiments-plus/differential-impact-detection) to learn more about differential impact detection.

Some health checks are relevant only to end-to-end statsig experiments where the statsig sdk is used for assignment, while some are only relevant for analysis experiments where assignment is handled outside of statsig.

Expand Down

0 comments on commit c061df0

Please sign in to comment.