-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: adding more samples for precomp
- Loading branch information
1 parent
9e25aa1
commit 75aa78d
Showing
9 changed files
with
118 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
samples/react/src/samples/precomputed-client/PrecomputedClientCheckGate.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { myStatsigClient } from './PrecomputedClientInstance'; | ||
|
||
// prettier-ignore | ||
export default async function Sample(): Promise<void> { | ||
// <snippet> | ||
if (myStatsigClient.checkGate("new_homepage_design")) { | ||
// Gate is on, show new home page | ||
} else { | ||
// Gate is off, show old home page | ||
} | ||
// </snippet> | ||
} |
15 changes: 15 additions & 0 deletions
15
samples/react/src/samples/precomputed-client/PrecomputedClientGetDynamicConfig.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import { myStatsigClient } from './PrecomputedClientInstance'; | ||
|
||
// prettier-ignore | ||
export default async function Sample(): Promise<void> { | ||
// <snippet> | ||
const dynamicConfig = myStatsigClient.getDynamicConfig("awesome_product_details"); | ||
const itemName = dynamicConfig.value["product_name"] ?? "Some Fallback"; | ||
const price = dynamicConfig.value["price"] ?? 10.0; | ||
|
||
if (dynamicConfig.value["is_discount_enabled"] === true) { | ||
// apply some discount logic | ||
} | ||
// </snippet> | ||
} |
30 changes: 30 additions & 0 deletions
30
samples/react/src/samples/precomputed-client/PrecomputedClientGetLayer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import { myStatsigClient } from './PrecomputedClientInstance'; | ||
|
||
// prettier-ignore | ||
export default async function Sample(): Promise<void> { | ||
// <snippet> | ||
// Values via getLayer | ||
|
||
const layer = myStatsigClient.getLayer("user_promo_experiments"); | ||
|
||
const promoTitle = layer.getValue("title") ?? "Welcome to Statsig!"; | ||
const discount = layer.getValue("discount") ?? 0.1; | ||
// </snippet> | ||
|
||
viaGetExperiment() | ||
} | ||
|
||
// prettier-ignore | ||
function viaGetExperiment() { | ||
// <snippet> | ||
|
||
// or, via getExperiment | ||
|
||
const titleExperiment = myStatsigClient.getExperiment("new_user_promo_title"); | ||
const priceExperiment = myStatsigClient.getExperiment("new_user_promo_price"); | ||
|
||
const promoTitle = titleExperiment.value["title"] ?? "Welcome to Statsig!"; | ||
const discount = priceExperiment.value["discount"] ?? 0.1; | ||
// </snippet> | ||
} |
16 changes: 16 additions & 0 deletions
16
samples/react/src/samples/precomputed-client/PrecomputedClientGetLogEvent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import { myStatsigClient } from './PrecomputedClientInstance'; | ||
|
||
// prettier-ignore | ||
export default async function Sample(): Promise<void> { | ||
// <snippet> | ||
myStatsigClient.logEvent({ | ||
eventName: 'add_to_cart', | ||
value: 'SKU_12345', | ||
metadata: { | ||
price: '9.99', | ||
item_name: 'diet_coke_48_pack', | ||
}, | ||
}); | ||
// </snippet> | ||
} |
8 changes: 8 additions & 0 deletions
8
samples/react/src/samples/precomputed-client/PrecomputedClientInstance.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { PrecomputedEvaluationsClient } from '@statsig/precomputed-evaluations'; | ||
|
||
import { STATSIG_CLIENT_KEY } from '../../Contants'; | ||
|
||
export const myStatsigClient = new PrecomputedEvaluationsClient( | ||
STATSIG_CLIENT_KEY, | ||
{ userID: '' }, | ||
); |
9 changes: 9 additions & 0 deletions
9
samples/react/src/samples/precomputed-client/PrecomputedClientShutdown.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import { myStatsigClient } from './PrecomputedClientInstance'; | ||
|
||
// prettier-ignore | ||
export default async function Sample(): Promise<void> { | ||
// <snippet> | ||
await myStatsigClient.shutdown(); | ||
// </snippet> | ||
} |
18 changes: 18 additions & 0 deletions
18
samples/react/src/samples/precomputed-client/PrecomputedInitialize.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// <snippet> | ||
import { PrecomputedEvaluationsClient } from '@statsig/precomputed-evaluations'; | ||
|
||
// </snippet> | ||
import { STATSIG_CLIENT_KEY as YOUR_CLIENT_KEY } from '../../Contants'; | ||
|
||
// prettier-ignore | ||
export default async function Sample(): Promise<void> { | ||
// <snippet> | ||
const myStatsigClient = new PrecomputedEvaluationsClient( | ||
YOUR_CLIENT_KEY, | ||
{ userID: 'a-user' }, | ||
{ environment: { tier: 'development' } } // (optional) Configure SDK via StatsigOptions here | ||
); | ||
|
||
await myStatsigClient.initialize(); | ||
// </snippet> | ||
} |