/** * Native module interface for BigCrunch Ads * This is the bridge to the native Android/iOS implementation */ import { NativeModules, NativeEventEmitter, Platform } from 'react-native'; import type { InitializationOptions, AdRequestOptions, SessionInfo, DeviceContext, AppConfig, ScreenViewOptions } from './types'; // Type definition for the native module export interface NativeBigCrunchAdsModule { // Initialization initialize(options: InitializationOptions): Promise; isInitialized(): Promise; // Configuration getAppConfig(): Promise; refreshConfig(): Promise; // Screen tracking trackScreenView(screenName: string, options: ScreenViewOptions | null): Promise; // Interstitial ads loadInterstitial(options: AdRequestOptions): Promise; showInterstitial(placementId: string): Promise; isInterstitialLoaded(placementId: string): Promise; destroyInterstitial(placementId: string): Promise; // Rewarded ads loadRewarded(options: AdRequestOptions): Promise; showRewarded(placementId: string): Promise; isRewardedLoaded(placementId: string): Promise; destroyRewarded(placementId: string): Promise; // Session management getSessionInfo(): Promise; startNewSession(): Promise; // Device context getDeviceContext(): Promise; // Privacy setGdprConsent(consent: string): Promise; setCcpaString(ccpaString: string): Promise; setCoppaCompliant(isCompliant: boolean): Promise; // Account type setAccountType(accountType: string): Promise; // Debug setDebugMode(enabled: boolean): Promise; addTestDevice(deviceId: string): Promise; removeTestDevice(deviceId: string): Promise; getTestDevices(): Promise; // UTM Attribution setUTMParameters(params: { source?: string; medium?: string; campaign?: string; term?: string; content?: string; }): Promise; clearUTMParameters(): Promise; } // Get the native module const { BigCrunchAdsModule } = NativeModules; if (!BigCrunchAdsModule) { const errorMessage = Platform.select({ ios: 'BigCrunchAdsModule native module is not available on iOS. Make sure you have run `pod install` and rebuilt the app.', android: 'BigCrunchAdsModule native module is not available on Android. Make sure you have rebuilt the app.', default: 'BigCrunchAdsModule native module is not available. Make sure the library is properly linked.', }); throw new Error(errorMessage); } // Export the native module with proper typing export const NativeBigCrunchAds = BigCrunchAdsModule as NativeBigCrunchAdsModule; // Export the event emitter for the native module export const BigCrunchAdsEventEmitter = new NativeEventEmitter(BigCrunchAdsModule); // Event names used by the native module export const NativeEventNames = { // Banner events BANNER_AD_LOADED: 'BigCrunchBannerAdLoaded', BANNER_AD_FAILED_TO_LOAD: 'BigCrunchBannerAdFailedToLoad', BANNER_AD_IMPRESSION: 'BigCrunchBannerAdImpression', BANNER_AD_CLICKED: 'BigCrunchBannerAdClicked', BANNER_AD_OPENED: 'BigCrunchBannerAdOpened', BANNER_AD_CLOSED: 'BigCrunchBannerAdClosed', BANNER_AD_REVENUE: 'BigCrunchBannerAdRevenue', BANNER_AD_VIEWABLE: 'BigCrunchBannerAdViewable', // Interstitial events INTERSTITIAL_AD_LOADED: 'BigCrunchInterstitialAdLoaded', INTERSTITIAL_AD_FAILED_TO_LOAD: 'BigCrunchInterstitialAdFailedToLoad', INTERSTITIAL_AD_FAILED_TO_SHOW: 'BigCrunchInterstitialAdFailedToShow', INTERSTITIAL_AD_IMPRESSION: 'BigCrunchInterstitialAdImpression', INTERSTITIAL_AD_CLICKED: 'BigCrunchInterstitialAdClicked', INTERSTITIAL_AD_OPENED: 'BigCrunchInterstitialAdOpened', INTERSTITIAL_AD_CLOSED: 'BigCrunchInterstitialAdClosed', /** Reserved: not currently emitted by the native SDKs (revenue is tracked natively via ILRD) */ INTERSTITIAL_AD_REVENUE: 'BigCrunchInterstitialAdRevenue', // Rewarded events REWARDED_AD_LOADED: 'BigCrunchRewardedAdLoaded', REWARDED_AD_FAILED_TO_LOAD: 'BigCrunchRewardedAdFailedToLoad', REWARDED_AD_FAILED_TO_SHOW: 'BigCrunchRewardedAdFailedToShow', REWARDED_AD_IMPRESSION: 'BigCrunchRewardedAdImpression', REWARDED_AD_CLICKED: 'BigCrunchRewardedAdClicked', REWARDED_AD_OPENED: 'BigCrunchRewardedAdOpened', REWARDED_AD_CLOSED: 'BigCrunchRewardedAdClosed', /** Reserved: not currently emitted by the native SDKs (revenue is tracked natively via ILRD) */ REWARDED_AD_REVENUE: 'BigCrunchRewardedAdRevenue', REWARDED_AD_EARNED: 'BigCrunchRewardedAdEarned', // Configuration events CONFIG_UPDATED: 'BigCrunchConfigUpdated', CONFIG_FAILED: 'BigCrunchConfigFailed', // Session events SESSION_STARTED: 'BigCrunchSessionStarted', /** Reserved: not currently emitted by the native SDKs */ SESSION_ENDED: 'BigCrunchSessionEnded', } as const;