Repository navigation
Expand file tree
/
Copy pathbrowser.ts
More file actions
35 lines (32 loc) · 1.71 KB
/
Copy pathbrowser.ts
File metadata and controls
35 lines (32 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { GOOGLE_ANALYTICS_TO_SPLIT, SPLIT_TO_GOOGLE_ANALYTICS } from '../utils/constants/browser';
import { IIntegration, IIntegrationManager, IIntegrationFactoryParams } from './types';
import { BrowserIntegration } from './ga/types';
import { pluggableIntegrationsManagerFactory } from './pluggable';
import { GoogleAnalyticsToSplit } from './ga/GoogleAnalyticsToSplit';
import { SplitToGoogleAnalytics } from './ga/SplitToGoogleAnalytics';
/**
* IntegrationsManager factory for the browser variant of the isomorphic JS SDK.
* The integrations manager instantiates integration modules, and bypass tracked events and impressions to them.
*
* @param integrations valid integration settings object for browser sdk
* @param params information of the Sdk factory instance that integrations can access to
*
* @returns integration manager or undefined if `integrations` are not present in settings.
*/
export function integrationsManagerFactory(
integrations: BrowserIntegration[],
params: IIntegrationFactoryParams
): IIntegrationManager | undefined {
// maps integration config items into integration factories to reuse the pluggable integration manager
const integrationFactories: Array<(params: IIntegrationFactoryParams) => IIntegration | void> = integrations
.map(integrationOptions => {
switch (integrationOptions.type) {
case GOOGLE_ANALYTICS_TO_SPLIT: return GoogleAnalyticsToSplit(integrationOptions);
case SPLIT_TO_GOOGLE_ANALYTICS: return SplitToGoogleAnalytics(integrationOptions);
}
})
.filter(integrationFactory => {
return integrationFactory && typeof integrationFactory === 'function';
});
return pluggableIntegrationsManagerFactory(integrationFactories, params);
}