Hypertune
  • Introduction
  • Getting Started
    • Set up Hypertune
    • Next.js (App Router) quickstart
    • Next.js (Pages Router) quickstart
    • React quickstart
    • Remix quickstart
    • Gatsby quickstart
    • Vue quickstart
    • Nuxt quickstart
    • Node.js quickstart
    • React Native quickstart
    • JavaScript quickstart
    • Python quickstart
    • Rust quickstart
    • Go quickstart
    • Web quickstart
    • GraphQL quickstart
  • Example apps
    • Next.js and Vercel example app
  • Concepts
    • Architecture
    • Project
    • Schema
    • Flag lifecycle
    • Logic
    • Variables
    • Splits
    • A/B tests
    • Staged rollouts
    • Multivariate tests
    • Machine learning loops
    • Events
    • Funnels
    • Hypertune Edge
    • Reduction
    • SDKs
    • GraphQL API
    • Git-style version control
    • App configuration
  • Use Cases
    • Feature flags and A/B testing
    • Landing page optimization
    • In-app content management
    • Pricing plan management
    • Permissions, rules and limits
    • Optimizing magic numbers
    • Backend configuration
    • Product analytics
  • Integrations
    • Vercel Edge Config integration
    • Google Analytics integration
    • Segment integration
    • Webhooks
      • Creating webhooks
      • Handling webhooks
  • SDK Reference
    • Installation
    • Type-safe client generation
    • Initialization
    • Build-time logic snapshot
    • Hard-coded fallbacks
    • Local-only, offline mode
    • Hydrate from your own server
    • Wait for server initialization
    • Provide targeting attributes
    • Local, synchronous evaluation
    • Remote logging
    • Getting flag updates
    • Serverless environments
    • Vercel Edge Config
    • Custom logging
    • Shutting down
Powered by GitBook
On this page
  • Provide targeting attributes during SDK initialization
  • Provide targeting attributes during local flag evaluation
  • Provide flag-specific targeting attributes
  1. SDK Reference

Provide targeting attributes

PreviousWait for server initializationNextLocal, synchronous evaluation

Last updated 10 months ago

Hypertune is uniquely architected to let you define targeting attributes at the:

  • root level

  • individual flag level

And provide them during:

  • SDK initialization

  • local flag evaluation

  • a mix of both

Provide targeting attributes during SDK initialization

To provide targeting attributes during SDK initialization, .

Provide targeting attributes during local flag evaluation

On the server, you'll typically provide targeting attributes when locally evaluating the root flag, passing it the context argument you defined in your . You'll get back the Root SDK node which will have type-safe methods to evaluate all your individual flags. In the browser, this is managed by the generated <HypertuneProvider> component.

src/lib/getHypertune.ts
import { createSource } from "../generated/hypertune";

const hypertuneSource = createSource({
  token: process.env.HYPERTUNE_TOKEN!,
});

export default async function getHypertune() {
  // Get flag updates in serverless environments
  // await hypertuneSource.initIfNeeded();

  return hypertuneSource.root({
    args: {
      context: {
        environment:
          process.env.NODE_ENV === "development"
            ? "development"
            : "production",
        user: { id: "1", name: "Test", email: "hi@test.com" },
      },
    },
  });
}
src/components/AppHypertuneProvider.tsx
import { HypertuneProvider } from "../generated/hypertune.react";

export default function AppHypertuneProvider({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <HypertuneProvider
      createSourceOptions={{
        token: import.meta.env.VITE_HYPERTUNE_TOKEN!,
      }}
      rootArgs={{
        context: {
          environment:
            process.env.NODE_ENV === "development"
              ? "development"
              : "production",
          user: { id: "1", name: "Test", email: "hi@test.com" },
        },
      }}
    >
      {children}
    </HypertuneProvider>
  );
}

Provide flag-specific targeting attributes

hypertune.upgradeCopy({ args: { selectedPlan }, fallback: "Upgrade your plan" });

You can also provide when evaluating individual flags:

schema
use an initialization query
flag-specific targeting attributes