/** * Copyright 2024-2026 Wingify Software Pvt. Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { getEventsBaseProperties, getSDKInitEventPayload, getSDKUsageStatsEventPayload, sendEvent, } from './NetworkUtil'; import { EventEnum } from '../enums/EventEnum'; import { ServiceContainer } from '../services/ServiceContainer'; import { UsageStatsUtil } from './UsageStatsUtil'; /** * Sends an init called event to Wingify. * This event is triggered when the init function is called. * @param settingsFetchTime - Time taken to fetch settings in milliseconds. * @param sdkInitTime - Time taken to initialize the SDK in milliseconds. * @param serviceContainer - The service container instance. */ export async function sendSdkInitEvent( settingsFetchTime: number, sdkInitTime: number, serviceContainer: ServiceContainer, ): Promise { const properties = getEventsBaseProperties(serviceContainer.getSettingsService(), EventEnum.INIT_CALLED); const payload = getSDKInitEventPayload( serviceContainer.getSettingsService(), EventEnum.INIT_CALLED, settingsFetchTime, sdkInitTime, ); if (serviceContainer.getBatchEventsQueue()) { serviceContainer.getBatchEventsQueue().enqueue(payload); return; } await sendEvent(serviceContainer, properties, payload, EventEnum.INIT_CALLED).catch(() => {}); } /** * Sends a usage stats event to Wingify. * This event is triggered when the SDK is initialized. * @param usageStatsAccountId - The account ID used for usage-stats reporting. * @param serviceContainer - The service container instance. * @param usageStatsUtil - The usage-stats payload builder. */ export async function sendSDKUsageStatsEvent( usageStatsAccountId: number, serviceContainer: ServiceContainer, usageStatsUtil: UsageStatsUtil, ): Promise { const properties = getEventsBaseProperties( serviceContainer.getSettingsService(), EventEnum.USAGE_STATS, null, null, true, usageStatsAccountId, ); const payload = getSDKUsageStatsEventPayload( serviceContainer.getSettingsService(), EventEnum.USAGE_STATS, usageStatsAccountId, usageStatsUtil, ); if (serviceContainer.getBatchEventsQueue()) { serviceContainer.getBatchEventsQueue().enqueue(payload); return; } await sendEvent(serviceContainer, properties, payload, EventEnum.USAGE_STATS).catch(() => {}); }