Skip to main content

AnalyticsClientFactory

Upgather Analytics


Upgather Analytics / AnalyticsClientFactory

Class: AnalyticsClientFactory

Factory for creating AnalyticsClient instances.

Remarks​

This factory class provides methods to create properly configured AnalyticsClient instances with appropriate SDK integration. It handles the configuration of authentication, rate limiting, circuit breaker, and other settings based on the provided configuration.

This is the recommended way to create AnalyticsClient instances, as it ensures that all required dependencies are properly configured.

Example​

import {
AnalyticsClientFactory,
MetricType
} from '@upgather/analytics';

// Simple usage with just a base URL and auth token
const client = AnalyticsClientFactory.createClient(
'https://api.upgather.com/v1',
'your-auth-token'
);

// Advanced usage with configuration object
const clientWithConfig = AnalyticsClientFactory.createClient({
baseUrl: 'https://api.upgather.com/v1',
authToken: 'your-auth-token',
defaultEventId: 'aitalks26',
rateLimiting: {
enabled: true,
requestsPerSecond: 10
}
});

// Create a client for a specific event
const eventClient = AnalyticsClientFactory.createClientForEvent(
'aitalks26',
'https://api.upgather.com/v1'
);

Constructors​

new AnalyticsClientFactory()​

new AnalyticsClientFactory(): AnalyticsClientFactory

Returns​

AnalyticsClientFactory

Methods​

createClient()​

static createClient(configOrBaseUrl, authToken?): AnalyticsClient

Create a new AnalyticsClient with the specified configuration.

Parameters​

configOrBaseUrl​

Either a complete config object or the base URL

string | AnalyticsConfig

authToken?​

string

Optional auth token (when using the baseUrl overload)

Returns​

AnalyticsClient

A fully configured AnalyticsClient instance

Remarks​

This method creates a new AnalyticsClient with the specified configuration. It accepts either a complete configuration object or a base URL and auth token.

When providing just a baseUrl and authToken, a configuration object is created with default values for other settings.


createClientForEvent()​

static createClientForEvent(eventId, baseUrl?, authToken?): AnalyticsClient

Create a new AnalyticsClient specifically for a conference or event.

Parameters​

eventId​

string

The identifier for the conference or event

baseUrl?​

string

Optional base URL for the API

authToken?​

string

Optional auth token for API requests

Returns​

AnalyticsClient

A fully configured AnalyticsClient instance with the event ID set as default

Remarks​

This method creates a client with the specified event ID as the default, which means you won't need to specify the eventId in subsequent tracking calls.

The eventId should be alphanumeric and can include hyphens, but should not include spaces or special characters.

This is particularly useful for event-specific apps or sites where all tracking will be for the same event.

Example​

// Create a client for the AI Talks 2026 event
const client = AnalyticsClientFactory.createClientForEvent('aitalks26');

// Now you can track events without specifying the eventId each time
await client.trackEvent({
metricType: MetricType.pageview,
payload: { url: 'https://aitalks26.example.com/agenda' }
});

createSdkApiClient()​

static createSdkApiClient(config): ApiClient

Create the SDK API client with appropriate configuration.

Parameters​

config​

AnalyticsConfig

Configuration options

Returns​

ApiClient

A configured ApiClient instance

Remarks​

This method creates an ApiClient from the SDK with the specified configuration. It uses configureSdkFactory to create a properly configured factory, then uses that factory to create the ApiClient.

This method is used internally by AnalyticsClient but is public to allow advanced use cases where direct access to the ApiClient is needed.

Deprecated​

Use createSdkApiClient from utils/apiClientFactory instead.