Skip to main content

Market Availability Check

The Reachu SDK automatically verifies if the market is available for the user's country before enabling components. If the market is not available, all Reachu components are automatically hidden.

Overview

The Market Availability Check feature allows you to:

  • Automatically detectif your market is available for a specific country
  • Hide SDK componentsgracefully when the market is unavailable
  • Show alternative contentinstead of showing errors
  • Seamless user experiencewith no error messages visible to users

How It Works

When you provide a userCountryCode during configuration, the SDK:

  1. Checks if the market is available for that country via the API
  2. If available → SDK works normally
  3. If unavailable → SDK is disabled silently, components are hidden
  4. If no country provided → SDK works normally (backward compatible)

Basic Usage

Option 1: No Country Check (SDK Always Enabled)

App.swift
import ReachuCore

@main
struct MyApp: App {
init() {
ConfigurationLoader.loadConfiguration()
}

var body: some Scene {
WindowGroup {
ContentView()
}
}
}

Option 2: With User Country Check

App.swift
import ReachuCore

@main
struct MyApp: App {
init() {
// Pass user's country code
// SDK will check if market is available for this country
ConfigurationLoader.loadConfiguration(userCountryCode: "US")
}

var body: some Scene {
WindowGroup {
ContentView()
}
}
}

Option 3: Auto-Detect User Country

App.swift
import ReachuCore

@main
struct MyApp: App {
init() {
// Auto-detect country from device settings
let userCountry = Locale.current.region?.identifier ?? "US"
ConfigurationLoader.loadConfiguration(userCountryCode: userCountry)
}

var body: some Scene {
WindowGroup {
ContentView()
}
}
}

Option 4: Using Environment Variable

You can also set the country via environment variable:

**In Xcode:**Edit Scheme → Run → Arguments → Environment Variables

REACHU_USER_COUNTRY = US

Then load configuration normally:

ConfigurationLoader.loadConfiguration()
// Automatically reads REACHU_USER_COUNTRY if configured

Behavior

Market Available

  • SDK is enabled (isMarketAvailable = true)
  • All Reachu components display normally
  • Products load correctly
  • Full ecommerce functionality available

Market Unavailable

  • SDK is disabled (isMarketAvailable = false)
  • All Reachu components are automatically hidden - No API calls are made
  • Only a warning appears in logs (no user-facing errors)

Components That Auto-Hide

When isMarketAvailable = false, these components automatically hide:

  • RProductSlider - Completely hidden
  • RProductCard - Hidden (if using API data)
  • RCheckoutOverlay - Completely hidden
  • RFloatingCartIndicator - Completely hidden
  • RProductDetailOverlay - Completely hidden
  • Any component checking ReachuConfiguration.shared.shouldUseSDK

Manual Verification

You can manually check if the SDK is available:

ContentView.swift
import ReachuCore

struct ContentView: View {
var body: some View {
if ReachuConfiguration.shared.shouldUseSDK {
// SDK is available, show components
RProductSlider(...)
} else {
// SDK not available, show alternative
Text("Shopping not available in your region")
.foregroundColor(.secondary)
}
}
}

Using Helper View Wrapper

You can also use the helper wrapper to automatically hide components:

ContentView.swift
import ReachuUI

struct ContentView: View {
var body: some View {
VStack {
// Your app content
Text("Welcome")

// Wrap Reachu components
ReachuComponentWrapper {
RProductSlider(...)
RFloatingCartIndicator()
}
}
}
}

Or use the modifier:

RProductSlider(...)
.reachuOnly()

Complete Example

App.swift
import SwiftUI
import ReachuCore
import ReachuUI

@main
struct MyApp: App {
init() {
// Detect user country
let userCountry = getUserCountry()

// Load configuration with market check
ConfigurationLoader.loadConfiguration(userCountryCode: userCountry)
}

var body: some Scene {
WindowGroup {
ContentView()
}
}
}

struct ContentView: View {
@StateObject private var cartManager = CartManager()

var body: some View {
NavigationView {
ScrollView {
VStack {
// Your normal app content
Text("My App Content")

// Reachu components - automatically hidden if market unavailable
RProductSlider(
title: "Recommended Products",
layout: .cards,
currency: cartManager.currency,
country: cartManager.country
)
.environmentObject(cartManager)
}
}
}
.environmentObject(cartManager)
.overlay {
// Cart indicator also respects market availability
RFloatingCartIndicator()
.environmentObject(cartManager)
}
.sheet(isPresented: $cartManager.isCheckoutPresented) {
RCheckoutOverlay()
.environmentObject(cartManager)
}
}
}

func getUserCountry() -> String {
// Option 1: From device settings
if let region = Locale.current.region?.identifier {
return region
}

// Option 2: From your backend/API
// let userProfile = await fetchUserProfile()
// return userProfile.countryCode

// Option 3: Fallback
return "US"
}

Logs

Market Unavailable

 [Config] Checking market availability for country: XX
[Config] Market not available for XX - SDK disabled
[ReachuSDK] Market not available for country: XX - SDK disabled

Market Available

 [Config] Checking market availability for country: US
[Config] Market available for US - SDK enabled
[ReachuSDK] Market available for country: US - SDK enabled

Important Notes

  • **If no userCountryCode is provided:**SDK is enabled by default (backward compatible behavior)
  • **Async check:**Verification is asynchronous and doesn't block app initialization
  • **Network errors:**If there's a network error during verification, SDK is enabled by default (to not block usage)
  • **Only 404/NOT_FOUND errors disable SDK:**Other errors allow normal SDK operation

Integration with Campaign System

The market availability check works together with the campaign lifecycle system:

// Both checks must pass for components to show
if ReachuConfiguration.shared.shouldUseSDK &&
CampaignManager.shared.isCampaignActive {
// Show components
}

Components automatically respect both:

  1. Market availability
  2. Campaign active state

If either is false, components are hidden automatically.