import { Analytics, Event, MessageBroker } from '../types'; // Only pickups and clicks are supported for now. This is just to warn the // developer in development, the device runtime will validate the event type // and ignore unsupported events. const supportedEvents = ['pickup', 'click']; const supportedEventsText = supportedEvents.map((x) => `'${x}'`).join(', '); // The Analytics API allows apps to send analytics events. export function initializeAnalytics(messageBroker: MessageBroker): Analytics { return { track(event: Event) { if (!supportedEvents.includes(event.type)) { console.warn( `Raydiant SDK: Unsupported event type '${event.type}' — only ${supportedEventsText} are supported.` ); return; } if (!event.source) { console.warn( `Raydiant SDK: Event source is missing from event type '${event.type}'.` ); return; } messageBroker.sendMessage('analytics-event', event); }, }; }