UNPKG

@tryinhouse/react-native-inhouse-sdk

Version:
116 lines 3.97 kB
import { NativeModules, NativeEventEmitter, Platform, } from "react-native"; const { TrackingSDK } = NativeModules; // Check if the native module is available if (!TrackingSDK) { console.error("TrackingSDK native module is not available. Make sure the native module is properly linked."); } class TrackingSDKManager { constructor() { this.eventEmitter = null; this.listeners = []; this.isAvailable = false; if (!TrackingSDK) { console.error("TrackingSDK native module is not available. Make sure the native module is properly linked."); this.isAvailable = false; return; } try { // Only create NativeEventEmitter if the module is available this.eventEmitter = new NativeEventEmitter(TrackingSDK); this.isAvailable = true; } catch (error) { console.error("Failed to create NativeEventEmitter for TrackingSDK:", error); this.isAvailable = false; } } checkAvailability() { if (!this.isAvailable) { throw new Error("TrackingSDK native module is not available. Make sure the native module is properly linked."); } } initialize(projectToken, tokenId, shortLinkDomain, serverUrl, enableDebugLogging = false) { this.checkAvailability(); return TrackingSDK.initialize(projectToken, tokenId, shortLinkDomain, serverUrl, enableDebugLogging); } onAppResume() { this.checkAvailability(); return TrackingSDK.onAppResume(); } onNewURL(url) { this.checkAvailability(); if (Platform.OS === "ios") { return TrackingSDK.onNewURL(url); } return Promise.resolve(); } trackAppOpen(shortLink) { this.checkAvailability(); return TrackingSDK.trackAppOpen(shortLink); } trackSessionStart(shortLink) { this.checkAvailability(); return TrackingSDK.trackSessionStart(shortLink); } trackShortLinkClick(shortLink, deepLink) { this.checkAvailability(); return TrackingSDK.trackShortLinkClick(shortLink, deepLink); } getInstallReferrer() { this.checkAvailability(); return TrackingSDK.getInstallReferrer(); } fetchInstallReferrer() { this.checkAvailability(); return TrackingSDK.fetchInstallReferrer(); } resetFirstInstall() { this.checkAvailability(); return TrackingSDK.resetFirstInstall(); } addCallbackListener(callback) { this.checkAvailability(); if (!this.eventEmitter) { throw new Error("Event emitter is not available"); } const subscription = this.eventEmitter.addListener("onSdkCallback", callback); this.listeners.push(subscription); return subscription; } removeCallbackListener(subscription) { subscription.remove(); const index = this.listeners.indexOf(subscription); if (index > -1) { this.listeners.splice(index, 1); } } removeAllListeners() { this.listeners.forEach((subscription) => subscription.remove()); this.listeners = []; } // Thumbmark additions getFingerprint() { this.checkAvailability(); if (Platform.OS === "android") { return TrackingSDK.getFingerprint(); } return Promise.resolve(""); } getFingerprintId(algorithm) { this.checkAvailability(); if (Platform.OS === "android") { return TrackingSDK.getFingerprintId(algorithm); } return Promise.resolve(""); } } // Create a singleton instance with proper error handling let trackingSDKInstance = null; try { trackingSDKInstance = new TrackingSDKManager(); } catch (error) { console.error("Failed to initialize TrackingSDK:", error); } export default trackingSDKInstance; //# sourceMappingURL=index.js.map