Skip to main content

trackEventLegacy

Upgather Analytics


Upgather Analytics / trackEventLegacy

Function: trackEventLegacy()

trackEventLegacy(props, apiKeyOverride?): Promise<void>

Track an analytics event using the legacy endpoint with default configuration. Supports both regular and API key authentication methods.

Parameters

props

TrackEventProps

Event properties to track

apiKeyOverride?

string

Optional API key to override the cached key

Returns

Promise<void>

Promise that resolves when the event is successfully tracked

Remarks

This function uses the legacy endpoint (/${eventId}/analytics) for backward compatibility. For new applications, use the standard trackEvent function instead.

It supports both regular and API key authentication methods:

  • If an API key is provided (either in this call or previously cached), it will use that key for authentication via the x-api-key header
  • Otherwise, it falls back to regular authentication

Example

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

// Using API key authentication
await trackEventLegacy(
{
eventId: 'homepage-visit',
metricType: MetricType.pageview,
payload: {
url: 'https://app.upgather.com/',
referrer: 'https://google.com',
},
organizationId: 'org-example-123'
},
'da2-7ekeutfuafga5fqlowgydwsq2u'
);

// Or set API key once and reuse
trackEventLegacy.setApiKey('da2-7ekeutfuafga5fqlowgydwsq2u');
await trackEventLegacy({
eventId: 'homepage-visit',
metricType: MetricType.pageview,
payload: { url: 'https://app.upgather.com/' },
organizationId: 'org-example-123'
});

Throws

If the event is invalid or the API request fails