Skip to content

API Reference

Complete reference for the FanFest SDK methods, types, and configuration options.

Global SDK Instance

The SDK is available globally as FanFestSDK:

javascript
// Global access after loading the SDK script
window.FanFestSDK.init({ ... });

// Or simply
FanFestSDK.init({ ... });

Methods

init(options)

Initialize the SDK with configuration options.

typescript
FanFestSDK.init(options: SDKConfig): void

Parameters:

Example:

javascript
FanFestSDK.init({
  apiKey: "your-api-key",
  clientId: "your-client-id",
  apiBase: "https://api.fanfest.vip",
  appOrigin: "https://fanfest.vip",
});

trackEvent(payload)

Track a custom event programmatically.

typescript
FanFestSDK.trackEvent(payload: TrackEventPayload): Promise<TrackEventResponse>

Parameters:

Returns:

  • Promise<TrackEventResponse> - Event processing result

Example:

javascript
const response = await FanFestSDK.trackEvent({
  action: "cta_click",
  description: "Hero CTA",
  externalObjectId: "hero-cta-1",
  metadata: {
    campaign: "BlackFriday",
  },
});

if (response.success) {
  console.log("Event tracked successfully");
}

login()

Initiate user authentication flow.

typescript
FanFestSDK.login(): Promise<void>

Example:

javascript
await FanFestSDK.login();

logout()

Log out the current user.

typescript
FanFestSDK.logout(): Promise<void>

Example:

javascript
await FanFestSDK.logout();

registerActionMapping(payload)

Register custom action mappings for event tracking.

typescript
FanFestSDK.registerActionMapping(payload: SDKActionRegistryPayload): void

Parameters:

  • payload - Action mapping configuration

Example:

javascript
FanFestSDK.registerActionMapping({
  action: "custom_click",
  channelActionId: "cta_click",
});

Types

SDKConfig

Configuration options for SDK initialization.

typescript
interface SDKConfig {
  apiKey: string; // Required: Your FanFest API key
  clientId: string; // Required: Your FanFest client ID
  apiBase?: string; // Optional: API endpoint (default: 'https://api.fanfest.vip')
  appOrigin?: string; // Optional: FanFest app origin (default: 'https://fanfest.vip')
  iframe?: {
    backgroundColor?: string; // Optional: Iframe background color
  };
  hostLoginFn?: () => void; // Optional: Triggers login on host website
  hostRewardsFn?: () => void; // Optional: Navigates to rewards page/section
}

Host Function Handlers

hostLoginFn - Host Website Login

Called when the SDK needs to trigger authentication on your host website:

javascript
FanFestSDK.init({
  apiKey: "your-api-key",
  clientId: "your-client-id",
  hostLoginFn: () => {
    // Trigger login on your host website
    window.location.href = "/login"; // Redirect to login page
    // or
    openLoginModal(); // Open login modal
    // or
    authStore.login(); // Trigger auth store login
  },
});

hostRewardsFn - Navigate to Rewards Section

Called when the SDK needs to navigate to your rewards page or section:

javascript
FanFestSDK.init({
  apiKey: "your-api-key",
  clientId: "your-client-id",
  hostRewardsFn: () => {
    // Navigate to your rewards page/section
    window.location.href = "/rewards"; // Redirect to rewards page
    // or
    router.push("/rewards"); // SPA navigation
    // or
    showRewardsSection(); // Show rewards section
  },
});

TrackEventPayload

Event data structure for tracking.

typescript
interface TrackEventPayload {
  action: string; // Event name (required)
  description?: string; // Human-readable description
  externalExperienceId?: string; // Experience/channel identifier
  externalObjectId?: string; // Object being interacted with
  location?: LocationData; // Geographic location
  metadata?: Record<string, string | number | boolean>; // Custom data
}

TrackEventResponse

Response from event tracking.

typescript
interface TrackEventResponse {
  success: boolean; // Whether the event was processed
  didReward: boolean; // Whether the user received a reward
  message?: string; // Optional success/error message
  rewardData?: RewardData; // Reward details (if applicable)
}

LocationData

Geographic location information.

typescript
interface LocationData {
  latitude: number; // Latitude coordinate
  longitude: number; // Longitude coordinate
  types?: string[]; // Location types
  raw?: string; // Raw location data
}

AuthData

Authentication data for SSO integration.

typescript
interface AuthData {
  token: string; // SSO token
  userId: string; // User identifier
  email?: string; // User email (optional)
  displayName?: string; // Display name (optional)
}

SDKActionRegistryPayload

Action mapping configuration.

typescript
interface SDKActionRegistryPayload {
  action: string; // Action name
  channelActionId: string; // Mapped channel action ID
}

Data Attributes

Core Attributes

AttributeTypeDescriptionExample
data-fanfest-trackstringEvent name to trackdata-fanfest-track="cta_click"
data-fanfest-onstringEvent trigger with modifiersdata-fanfest-on="click:prevent:once"
data-fanfest-descriptionstringHuman-readable descriptiondata-fanfest-description="Hero CTA"
data-fanfest-experience-idstringExperience identifierdata-fanfest-experience-id="homepage"
data-fanfest-object-idstringObject identifierdata-fanfest-object-id="hero-cta-1"

Metadata Attributes

Use data-fanfest-meta-* for custom metadata:

html
<button
  data-fanfest-track="purchase"
  data-fanfest-meta-campaign="BlackFriday"
  data-fanfest-meta-amount="99.99"
  data-fanfest-meta-currency="USD"
>
  Buy Now
</button>

Event Triggers

Supported Events

EventDescriptionUse Case
clickMouse click eventsButtons, links, CTAs
submitForm submissionContact forms, signups
renderElement visibilityView tracking, impressions

Event Modifiers

ModifierDescriptionExample
preventPrevent default behaviordata-fanfest-on="click:prevent"
onceFire only oncedata-fanfest-on="click:once"
stopStop event propagationdata-fanfest-on="click:stop"
captureUse capture phasedata-fanfest-on="click:capture"

Error Handling

Common Errors

ErrorCodeDescriptionSolution
Invalid SDK options-Configuration validation failedCheck required options
SDK not initialized-Called before init()Call init() first
API key not found-Missing API keyProvide valid API key
Invalid payload-Event data validation failedCheck payload structure

Debug Mode

Enable detailed logging:

javascript
FanFestSDK.init({
  apiKey: "your-api-key",
  clientId: "your-client-id",
  logLevel: "debug", // Enable detailed logging
});

Static Properties

embedElementId

typescript
FanFestSDK.embedElementId: string

Default ID for embed elements.

embedContainerId

typescript
FanFestSDK.embedContainerId: string

Default ID for embed containers.

Next Steps

Released under the MIT License.