Last updated

Settings

The FairShare SDK uses a layered configuration system where API settings provide defaults that can be overwritten by your UI code.

How Settings Work

┌─────────────────────────────────────────────────────────┐
│                    Your UI Code                         │
│         (highest priority - overrides everything)       │
├─────────────────────────────────────────────────────────┤
│                   Script Tag Attributes                 │
│            (data-fluid-shop, data-share-guid, etc.)     │
├─────────────────────────────────────────────────────────┤
│                    API Settings                         │
│             (defaults from your shop config)            │
└─────────────────────────────────────────────────────────┘

1. API Settings (Base Defaults)

When the SDK initializes, it fetches your shop's default configuration from the API. This includes:

  • Default language and country
  • Currency settings
  • Shop branding and display options
  • Available payment methods
// These settings come from your shop's API configuration
const settings = await window.FairShareSDK.fetchSettings();
console.log(settings.language);  // e.g., "en" (API default)
console.log(settings.country);   // e.g., "US" (API default)

2. Script Tag Overrides

Attributes on the SDK script tag can override API defaults:

<script
  id="fluid-cdn-script"
  src="https://assets.fluid.app/scripts/fluid-sdk/latest/web-widgets/index.js"
  data-fluid-shop="your-shop-id"
  data-share-guid="specific-affiliate-id"
></script>

3. UI Code Overrides (Highest Priority)

Your JavaScript code has the highest priority and overwrites any previous settings:

// This overrides whatever the API returned
await window.FairShareSDK.updateLocaleSettings({
  language: "es",
  country: "MX"
});

// Now the SDK uses Spanish/Mexico regardless of API defaults

Important: Settings Are Overwritten, Not Merged

When you update settings via UI code, they replace the API values—they don't merge with them.

// API returns: { language: "en", country: "US", currency: "USD" }

// Your code updates:
await window.FairShareSDK.updateLocaleSettings({
  country: "CA"
});

// Result: country is now "CA", language stays "en"
// (language wasn't overwritten because you didn't specify it)

When to Use Each Approach

ScenarioRecommended Approach
Default shop settingsConfigure in API/admin dashboard
Affiliate-specific overridesScript tag data-* attributes
User-selected preferencesUI code via updateLocaleSettings()
Dynamic runtime changesUI code via SDK functions

Settings Functions

FunctionDescription
fetchSettingsFetch fresh settings from the API
getSettingsGet cached settings (no API call)
getOrFetchSettingsGet from cache or fetch if needed
updateLocaleSettingsOverride language/country settings