import { AutocaptureBindOptions, normalizeOptions, register, } from '@contentsquare/react-native-autocapture'; import { StartRecordingOptions } from "@contentsquare/react-native-autocapture/dist/core"; import { LogChannel, LogLevel } from '@heap/heap-javascript-bridge-support'; import { start as csqStart, getProductAnalyticsOptions } from '../core/csqCore'; import { Heap, HeapLogger } from '../heap'; import { ProductAnalyticsOptions } from '../types/types'; const getStartRecordingOptions = ( productAnalyticsOptions?: ProductAnalyticsOptions ): StartRecordingOptions | undefined => { if (!productAnalyticsOptions) { return undefined; } const { baseUrl, uploadInterval, clearEventPropertiesOnNewUser, resumePreviousSession, captureAdvertiserId, captureVendorId, disablePageviewAutocapture, disableInteractionAutocapture, disableInteractionTextCapture, disableInteractionAccessibilityLabelCapture, } = productAnalyticsOptions; return { baseUrl, uploadInterval, clearEventPropertiesOnNewUser, resumePreviousSession, captureAdvertiserId, captureVendorId, disablePageviewAutocapture, disableInteractionAutocapture, disableInteractionTextCapture, disableInteractionAccessibilityLabelCapture, }; }; const registerAutocapture = ( isDefaultOrOptions?: AutocaptureBindOptions | boolean ) => { const productAnalyticsOptions = getProductAnalyticsOptions(); const startRecordingOptions = getStartRecordingOptions(productAnalyticsOptions); if (productAnalyticsOptions?.enableRNAutocapture === false) { HeapLogger.warn( '[Autocapture] React Native autocapture registration skipped: enableRNAutocapture is set to false in configureProductAnalytics options' ); return; } register(Heap, HeapLogger, normalizeOptions(isDefaultOrOptions), new Date(), startRecordingOptions); }; /** * Start the SDK and automatically register autocapture if enabled. * This combines the functionality of start() and registerAutocapture(). */ export const startWithAutocapture = () => { csqStart(); registerAutocapture(true); }; export const logToConsole = () => Heap.logToConsole(); export const setLogChannel = (logChannel: LogChannel) => Heap.setLogChannel(logChannel); export const setLogLevel = (logLevel: LogLevel) => Heap.setLogLevel(logLevel); /** @internal */ export { registerAutocapture };