mirror of
https://github.com/hanzoai/insights.git
synced 2026-10-30 16:15:31 +00:00
The tree was a debranded snapshot of upstream taken around 2026-02-20, and upstream has moved about five months since. This replaces it with upstream master, mechanically re-derived: bin/debrand does the rename, and the pipeline and squashed migrations are restored from the shipped tree. Not a merge. The previous import replaced the tree wholesale in a single commit, so there is no shared content history to merge against. Reproducing the rename on the new tree is what actually converges. What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints, compose files, LLM.md, and insights/migrations. The squashed initial migration is load-bearing — the live database records it by name, so upstream's ~918 individual migrations cannot come back. Nine products are dropped as unreferenced. Twenty-one more that we do not run are kept anyway because the core app still imports them; unpicking those is a refactor and does not belong in a rebase. This base does not build yet, and the reasons are not in the rename: upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against our 4.2, and the dependency manifests still name upstream packages that we republish under our own names. Those are decisions, not renames.
156 lines
6.7 KiB
TypeScript
156 lines
6.7 KiB
TypeScript
import { memo } from 'react'
|
|
|
|
import { useMDXComponents } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'
|
|
|
|
export const ExperimentImplementationSnippet = memo(
|
|
({ language = 'javascript' }: { language?: string }): JSX.Element => {
|
|
const { CodeBlock, dedent } = useMDXComponents()
|
|
|
|
const snippets: Record<string, string> = {
|
|
javascript: dedent`
|
|
if (insights.getFeatureFlag('your-experiment-feature-flag') === 'test') {
|
|
// Do something differently for this user
|
|
} else {
|
|
// It's a good idea to let control variant always be the default behaviour,
|
|
// so if something goes wrong with flag evaluation, you don't break your app.
|
|
}
|
|
|
|
// Test that it works
|
|
insights.featureFlags.overrideFeatureFlags({ flags: {'your-experiment-feature-flag': 'test'} })
|
|
`,
|
|
react: dedent`
|
|
// You can either use the useFeatureFlagVariantKey hook,
|
|
// or you can use the feature flags component - https://hanzo.ai/docs/libraries/react#feature-flags-react-component
|
|
|
|
// Method one: using the useFeatureFlagVariantKey hook
|
|
import { useFeatureFlagVariantKey } from '@hanzo/react'
|
|
|
|
function App() {
|
|
const variant = useFeatureFlagVariantKey('your-experiment-feature-flag')
|
|
if (variant === 'test') {
|
|
// do something
|
|
}
|
|
}
|
|
|
|
// Method two: using the feature flags component
|
|
import { InsightsFeature } from '@hanzo/react'
|
|
|
|
function App() {
|
|
return (
|
|
<InsightsFeature flag='your-experiment-feature-flag' match='test'>
|
|
<div>
|
|
{/* the component to show */}
|
|
</div>
|
|
</InsightsFeature>
|
|
)
|
|
}
|
|
|
|
// You can also test your code by overriding the feature flag:
|
|
insights.featureFlags.overrideFeatureFlags({ flags: {'your-experiment-feature-flag': 'test'} })
|
|
`,
|
|
'react-native': dedent`
|
|
if (insights.getFeatureFlag('your-experiment-feature-flag') === 'test') {
|
|
// Do something differently for this user
|
|
} else {
|
|
// It's a good idea to let control variant always be the default behaviour,
|
|
// so if something goes wrong with flag evaluation, you don't break your app.
|
|
}
|
|
`,
|
|
'node.js': dedent`
|
|
const experimentFlagValue = await client.getFeatureFlag('your-experiment-feature-flag', 'user distinct id')
|
|
|
|
if (experimentFlagValue === 'test' ) {
|
|
// Do something differently for this user
|
|
} else {
|
|
// It's a good idea to let control variant always be the default behaviour,
|
|
// so if something goes wrong with flag evaluation, you don't break your app.
|
|
}
|
|
`,
|
|
python: dedent`
|
|
experiment_flag_value = insights.get_feature_flag("your-experiment-feature-flag", "user_distinct_id")
|
|
|
|
if experiment_flag_value == 'test':
|
|
# Do something differently for this user
|
|
else:
|
|
# It's a good idea to let control variant always be the default behaviour,
|
|
# so if something goes wrong with flag evaluation, you don't break your app.
|
|
`,
|
|
php: dedent`
|
|
if (Insights::getFeatureFlag('your-experiment-feature-flag', 'user distinct id') == 'test') {
|
|
// Do something differently for this user
|
|
} else {
|
|
// It's a good idea to let control variant always be the default behaviour,
|
|
// so if something goes wrong with flag evaluation, you don't break your app.
|
|
}
|
|
`,
|
|
ruby: dedent`
|
|
experimentFlagValue = insights.get_feature_flag('your-experiment-feature-flag', 'user distinct id')
|
|
|
|
if experimentFlagValue == 'test'
|
|
# Do something differently for this user
|
|
else
|
|
# It's a good idea to let control variant always be the default behaviour,
|
|
# so if something goes wrong with flag evaluation, you don't break your app.
|
|
end
|
|
`,
|
|
go: dedent`
|
|
experimentFlagValue, err := client.GetFeatureFlag(insights.FeatureFlagPayload{
|
|
Key: "your-experiment-feature-flag",
|
|
DistinctId: "distinct-id",
|
|
})
|
|
if err != nil {
|
|
// Handle error (e.g. capture error and fallback to default behaviour)
|
|
}
|
|
if experimentFlagValue == "test" {
|
|
// Do something differently for this user
|
|
} else {
|
|
// It's a good idea to let control variant always be the default behaviour,
|
|
// so if something goes wrong with flag evaluation, you don't break your app.
|
|
}
|
|
`,
|
|
android: dedent`
|
|
if (Insights.getFeatureFlag("your-experiment-feature-flag") == "test") {
|
|
// do something
|
|
} else {
|
|
// It's a good idea to let control variant always be the default behaviour,
|
|
// so if something goes wrong with flag evaluation, you don't break your app.
|
|
}
|
|
`,
|
|
ios: dedent`
|
|
if (InsightsSDK.shared.getFeatureFlag("your-experiment-feature-flag") as? String == "test") {
|
|
// do something
|
|
} else {
|
|
// It's a good idea to let control variant always be the default behaviour,
|
|
// so if something goes wrong with flag evaluation, you don't break your app.
|
|
}
|
|
`,
|
|
flutter: dedent`
|
|
if (await Insights().getFeatureFlag('your-experiment-feature-flag') == 'test') {
|
|
// Do something differently for this user
|
|
} else {
|
|
// It's a good idea to let control variant always be the default behaviour,
|
|
// so if something goes wrong with flag evaluation, you don't break your app.
|
|
}
|
|
`,
|
|
}
|
|
|
|
const langMap: Record<string, string> = {
|
|
javascript: 'javascript',
|
|
react: 'jsx',
|
|
'react-native': 'javascript',
|
|
'node.js': 'javascript',
|
|
python: 'python',
|
|
php: 'php',
|
|
ruby: 'ruby',
|
|
go: 'go',
|
|
android: 'kotlin',
|
|
ios: 'swift',
|
|
flutter: 'dart',
|
|
}
|
|
|
|
return (
|
|
<CodeBlock language={langMap[language] || 'javascript'} code={snippets[language] || snippets.javascript} />
|
|
)
|
|
}
|
|
)
|