/** * Event types for BigCrunch Mobile Ads SDK */ import { AdError, AdRevenue, AdFormat } from './index'; /** * Base event data */ export interface BaseAdEvent { /** Placement ID */ placementId: string; /** Ad format */ format: AdFormat; /** Timestamp of the event */ timestamp: number; } /** * Ad loaded event */ export interface AdLoadedEvent extends BaseAdEvent { type: 'adLoaded'; /** Ad network that filled the ad */ adNetwork?: string; /** Ad unit ID */ adUnitId?: string; } /** * Ad failed to load event */ export interface AdFailedToLoadEvent extends BaseAdEvent { type: 'adFailedToLoad'; /** Error details */ error: AdError; } /** * Ad impression event */ export interface AdImpressionEvent extends BaseAdEvent { type: 'adImpression'; /** Ad network that served the impression */ adNetwork?: string; /** Unique impression ID (UUID) */ impressionId?: string; /** GAM ad unit path */ gamAdUnit?: string; /** Ad size (e.g., "320x50") */ adSize?: string; /** Auction ID from S2S bid request */ auctionId?: string; /** Winning bidder name */ bidder?: string; /** Bid price in CPM */ bidPriceCpm?: number; /** Advertiser ID from GAM metadata */ advertiserId?: string; /** Campaign ID from GAM metadata (not available in mobile SDKs) */ campaignId?: string; /** Line item ID from GAM metadata (not available in mobile SDKs) */ lineItemId?: string; /** Creative ID from GAM metadata */ creativeId?: string; /** Refresh count for this placement */ refreshCount?: number; /** Demand channel (e.g., "S2S Header", "GAM Direct") */ demandChannel?: string; } /** * Ad clicked event */ export interface AdClickedEvent extends BaseAdEvent { type: 'adClicked'; } /** * Ad opened event (for overlays/modals) */ export interface AdOpenedEvent extends BaseAdEvent { type: 'adOpened'; } /** * Ad closed event */ export interface AdClosedEvent extends BaseAdEvent { type: 'adClosed'; } /** * Ad revenue event (ILRD) */ export interface AdRevenueEvent extends BaseAdEvent { type: 'adRevenue'; /** Revenue data */ revenue: AdRevenue; } /** * Ad viewable event */ export interface AdViewableEvent extends BaseAdEvent { type: 'adViewable'; /** Duration in view (milliseconds) */ viewDuration?: number; /** Percentage of ad visible */ visiblePercentage?: number; } /** * Rewarded ad events */ export interface RewardedAdEarnedEvent extends BaseAdEvent { type: 'rewardEarned'; /** Reward type */ rewardType: string; /** Reward amount */ rewardAmount: number; } /** * Union type of all ad events */ export type AdEvent = | AdLoadedEvent | AdFailedToLoadEvent | AdImpressionEvent | AdClickedEvent | AdOpenedEvent | AdClosedEvent | AdRevenueEvent | AdViewableEvent | RewardedAdEarnedEvent; /** * Event listener callback */ export type AdEventListener = (event: T) => void; /** * Event subscription */ export interface EventSubscription { /** Remove the event listener */ remove: () => void; } /** * Analytics event for backend * * Note: This represents the legacy event format. The SDK now uses web schema events * with flattened structure (PageViewEvent, ImpressionEvent, ClickEvent, etc.) * * @deprecated Use web schema event types instead */ export interface AnalyticsEvent { /** Event type */ eventType: 'screen_view' | 'ad_request' | 'ad_impression' | 'ad_click' | 'ad_revenue' | 'ad_viewable' | 'session_start' | 'session_end'; /** Event timestamp (milliseconds since epoch) */ timestamp: number; /** Session ID */ sessionId: string; /** Event-specific data */ data: Record; /** Device context */ deviceContext?: Partial; } /** * Web schema common fields (present in all events) */ export interface WebSchemaCommonFields { /** Payload version identifier */ payloadVersion: string; /** Config version from backend */ configVersion?: string; /** Event timestamp in ISO 8601 format (e.g., "2025-01-15T10:30:00Z") */ browserTimestamp: string; /** Session ID (UUID) */ sessionId: string; /** User ID (UUID, persistent across sessions) */ userId: string; /** Property ID from BigCrunch dashboard */ propertyId: string; /** True if this is user's first session */ newUser: boolean; /** Current page/screen ID (UUID) */ pageId: string; /** Number of page views in current session */ sessionDepth: number; /** Browser/SDK identifier (e.g., "BigCrunch iOS SDK 1.0.0") */ browser: string; /** Device type (e.g., "iPhone 14", "Samsung Galaxy S21") */ device: string; /** Operating system (e.g., "iOS 16.0", "Android 13") */ os: string; /** Country code (ISO 3166-1 alpha-2, e.g., "US") */ country: string; /** Region/state code */ region: string; /** Session attribution source */ sessionSource: string; /** Session attribution medium */ sessionMedium: string; /** UTM source parameter */ utmSource?: string; /** UTM medium parameter */ utmMedium?: string; /** UTM campaign parameter */ utmCampaign?: string; /** UTM term parameter */ utmTerm?: string; /** UTM content parameter */ utmContent?: string; /** Google Click ID for attribution */ gclid?: string; /** Facebook Click ID for attribution */ fbclid?: string; } /** * Page view event (web schema) * Sent to /pageviews endpoint */ export interface PageViewEvent extends WebSchemaCommonFields { /** Screen/page name */ screenName: string; /** Referrer (previous screen) */ referrer?: string; } /** * Impression event (web schema) * Sent to /impressions endpoint * Consolidates ad request, impression, and revenue tracking */ export interface ImpressionEvent extends WebSchemaCommonFields { /** Unique impression ID (UUID) */ impressionId: string; /** Placement identifier */ placementId: string; /** GAM ad unit path */ gamAdUnit: string; /** Ad format (banner, interstitial, rewarded) */ format: string; /** Auction ID from S2S bid request */ auctionId?: string; /** Refresh count for this placement */ refreshCount?: number; /** Winning bidder name */ bidder?: string; /** Ad size (e.g., "320x50") */ adSize?: string; /** Bid price/revenue in CPM */ bidPriceCpm?: number; /** Floor price */ floorPrice?: number; /** Minimum bid to win */ minBidToWin?: number; /** Advertiser ID from GAM */ advertiserId?: string; /** Campaign ID from GAM (not available in mobile SDKs) */ campaignId?: string; /** Line item ID from GAM (not available in mobile SDKs) */ lineItemId?: string; /** Creative ID from GAM response */ creativeId?: string; /** Amazon bid data */ amznBid?: string; /** Amazon price data */ amznPrice?: string; /** Demand type (banner, video, etc.) */ demandType?: string; /** Demand channel (e.g., "S2S Header", "GAM Direct") */ demandChannel?: string; } /** * Click event (web schema) * Sent to /clicks endpoint */ export interface ClickEvent extends WebSchemaCommonFields { /** Reference to the impression that was clicked */ impressionId: string; /** Placement identifier */ placementId: string; /** Ad format */ format: string; } /** * Viewability event (web schema) * Sent to /viewability endpoint */ export interface ViewabilityEvent extends WebSchemaCommonFields { /** Reference to the impression */ impressionId: string; /** Placement identifier */ placementId: string; /** Ad format */ format: string; /** Time ad was viewable in milliseconds */ viewableTimeMs: number; /** Percentage of ad that was visible */ percentVisible: number; } /** * Engagement event (web schema) * Sent to /engagement endpoint */ export interface EngagementEvent extends WebSchemaCommonFields { /** Time actively engaged in seconds */ engagedTime: number; /** Total time on page/screen in seconds */ timeOnPage: number; } /** * Screen view event data */ export interface ScreenViewData { /** Screen name */ screenName: string; /** Screen class/component name */ screenClass?: string; /** Previous screen */ previousScreen?: string; } /** * Device context (imported from index) */ import { DeviceContext } from './index';