@aws-amplify/analytics
Version:
Analytics category of aws-amplify
52 lines (49 loc) • 2.28 kB
JavaScript
import { ConsoleLogger, Hub } from '@aws-amplify/core';
import { resolveCtxArgs, AMPLIFY_SYMBOL, AnalyticsAction } from '@aws-amplify/core/internals/utils';
import { record as record$1 } from '@aws-amplify/core/internals/providers/pinpoint';
import { assertValidationError } from '../../../errors/assertValidationError.mjs';
import { AnalyticsValidationErrorCode } from '../../../errors/validation.mjs';
import '../../../utils/eventBuffer/EventBuffer.mjs';
import { isAnalyticsEnabled } from '../../../utils/statusHelpers.mjs';
import { getAnalyticsUserAgentString } from '../../../utils/userAgent.mjs';
import '../../../trackers/EventTracker.mjs';
import '../../../trackers/PageViewTracker.mjs';
import '../../../trackers/SessionTracker.mjs';
import '../../../utils/deprecatePinpoint.mjs';
import { resolveConfig } from '../utils/resolveConfig.mjs';
import { resolveCredentials } from '../utils/resolveCredentials.mjs';
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
const logger = new ConsoleLogger('Analytics');
function record(...args) {
const [ctx, input] = resolveCtxArgs(args);
const { appId, region, bufferSize, flushSize, flushInterval, resendLimit } = resolveConfig(ctx);
if (!isAnalyticsEnabled()) {
logger.debug('Analytics is disabled, event will not be recorded.');
return;
}
assertValidationError(!!input.name, AnalyticsValidationErrorCode.NoEventName);
resolveCredentials(ctx)
.then(({ credentials, identityId }) => {
Hub.dispatch('analytics', { event: 'record', data: input, message: 'Recording Analytics event' }, 'Analytics', AMPLIFY_SYMBOL);
record$1({
appId,
category: 'Analytics',
credentials,
event: input,
identityId,
region,
userAgentValue: getAnalyticsUserAgentString(AnalyticsAction.Record),
bufferSize,
flushSize,
flushInterval,
resendLimit,
});
})
.catch(e => {
// An error occurred while fetching credentials or persisting the event to the buffer
logger.warn('Failed to record event.', e);
});
}
export { record };
//# sourceMappingURL=record.mjs.map