@aws-amplify/analytics
Version:
Analytics category of aws-amplify
51 lines (48 loc) • 2.4 kB
JavaScript
import '@aws-amplify/core/internals/utils';
import { assertValidationError } from '../../../errors/assertValidationError.mjs';
import { AnalyticsValidationErrorCode } from '../../../errors/validation.mjs';
import '../../../utils/eventBuffer/EventBuffer.mjs';
import { updateProviderTrackers } from '../../../utils/trackerHelpers.mjs';
import { validateTrackerConfiguration } from '../../../utils/trackerConfigHelpers.mjs';
import '../../../utils/deprecatePinpoint.mjs';
import { peekCtxArgs } from '../../../utils/peekCtxArgs.mjs';
import { record } from './record.mjs';
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// Configured Tracker instances for Kinesis Data Firehose
const configuredTrackers = {};
function configureAutoTrack(...args) {
// Peek the optional leading context WITHOUT falling back to the global
// context. The context is only needed when events are emitted; resolving it
// eagerly would (a) throw when trackers are configured before
// `Amplify.configure()` and (b) pin auto-tracked events to the configuration
// snapshot captured at setup time after a later `configure()` call.
const { ctx, input } = peekCtxArgs(args);
validateTrackerConfiguration(input);
if (input.enable) {
assertValidationError(!!input.options?.streamName, AnalyticsValidationErrorCode.NoStreamName);
}
// Callback that will emit an appropriate event to Kinesis Data Firehose when required by the Tracker.
// When no explicit context was supplied, `record` resolves the global context
// lazily at emit time so auto-tracked events follow the live configuration.
const emitTrackingEvent = (eventName, attributes) => {
const recordInput = {
streamName: input.options.streamName,
data: {
name: eventName,
attributes,
},
};
if (ctx) {
record(ctx, recordInput);
}
else {
record(recordInput);
}
};
// Initialize or update this provider's trackers. The 'kinesis-firehose' namespace
// keeps page-view tracking state isolated from other providers (e.g. Pinpoint).
updateProviderTrackers(input, emitTrackingEvent, configuredTrackers, 'kinesis-firehose');
}
export { configureAutoTrack };
//# sourceMappingURL=configureAutoTrack.mjs.map