UNPKG

@aws-amplify/analytics

Version:

Analytics category of aws-amplify

47 lines (42 loc) • 1.35 kB
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import { AnalyticsAction, resolveCtxArgs, } from '@aws-amplify/core/internals/utils'; import { AmplifyContext, ConsoleLogger } from '@aws-amplify/core'; import { getEventBuffer, resolveConfig } from '../utils'; import { getAnalyticsUserAgentString, resolveCredentials, } from '../../../utils'; const logger = new ConsoleLogger('Personalize'); export function flushEvents(ctx: AmplifyContext): void; /** * Flushes all buffered Personalize events to the service. * * @note * This API will make a best-effort attempt to flush events from the buffer. Events recorded immediately after invoking * this API may not be included in the flush. */ export function flushEvents(): void; export function flushEvents(...args: any[]): void { const [ctx] = resolveCtxArgs<[]>(args); const { region, flushSize, bufferSize, flushInterval } = resolveConfig(ctx); resolveCredentials(ctx) .then(({ credentials, identityId }) => getEventBuffer({ region, flushSize, flushInterval, bufferSize, credentials, identityId, userAgentValue: getAnalyticsUserAgentString(AnalyticsAction.Record), }), ) .then(eventBuffer => eventBuffer.flushAll()) .catch(e => { logger.warn('Failed to flush events', e); }); }