UNPKG

@aws-amplify/analytics

Version:

Analytics category of aws-amplify

1 lines 3.76 kB
{"version":3,"file":"record.mjs","sources":["../../../../../src/providers/pinpoint/apis/record.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { ConsoleLogger, Hub } from '@aws-amplify/core';\nimport { AMPLIFY_SYMBOL, AnalyticsAction, } from '@aws-amplify/core/internals/utils';\nimport { record as recordCore } from '@aws-amplify/core/internals/providers/pinpoint';\nimport { AnalyticsValidationErrorCode, assertValidationError, } from '../../../errors';\nimport { getAnalyticsUserAgentString, isAnalyticsEnabled, } from '../../../utils';\nimport { resolveConfig, resolveCredentials } from '../utils';\nconst logger = new ConsoleLogger('Analytics');\n/**\n * Records an Analytic event to Pinpoint. Events will be buffered and periodically sent to Pinpoint.\n *\n * @param params The input object used to construct the request.\n *\n * @throws validation: {@link AnalyticsValidationErrorCode} - Thrown when the provided parameters or library\n * configuration is incorrect.\n *\n * @example\n * ```ts\n * // Send an event to Pinpoint\n * record({ name: eventName })\n * ```\n *\n * @example\n * ```ts\n * // Send an event to Pinpoint with metrics & custom attributes\n * record({\n * name: eventName,\n * attributes: {\n * 'my-attribute': attributeValue\n * },\n * metrics: {\n * 'my-metric': metricValue\n * }\n * })\n * ```\n */\nexport const record = (input) => {\n const { appId, region, bufferSize, flushSize, flushInterval, resendLimit } = resolveConfig();\n if (!isAnalyticsEnabled()) {\n logger.debug('Analytics is disabled, event will not be recorded.');\n return;\n }\n assertValidationError(!!input.name, AnalyticsValidationErrorCode.NoEventName);\n resolveCredentials()\n .then(({ credentials, identityId }) => {\n Hub.dispatch('analytics', { event: 'record', data: input, message: 'Recording Analytics event' }, 'Analytics', AMPLIFY_SYMBOL);\n recordCore({\n appId,\n category: 'Analytics',\n credentials,\n event: input,\n identityId,\n region,\n userAgentValue: getAnalyticsUserAgentString(AnalyticsAction.Record),\n bufferSize,\n flushSize,\n flushInterval,\n resendLimit,\n });\n })\n .catch(e => {\n // An error occured while fetching credentials or persisting the event to the buffer\n logger.warn('Failed to record event.', e);\n });\n};\n"],"names":["recordCore"],"mappings":";;;;;;;;;;;;;;AAAA;AACA;AAOA,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,WAAW,CAAC;AAC7C;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,MAAM,GAAG,CAAC,KAAK,KAAK;AACjC,IAAI,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,aAAa,EAAE;AAChG,IAAI,IAAI,CAAC,kBAAkB,EAAE,EAAE;AAC/B,QAAQ,MAAM,CAAC,KAAK,CAAC,oDAAoD,CAAC;AAC1E,QAAQ;AACR,IAAI;AACJ,IAAI,qBAAqB,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,4BAA4B,CAAC,WAAW,CAAC;AACjF,IAAI,kBAAkB;AACtB,SAAS,IAAI,CAAC,CAAC,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK;AAC/C,QAAQ,GAAG,CAAC,QAAQ,CAAC,WAAW,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,2BAA2B,EAAE,EAAE,WAAW,EAAE,cAAc,CAAC;AACtI,QAAQA,QAAU,CAAC;AACnB,YAAY,KAAK;AACjB,YAAY,QAAQ,EAAE,WAAW;AACjC,YAAY,WAAW;AACvB,YAAY,KAAK,EAAE,KAAK;AACxB,YAAY,UAAU;AACtB,YAAY,MAAM;AAClB,YAAY,cAAc,EAAE,2BAA2B,CAAC,eAAe,CAAC,MAAM,CAAC;AAC/E,YAAY,UAAU;AACtB,YAAY,SAAS;AACrB,YAAY,aAAa;AACzB,YAAY,WAAW;AACvB,SAAS,CAAC;AACV,IAAI,CAAC;AACL,SAAS,KAAK,CAAC,CAAC,IAAI;AACpB;AACA,QAAQ,MAAM,CAAC,IAAI,CAAC,yBAAyB,EAAE,CAAC,CAAC;AACjD,IAAI,CAAC,CAAC;AACN;;;;"}