@aws-amplify/analytics
Version:
Analytics category of aws-amplify
1 lines • 4.3 kB
Source Map (JSON)
{"version":3,"file":"configureAutoTrack.mjs","sources":["../../../../../src/providers/kinesis/apis/configureAutoTrack.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { AnalyticsValidationErrorCode, assertValidationError, } from '../../../errors';\nimport { updateProviderTrackers, validateTrackerConfiguration, } from '../../../utils';\nimport { record } from './record';\n// Configured Tracker instances for Kinesis\nconst configuredTrackers = {};\n/**\n * Configures automatic event tracking for Kinesis. This API will automatically transmit an analytic event to the\n * configured Kinesis stream when configured events are detected within your application. This can include: DOM\n * element events (via the `event` tracker), session events (via the `session` tracker), and page view events (via\n * the `pageView` tracker).\n *\n * Auto-tracked events are recorded with a data payload of the shape `{ name: eventName, attributes }`.\n *\n * @remark Only session tracking is currently supported on React Native.\n *\n * @param {KinesisConfigureAutoTrackInput} input The input object to configure auto track behavior.\n *\n * @throws validation: {@link AnalyticsValidationErrorCode} - Thrown when the provided parameters or library\n * configuration is incorrect, or when `streamName` / `partitionKey` are missing while enabling a tracker.\n *\n * @example\n * ```ts\n * // Enable session tracking\n * configureAutoTrack({\n * enable: true,\n * type: 'session',\n * options: {\n * streamName: 'myKinesisStream',\n * partitionKey: 'myPartitionKey',\n * },\n * });\n * ```\n *\n * @example\n * ```ts\n * // Enable page view tracking for a single-page application\n * configureAutoTrack({\n * enable: true,\n * type: 'pageView',\n * options: {\n * streamName: 'myKinesisStream',\n * partitionKey: 'myPartitionKey',\n * appType: 'singlePage',\n * },\n * });\n * ```\n *\n * @example\n * ```ts\n * // Enable DOM element event tracking\n * configureAutoTrack({\n * enable: true,\n * type: 'event',\n * options: {\n * streamName: 'myKinesisStream',\n * partitionKey: 'myPartitionKey',\n * },\n * });\n * ```\n */\nexport const configureAutoTrack = (input) => {\n validateTrackerConfiguration(input);\n if (input.enable) {\n assertValidationError(!!input.options?.streamName, AnalyticsValidationErrorCode.NoStreamName);\n assertValidationError(!!input.options?.partitionKey, AnalyticsValidationErrorCode.NoPartitionKey);\n }\n // Callback that will emit an appropriate event to Kinesis when required by the Tracker\n const emitTrackingEvent = (eventName, attributes) => {\n record({\n streamName: input.options.streamName,\n partitionKey: input.options.partitionKey,\n data: {\n name: eventName,\n attributes,\n },\n });\n };\n // Initialize or update this provider's trackers. The 'kinesis' namespace keeps\n // page-view tracking state isolated from other providers (e.g. Pinpoint).\n updateProviderTrackers(input, emitTrackingEvent, configuredTrackers, 'kinesis');\n};\n"],"names":[],"mappings":";;;;;;;;;;AAAA;AACA;AAIA;AACA,MAAM,kBAAkB,GAAG,EAAE;AAC7B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,kBAAkB,GAAG,CAAC,KAAK,KAAK;AAC7C,IAAI,4BAA4B,CAAC,KAAK,CAAC;AACvC,IAAI,IAAI,KAAK,CAAC,MAAM,EAAE;AACtB,QAAQ,qBAAqB,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,UAAU,EAAE,4BAA4B,CAAC,YAAY,CAAC;AACrG,QAAQ,qBAAqB,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,YAAY,EAAE,4BAA4B,CAAC,cAAc,CAAC;AACzG,IAAI;AACJ;AACA,IAAI,MAAM,iBAAiB,GAAG,CAAC,SAAS,EAAE,UAAU,KAAK;AACzD,QAAQ,MAAM,CAAC;AACf,YAAY,UAAU,EAAE,KAAK,CAAC,OAAO,CAAC,UAAU;AAChD,YAAY,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC,YAAY;AACpD,YAAY,IAAI,EAAE;AAClB,gBAAgB,IAAI,EAAE,SAAS;AAC/B,gBAAgB,UAAU;AAC1B,aAAa;AACb,SAAS,CAAC;AACV,IAAI,CAAC;AACL;AACA;AACA,IAAI,sBAAsB,CAAC,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,SAAS,CAAC;AACnF;;;;"}