Refactor analytics event handling and manager setup
Updated event handling in `analytics-provider.tsx` to return results, enhancing consistency. Added a new function `registerActiveServices` in `analytics-manager.ts` for initializing active services, streamlining provider setup. Clarified types for `AnalyticsProviderFactory` to accept optional configuration.
This commit is contained in:
@@ -22,6 +22,27 @@ export function createAnalyticsManager<T extends string, Config extends object>(
|
||||
return Array.from(activeServices.values());
|
||||
};
|
||||
|
||||
const registerActiveServices = (
|
||||
options: CreateAnalyticsManagerOptions<T, Config>,
|
||||
) => {
|
||||
Object.keys(options.providers).forEach((provider) => {
|
||||
const providerKey = provider as keyof typeof options.providers;
|
||||
const factory = options.providers[providerKey];
|
||||
|
||||
if (!factory) {
|
||||
console.warn(
|
||||
`Analytics provider '${provider}' not registered. Skipping initialization.`,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
activeServices.set(provider as T, factory());
|
||||
});
|
||||
};
|
||||
|
||||
registerActiveServices(options);
|
||||
|
||||
return {
|
||||
addProvider: (
|
||||
provider: T,
|
||||
|
||||
Reference in New Issue
Block a user