# AppFig Quick Start

Source: https://appfig.com/docs/quick-start-guide

Feature flags and remote config that evaluate rules client-side. Zero latency, maximum control.

> **Prefer not to wire it by hand?** The [Guided Setup](https://appfig.com/docs/guided-setup) reads your Flutter, Unity, Android or iOS code, finds the values you can control and opens one pull request that installs the SDK. Start at [app.appfig.com/start](https://app.appfig.com/start).

## Install & Initialize

### Unity

```csharp
AppFig.Init("company-id", "tenant-id", "prod", "api-key");
```

### React/Web

```typescript
import AppFig from './AppFigReactSDK';

await AppFig.init({
  companyId: 'company-id',
  tenantId: 'tenant-id',
  env: 'prod',
  apiKey: 'api-key'
});
```

### iOS

```swift
AppFig.shared.initialize(
  companyId: "company-id",
  tenantId: "tenant-id",
  environment: "prod",
  apiKey: "api-key"
)
```

### Android

```kotlin
AppFig.init(
  context = this,
  companyId = "company-id",
  tenantId = "tenant-id",
  env = "prod",
  apiKey = "api-key"
)
```

## Log Events

### Unity
```csharp
AppFig.LogEvent("level_complete");
AppFig.LogEvent("purchase", new Dictionary<string, string> {
  { "item_id", "sword" },
  { "price", "9.99" }
});
```

### React/Web
```typescript
AppFig.logEvent('button_clicked');
AppFig.logEvent('purchase', { item_id: 'sword', price: '9.99' });
```

### iOS
```swift
AppFig.shared.logEvent(name: "level_complete")
AppFig.shared.logEvent(name: "purchase", parameters: ["item_id": "sword"])
```

### Android
```kotlin
AppFig.logEvent("level_complete")
AppFig.logEvent("purchase", mapOf("item_id" to "sword"))
```

## Check Features

### Unity
```csharp
if (AppFig.IsFeatureEnabled("double_xp")) {
  ApplyDoubleXP();
}

string maxLives = AppFig.GetFeatureValue("max_lives");
```

### React/Web
```typescript
const showBanner = AppFig.getConfig('premium_banner');
if (showBanner === 'on') {
  renderBanner();
}
```

### iOS
```swift
if AppFig.shared.isFeatureEnabled("double_xp") {
  applyDoubleXP()
}

let maxLives = AppFig.shared.getFeatureValue("max_lives")
```

### Android
```kotlin
if (AppFig.isFeatureEnabled("double_xp")) {
  applyDoubleXP()
}

val maxLives = AppFig.getFeatureValue("max_lives")
```

## Set Properties

### Unity
```csharp
AppFig.SetUserProperty("tier", "premium");
AppFig.SetUserProperty("level", "15");
```

### React/Web
```typescript
AppFig.setUserProperties({
  tier: 'premium',
  level: '15'
});
```

### iOS
```swift
AppFig.shared.setUserProperty(key: "tier", value: "premium")
AppFig.shared.setUserProperty(key: "level", value: "15")
```

### Android
```kotlin
AppFig.setUserProperty("tier", "premium")
AppFig.setUserProperty("level", "15")
```

## How It Works

1. **Define rules** in dashboard or JSON file
2. **SDK downloads** rules on launch (cached)
3. **App logs events** as users interact
4. **SDK evaluates** rules locally, instantly
5. **Features respond** to user behavior

## Example Rules

### Veteran Bonus
```
IF event "level_complete" count >= 10
THEN "veteran_bonus" = "2x"
```

### Platform-Specific
```
IF device.platform IN ["iOS", "Android"]
THEN "mobile_controls" = "on"
```

### Country Pricing
```
IF device.country == "US"
THEN "price" = "9.99"
```

### A/B Test
```
IF user.id % 2 == 0 THEN "button_color" = "red"
IF user.id % 2 == 1 THEN "button_color" = "blue"
```

## Plans

Every plan delivers your rules from the global CDN, evaluates them on the device and reaches devices within a minute. Players and publishes are unlimited, and SDK setup is identical on all plans.

**Lite (free):**
- 1 app, 1 seat, with dev and prod environments
- 5 configs, 1 A/B test at a time
- One AI setup
- No credit card required

An app is one game or product. Its iOS, Android and web versions share one app, one key and the same configs; when a change is for one platform only, add a platform condition to the rule.

**Full ($99 per app a month, your first app included; $50 per app from the 11th):**
- 500 configs and 25 A/B tests at a time, per app
- 1,000 AI credits a month per app
- Unlimited team, and email support from the team that builds AppFig

See [pricing](https://appfig.com/#pricing).

## Supported Platforms

- **Unity** - C# SDK (iOS, Android, Windows, macOS, WebGL)
- **React/Web** - TypeScript SDK (all browsers)
- **iOS** - Swift SDK (iPhone, iPad)
- **Android** - Kotlin SDK (phones, tablets)

## Next Steps

**Full Guides:**
- [Android Integration](https://appfig.com/docs/android-integration)
- [iOS Integration](https://appfig.com/docs/ios-integration)
- [React/Web Guide](https://appfig.com/docs/react-web-guide)
- [Unity Integration](https://appfig.com/docs/unity-integration)

**Concepts:**
- [Core Concepts](https://appfig.com/docs/concepts)
- [How It Works](https://appfig.com/docs/how-it-works)

**Reference:**
- [Rule Schema](https://appfig.com/docs/rule-schema)
- [Testing Guide](https://appfig.com/docs/testing)

## Auto-Detected Properties

The SDK automatically detects and sets these properties:

```
platform       "iOS", "Android", "Windows", "macOS", etc.
os_version     "17.0", "13", "11.0"
language       "English", "Japanese", "Spanish"
timezone       "America/Los_Angeles", "Asia/Tokyo"
country        "US", "JP", "GB"
device_brand   "Apple", "Samsung", "Google"
device_model   "iPhone 15", "Galaxy S23", "Pixel 8"
```

Use these in rules without any setup required.

## Common Patterns

### Feature Rollout
```csharp
// Enable for users who completed onboarding
Rule: IF event "onboarding_complete" count >= 1
      THEN "new_feature" = "on"
```

### Time-Limited Event
```csharp
// Show holiday event based on timezone
Rule: IF device.timezone IN ["America/Los_Angeles", "America/New_York"]
      AND event "app_open" count >= 1
      THEN "holiday_event" = "on"
```

### Premium Features
```csharp
// Unlock features for premium users
Rule: IF user.subscription_tier == "premium"
      THEN "unlimited_lives" = "on"
```

### Progressive Unlock
```csharp
// Increase lives as player progresses
Rule 1: IF event "level_complete" count >= 5  THEN "max_lives" = "5"
Rule 2: IF event "level_complete" count >= 10 THEN "max_lives" = "7"
Rule 3: IF event "level_complete" count >= 20 THEN "max_lives" = "10"
```

## Best Practices

1. **Cache feature values** - Don't check every frame
2. **Handle null** - Provide fallback values
3. **Log liberally** - More events = better targeting
4. **Test rules** - Verify before deploying
5. **Start on Lite** - free for 1 app and 5 configs, no credit card

## Quick Troubleshooting

**Features return null?**
- Check feature name spelling (case-sensitive)
- Verify rules are loaded
- Log events/properties first

**Rules not updating?**
- Wait for poll interval
- Call `refreshRules()` manually
- Check network connection

**SDK not initialized?**
- Must call init before any SDK methods
- Initialize in app entry point

---

**Ready to start?** Pick your platform above and follow the full integration guide.
