@aws-amplify/analytics 7.0.1-preview-testing.034e780.0 → 7.0.1-server-generate-client.1e317a1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/kinesis/package.json +7 -0
- package/kinesis-firehose/package.json +7 -0
- package/lib/apis/disable.d.ts +8 -0
- package/lib/apis/disable.js +14 -0
- package/lib/apis/enable.d.ts +7 -0
- package/lib/apis/enable.js +13 -0
- package/lib/apis/index.d.ts +2 -0
- package/lib/apis/index.js +9 -0
- package/lib/errors/AnalyticsError.d.ts +2 -2
- package/lib/errors/assertValidationError.d.ts +1 -1
- package/lib/errors/assertValidationError.js +7 -3
- package/lib/errors/validation.d.ts +5 -2
- package/lib/errors/validation.js +16 -4
- package/lib/index.d.ts +2 -1
- package/lib/index.js +6 -1
- package/lib/providers/kinesis/apis/flushEvents.d.ts +8 -0
- package/lib/providers/kinesis/apis/flushEvents.js +38 -0
- package/lib/providers/kinesis/apis/index.d.ts +2 -0
- package/lib/providers/kinesis/apis/index.js +9 -0
- package/lib/providers/kinesis/apis/record.d.ts +2 -0
- package/lib/providers/kinesis/apis/record.js +48 -0
- package/lib/providers/kinesis/index.d.ts +1 -0
- package/lib/providers/kinesis/index.js +8 -0
- package/lib/providers/kinesis/types/buffer.d.ts +15 -0
- package/lib/providers/kinesis/types/buffer.js +4 -0
- package/lib/providers/kinesis/types/index.d.ts +2 -0
- package/lib/providers/kinesis/types/index.js +4 -0
- package/lib/providers/kinesis/types/inputs.d.ts +6 -0
- package/lib/providers/kinesis/types/inputs.js +4 -0
- package/lib/providers/kinesis/utils/constants.d.ts +6 -0
- package/lib/providers/kinesis/utils/constants.js +11 -0
- package/lib/providers/kinesis/utils/getEventBuffer.d.ts +3 -0
- package/lib/providers/kinesis/utils/getEventBuffer.js +103 -0
- package/lib/providers/kinesis/utils/resolveConfig.d.ts +7 -0
- package/lib/providers/kinesis/utils/resolveConfig.js +24 -0
- package/lib/providers/kinesis-firehose/apis/flushEvents.d.ts +8 -0
- package/lib/providers/kinesis-firehose/apis/flushEvents.js +37 -0
- package/lib/providers/kinesis-firehose/apis/index.d.ts +2 -0
- package/lib/providers/kinesis-firehose/apis/index.js +9 -0
- package/lib/providers/kinesis-firehose/apis/record.d.ts +2 -0
- package/lib/providers/kinesis-firehose/apis/record.js +45 -0
- package/lib/providers/kinesis-firehose/index.d.ts +1 -0
- package/lib/providers/kinesis-firehose/index.js +8 -0
- package/lib/providers/kinesis-firehose/types/buffer.d.ts +15 -0
- package/lib/providers/kinesis-firehose/types/index.d.ts +2 -0
- package/lib/providers/kinesis-firehose/types/index.js +4 -0
- package/lib/providers/kinesis-firehose/types/inputs.d.ts +5 -0
- package/lib/providers/kinesis-firehose/types/inputs.js +4 -0
- package/lib/providers/kinesis-firehose/utils/constants.d.ts +6 -0
- package/lib/providers/kinesis-firehose/utils/constants.js +11 -0
- package/lib/providers/kinesis-firehose/utils/getEventBuffer.d.ts +3 -0
- package/lib/providers/kinesis-firehose/utils/getEventBuffer.js +100 -0
- package/lib/providers/kinesis-firehose/utils/index.d.ts +2 -0
- package/lib/providers/kinesis-firehose/utils/index.js +9 -0
- package/lib/providers/kinesis-firehose/utils/resolveConfig.d.ts +7 -0
- package/lib/providers/kinesis-firehose/utils/resolveConfig.js +24 -0
- package/lib/providers/personalize/apis/flushEvents.d.ts +8 -0
- package/lib/providers/personalize/apis/flushEvents.js +36 -0
- package/lib/providers/personalize/apis/index.d.ts +2 -0
- package/lib/providers/personalize/apis/index.js +9 -0
- package/lib/providers/personalize/apis/record.d.ts +2 -0
- package/lib/providers/personalize/apis/record.js +87 -0
- package/lib/providers/personalize/index.d.ts +1 -0
- package/lib/providers/personalize/index.js +8 -0
- package/lib/providers/personalize/types/buffer.d.ts +16 -0
- package/lib/providers/personalize/types/buffer.js +4 -0
- package/lib/providers/personalize/types/index.d.ts +2 -0
- package/lib/providers/personalize/types/index.js +4 -0
- package/lib/providers/personalize/types/inputs.d.ts +7 -0
- package/lib/providers/personalize/types/inputs.js +4 -0
- package/lib/providers/personalize/utils/autoTrackMedia.d.ts +10 -0
- package/lib/providers/personalize/utils/autoTrackMedia.js +183 -0
- package/lib/providers/personalize/utils/cachedSession.d.ts +5 -0
- package/lib/providers/personalize/utils/cachedSession.js +61 -0
- package/lib/providers/personalize/utils/constants.d.ts +7 -0
- package/lib/providers/personalize/utils/constants.js +12 -0
- package/lib/providers/personalize/utils/getEventBuffer.d.ts +3 -0
- package/lib/providers/personalize/utils/getEventBuffer.js +100 -0
- package/lib/providers/personalize/utils/index.d.ts +5 -0
- package/lib/providers/personalize/utils/index.js +17 -0
- package/lib/providers/personalize/utils/resolveConfig.d.ts +7 -0
- package/lib/providers/personalize/utils/resolveConfig.js +25 -0
- package/lib/providers/pinpoint/apis/configureAutoTrack.d.ts +15 -0
- package/lib/providers/pinpoint/apis/configureAutoTrack.js +35 -0
- package/lib/providers/pinpoint/apis/flushEvents.d.ts +8 -0
- package/lib/providers/pinpoint/apis/flushEvents.js +28 -0
- package/lib/providers/pinpoint/apis/identifyUser.d.ts +7 -5
- package/lib/providers/pinpoint/apis/identifyUser.js +15 -11
- package/lib/providers/pinpoint/apis/index.d.ts +2 -0
- package/lib/providers/pinpoint/apis/index.js +5 -1
- package/lib/providers/pinpoint/apis/record.d.ts +8 -14
- package/lib/providers/pinpoint/apis/record.js +22 -24
- package/lib/providers/pinpoint/index.d.ts +2 -2
- package/lib/providers/pinpoint/index.js +3 -1
- package/lib/providers/pinpoint/types/index.d.ts +2 -2
- package/lib/providers/pinpoint/types/index.js +0 -3
- package/lib/providers/pinpoint/types/inputs.d.ts +8 -17
- package/lib/providers/pinpoint/types/options.d.ts +5 -0
- package/lib/providers/pinpoint/types/options.js +4 -0
- package/lib/providers/pinpoint/utils/resolveCredentials.d.ts +1 -6
- package/lib/trackers/EventTracker.d.ts +10 -0
- package/lib/trackers/EventTracker.js +104 -0
- package/lib/trackers/PageViewTracker.d.ts +18 -0
- package/lib/trackers/PageViewTracker.js +116 -0
- package/lib/trackers/SessionTracker.d.ts +13 -0
- package/lib/trackers/SessionTracker.js +73 -0
- package/lib/trackers/SessionTracker.native.d.ts +13 -0
- package/lib/trackers/SessionTracker.native.js +73 -0
- package/lib/trackers/index.d.ts +3 -0
- package/lib/trackers/index.js +11 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/index.d.ts +3 -1
- package/lib/types/index.js +0 -2
- package/lib/types/inputs.d.ts +35 -0
- package/lib/types/inputs.js +4 -0
- package/lib/types/kinesis.d.ts +8 -0
- package/lib/types/kinesis.js +4 -0
- package/lib/types/options.d.ts +4 -0
- package/lib/types/options.js +4 -0
- package/lib/types/trackers.d.ts +22 -0
- package/lib/types/trackers.js +4 -0
- package/lib/utils/eventBuffer/EventBuffer.d.ts +16 -0
- package/lib/utils/eventBuffer/EventBuffer.js +91 -0
- package/lib/utils/eventBuffer/index.d.ts +2 -0
- package/lib/utils/eventBuffer/index.js +7 -0
- package/lib/utils/eventBuffer/types.d.ts +8 -0
- package/lib/utils/eventBuffer/types.js +4 -0
- package/lib/utils/groupBy.d.ts +1 -0
- package/lib/utils/groupBy.js +15 -0
- package/lib/utils/index.d.ts +7 -0
- package/lib/utils/index.js +22 -0
- package/lib/utils/resolveCredentials.d.ts +4 -0
- package/lib/utils/resolveCredentials.js +21 -0
- package/lib/utils/statusHelpers.d.ts +6 -0
- package/lib/utils/statusHelpers.js +19 -0
- package/lib/utils/trackerConfigHelpers.d.ts +5 -0
- package/lib/utils/trackerConfigHelpers.js +15 -0
- package/lib/utils/trackerConfigHelpers.native.d.ts +5 -0
- package/lib/utils/trackerConfigHelpers.native.js +14 -0
- package/lib/utils/trackerHelpers.d.ts +9 -0
- package/lib/utils/trackerHelpers.js +44 -0
- package/lib-esm/apis/disable.d.ts +8 -0
- package/lib-esm/apis/disable.js +11 -0
- package/lib-esm/apis/enable.d.ts +7 -0
- package/lib-esm/apis/enable.js +10 -0
- package/lib-esm/apis/index.d.ts +2 -0
- package/lib-esm/apis/index.js +4 -0
- package/lib-esm/errors/AnalyticsError.d.ts +2 -2
- package/lib-esm/errors/AnalyticsError.js +1 -1
- package/lib-esm/errors/assertValidationError.d.ts +1 -1
- package/lib-esm/errors/assertValidationError.js +7 -3
- package/lib-esm/errors/validation.d.ts +5 -2
- package/lib-esm/errors/validation.js +16 -4
- package/lib-esm/index.d.ts +2 -1
- package/lib-esm/index.js +2 -1
- package/lib-esm/providers/kinesis/apis/flushEvents.d.ts +8 -0
- package/lib-esm/providers/kinesis/apis/flushEvents.js +34 -0
- package/lib-esm/providers/kinesis/apis/index.d.ts +2 -0
- package/lib-esm/providers/kinesis/apis/index.js +4 -0
- package/lib-esm/providers/kinesis/apis/record.d.ts +2 -0
- package/lib-esm/providers/kinesis/apis/record.js +44 -0
- package/lib-esm/providers/kinesis/index.d.ts +1 -0
- package/lib-esm/providers/kinesis/index.js +3 -0
- package/lib-esm/providers/kinesis/types/buffer.d.ts +15 -0
- package/lib-esm/providers/kinesis/types/buffer.js +3 -0
- package/lib-esm/providers/kinesis/types/index.d.ts +2 -0
- package/lib-esm/providers/kinesis/types/index.js +3 -0
- package/lib-esm/providers/kinesis/types/inputs.d.ts +6 -0
- package/lib-esm/providers/kinesis/types/inputs.js +3 -0
- package/lib-esm/providers/kinesis/utils/constants.d.ts +6 -0
- package/lib-esm/providers/kinesis/utils/constants.js +8 -0
- package/lib-esm/providers/kinesis/utils/getEventBuffer.d.ts +3 -0
- package/lib-esm/providers/kinesis/utils/getEventBuffer.js +99 -0
- package/lib-esm/providers/kinesis/utils/resolveConfig.d.ts +7 -0
- package/lib-esm/providers/kinesis/utils/resolveConfig.js +20 -0
- package/lib-esm/providers/kinesis-firehose/apis/flushEvents.d.ts +8 -0
- package/lib-esm/providers/kinesis-firehose/apis/flushEvents.js +33 -0
- package/lib-esm/providers/kinesis-firehose/apis/index.d.ts +2 -0
- package/lib-esm/providers/kinesis-firehose/apis/index.js +4 -0
- package/lib-esm/providers/kinesis-firehose/apis/record.d.ts +2 -0
- package/lib-esm/providers/kinesis-firehose/apis/record.js +41 -0
- package/lib-esm/providers/kinesis-firehose/index.d.ts +1 -0
- package/lib-esm/providers/kinesis-firehose/index.js +3 -0
- package/lib-esm/providers/kinesis-firehose/types/buffer.d.ts +15 -0
- package/lib-esm/providers/kinesis-firehose/types/index.d.ts +2 -0
- package/lib-esm/providers/kinesis-firehose/types/index.js +3 -0
- package/lib-esm/providers/kinesis-firehose/types/inputs.d.ts +5 -0
- package/lib-esm/providers/kinesis-firehose/types/inputs.js +3 -0
- package/lib-esm/providers/kinesis-firehose/utils/constants.d.ts +6 -0
- package/lib-esm/providers/kinesis-firehose/utils/constants.js +8 -0
- package/lib-esm/providers/kinesis-firehose/utils/getEventBuffer.d.ts +3 -0
- package/lib-esm/providers/kinesis-firehose/utils/getEventBuffer.js +96 -0
- package/lib-esm/providers/kinesis-firehose/utils/index.d.ts +2 -0
- package/lib-esm/providers/kinesis-firehose/utils/index.js +4 -0
- package/lib-esm/providers/kinesis-firehose/utils/resolveConfig.d.ts +7 -0
- package/lib-esm/providers/kinesis-firehose/utils/resolveConfig.js +20 -0
- package/lib-esm/providers/personalize/apis/flushEvents.d.ts +8 -0
- package/lib-esm/providers/personalize/apis/flushEvents.js +32 -0
- package/lib-esm/providers/personalize/apis/index.d.ts +2 -0
- package/lib-esm/providers/personalize/apis/index.js +4 -0
- package/lib-esm/providers/personalize/apis/record.d.ts +2 -0
- package/lib-esm/providers/personalize/apis/record.js +83 -0
- package/lib-esm/providers/personalize/index.d.ts +1 -0
- package/lib-esm/providers/personalize/index.js +3 -0
- package/lib-esm/providers/personalize/types/buffer.d.ts +16 -0
- package/lib-esm/providers/personalize/types/buffer.js +3 -0
- package/lib-esm/providers/personalize/types/index.d.ts +2 -0
- package/lib-esm/providers/personalize/types/index.js +3 -0
- package/lib-esm/providers/personalize/types/inputs.d.ts +7 -0
- package/lib-esm/providers/personalize/types/inputs.js +3 -0
- package/lib-esm/providers/personalize/utils/autoTrackMedia.d.ts +10 -0
- package/lib-esm/providers/personalize/utils/autoTrackMedia.js +179 -0
- package/lib-esm/providers/personalize/utils/cachedSession.d.ts +5 -0
- package/lib-esm/providers/personalize/utils/cachedSession.js +56 -0
- package/lib-esm/providers/personalize/utils/constants.d.ts +7 -0
- package/lib-esm/providers/personalize/utils/constants.js +9 -0
- package/lib-esm/providers/personalize/utils/getEventBuffer.d.ts +3 -0
- package/lib-esm/providers/personalize/utils/getEventBuffer.js +96 -0
- package/lib-esm/providers/personalize/utils/index.d.ts +5 -0
- package/lib-esm/providers/personalize/utils/index.js +7 -0
- package/lib-esm/providers/personalize/utils/resolveConfig.d.ts +7 -0
- package/lib-esm/providers/personalize/utils/resolveConfig.js +21 -0
- package/lib-esm/providers/pinpoint/apis/configureAutoTrack.d.ts +15 -0
- package/lib-esm/providers/pinpoint/apis/configureAutoTrack.js +31 -0
- package/lib-esm/providers/pinpoint/apis/flushEvents.d.ts +8 -0
- package/lib-esm/providers/pinpoint/apis/flushEvents.js +24 -0
- package/lib-esm/providers/pinpoint/apis/identifyUser.d.ts +7 -5
- package/lib-esm/providers/pinpoint/apis/identifyUser.js +13 -9
- package/lib-esm/providers/pinpoint/apis/index.d.ts +2 -0
- package/lib-esm/providers/pinpoint/apis/index.js +2 -0
- package/lib-esm/providers/pinpoint/apis/record.d.ts +8 -14
- package/lib-esm/providers/pinpoint/apis/record.js +20 -22
- package/lib-esm/providers/pinpoint/index.d.ts +2 -2
- package/lib-esm/providers/pinpoint/index.js +1 -1
- package/lib-esm/providers/pinpoint/types/index.d.ts +2 -2
- package/lib-esm/providers/pinpoint/types/index.js +1 -1
- package/lib-esm/providers/pinpoint/types/inputs.d.ts +8 -17
- package/lib-esm/providers/pinpoint/types/options.d.ts +5 -0
- package/lib-esm/providers/pinpoint/types/options.js +3 -0
- package/lib-esm/providers/pinpoint/utils/resolveCredentials.d.ts +1 -6
- package/lib-esm/trackers/EventTracker.d.ts +10 -0
- package/lib-esm/trackers/EventTracker.js +101 -0
- package/lib-esm/trackers/PageViewTracker.d.ts +18 -0
- package/lib-esm/trackers/PageViewTracker.js +113 -0
- package/lib-esm/trackers/SessionTracker.d.ts +13 -0
- package/lib-esm/trackers/SessionTracker.js +70 -0
- package/lib-esm/trackers/SessionTracker.native.d.ts +13 -0
- package/lib-esm/trackers/SessionTracker.native.js +70 -0
- package/lib-esm/trackers/index.d.ts +3 -0
- package/lib-esm/trackers/index.js +5 -0
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/types/index.d.ts +3 -1
- package/lib-esm/types/index.js +1 -1
- package/lib-esm/types/inputs.d.ts +35 -0
- package/lib-esm/types/inputs.js +3 -0
- package/lib-esm/types/kinesis.d.ts +8 -0
- package/lib-esm/types/kinesis.js +3 -0
- package/lib-esm/types/options.d.ts +4 -0
- package/lib-esm/types/options.js +3 -0
- package/lib-esm/types/trackers.d.ts +22 -0
- package/lib-esm/types/trackers.js +3 -0
- package/lib-esm/utils/eventBuffer/EventBuffer.d.ts +16 -0
- package/lib-esm/utils/eventBuffer/EventBuffer.js +88 -0
- package/lib-esm/utils/eventBuffer/index.d.ts +2 -0
- package/lib-esm/utils/eventBuffer/index.js +3 -0
- package/lib-esm/utils/eventBuffer/types.d.ts +8 -0
- package/lib-esm/utils/eventBuffer/types.js +3 -0
- package/lib-esm/utils/groupBy.d.ts +1 -0
- package/lib-esm/utils/groupBy.js +11 -0
- package/lib-esm/utils/index.d.ts +7 -0
- package/lib-esm/utils/index.js +9 -0
- package/lib-esm/utils/resolveCredentials.d.ts +4 -0
- package/lib-esm/utils/resolveCredentials.js +17 -0
- package/lib-esm/utils/statusHelpers.d.ts +6 -0
- package/lib-esm/utils/statusHelpers.js +13 -0
- package/lib-esm/utils/trackerConfigHelpers.d.ts +5 -0
- package/lib-esm/utils/trackerConfigHelpers.js +11 -0
- package/lib-esm/utils/trackerConfigHelpers.native.d.ts +5 -0
- package/lib-esm/utils/trackerConfigHelpers.native.js +10 -0
- package/lib-esm/utils/trackerHelpers.d.ts +9 -0
- package/lib-esm/utils/trackerHelpers.js +40 -0
- package/package.json +39 -9
- package/personalize/package.json +7 -0
- package/src/apis/disable.ts +13 -0
- package/src/apis/enable.ts +12 -0
- package/src/apis/index.ts +5 -0
- package/src/errors/AnalyticsError.ts +5 -2
- package/src/errors/assertValidationError.ts +9 -3
- package/src/errors/validation.ts +16 -4
- package/src/index.ts +4 -0
- package/src/providers/kinesis/apis/flushEvents.ts +40 -0
- package/src/providers/kinesis/apis/index.ts +5 -0
- package/src/providers/kinesis/apis/record.ts +58 -0
- package/src/providers/kinesis/index.ts +4 -0
- package/src/providers/kinesis/types/buffer.ts +20 -0
- package/src/providers/kinesis/types/index.ts +5 -0
- package/src/providers/kinesis/types/inputs.ts +10 -0
- package/src/providers/kinesis/utils/constants.ts +9 -0
- package/src/providers/kinesis/utils/getEventBuffer.ts +110 -0
- package/src/providers/kinesis/utils/resolveConfig.ts +36 -0
- package/src/providers/kinesis-firehose/apis/flushEvents.ts +39 -0
- package/src/providers/kinesis-firehose/apis/index.ts +5 -0
- package/src/providers/kinesis-firehose/apis/record.ts +51 -0
- package/src/providers/kinesis-firehose/index.ts +4 -0
- package/src/providers/kinesis-firehose/types/buffer.ts +20 -0
- package/src/providers/kinesis-firehose/types/index.ts +9 -0
- package/src/providers/kinesis-firehose/types/inputs.ts +9 -0
- package/src/providers/kinesis-firehose/utils/constants.ts +9 -0
- package/src/providers/kinesis-firehose/utils/getEventBuffer.ts +118 -0
- package/src/providers/kinesis-firehose/utils/index.ts +5 -0
- package/src/providers/kinesis-firehose/utils/resolveConfig.ts +36 -0
- package/src/providers/personalize/apis/flushEvents.ts +37 -0
- package/src/providers/personalize/apis/index.ts +5 -0
- package/src/providers/personalize/apis/record.ts +102 -0
- package/src/providers/personalize/index.ts +4 -0
- package/src/providers/personalize/types/buffer.ts +21 -0
- package/src/providers/personalize/types/index.ts +5 -0
- package/src/providers/personalize/types/inputs.ts +11 -0
- package/src/providers/personalize/utils/autoTrackMedia.ts +232 -0
- package/src/providers/personalize/utils/cachedSession.ts +68 -0
- package/src/providers/personalize/utils/constants.ts +12 -0
- package/src/providers/personalize/utils/getEventBuffer.ts +111 -0
- package/src/providers/personalize/utils/index.ts +11 -0
- package/src/providers/personalize/utils/resolveConfig.ts +41 -0
- package/src/providers/pinpoint/apis/configureAutoTrack.ts +49 -0
- package/src/providers/pinpoint/apis/flushEvents.ts +32 -0
- package/src/providers/pinpoint/apis/identifyUser.ts +20 -12
- package/src/providers/pinpoint/apis/index.ts +2 -0
- package/src/providers/pinpoint/apis/record.ts +31 -23
- package/src/providers/pinpoint/index.ts +6 -2
- package/src/providers/pinpoint/types/index.ts +6 -2
- package/src/providers/pinpoint/types/inputs.ts +11 -17
- package/src/providers/pinpoint/types/options.ts +12 -0
- package/src/trackers/EventTracker.ts +135 -0
- package/src/trackers/PageViewTracker.ts +160 -0
- package/src/trackers/SessionTracker.native.ts +106 -0
- package/src/trackers/SessionTracker.ts +106 -0
- package/src/trackers/index.ts +6 -0
- package/src/types/index.ts +8 -1
- package/src/types/inputs.ts +52 -0
- package/src/types/kinesis.ts +13 -0
- package/src/types/options.ts +7 -0
- package/src/types/trackers.ts +35 -0
- package/src/utils/eventBuffer/EventBuffer.ts +84 -0
- package/src/utils/eventBuffer/index.ts +5 -0
- package/src/utils/eventBuffer/types.ts +12 -0
- package/src/utils/groupBy.ts +12 -0
- package/src/utils/index.ts +21 -0
- package/src/utils/resolveCredentials.ts +14 -0
- package/src/utils/statusHelpers.ts +17 -0
- package/src/utils/trackerConfigHelpers.native.ts +18 -0
- package/src/utils/trackerConfigHelpers.ts +19 -0
- package/src/utils/trackerHelpers.ts +57 -0
- package/lib/providers/pinpoint/types/errors.d.ts +0 -9
- package/lib/providers/pinpoint/types/errors.js +0 -15
- package/lib/types/analytics.d.ts +0 -50
- package/lib-esm/providers/pinpoint/types/errors.d.ts +0 -9
- package/lib-esm/providers/pinpoint/types/errors.js +0 -12
- package/lib-esm/types/analytics.d.ts +0 -50
- package/src/providers/pinpoint/types/errors.ts +0 -12
- package/src/types/analytics.ts +0 -70
- /package/lib/{types/analytics.js → providers/kinesis-firehose/types/buffer.js} +0 -0
- /package/lib-esm/{types/analytics.js → providers/kinesis-firehose/types/buffer.js} +0 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { RecordInput } from '../types';
|
|
5
|
+
import {
|
|
6
|
+
autoTrackMedia,
|
|
7
|
+
getEventBuffer,
|
|
8
|
+
resolveCachedSession,
|
|
9
|
+
resolveConfig,
|
|
10
|
+
updateCachedSession,
|
|
11
|
+
} from '../utils';
|
|
12
|
+
import {
|
|
13
|
+
getAnalyticsUserAgentString,
|
|
14
|
+
isAnalyticsEnabled,
|
|
15
|
+
resolveCredentials,
|
|
16
|
+
} from '../../../utils';
|
|
17
|
+
import { AnalyticsAction } from '@aws-amplify/core/internals/utils';
|
|
18
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
19
|
+
import {
|
|
20
|
+
IDENTIFY_EVENT_TYPE,
|
|
21
|
+
MEDIA_AUTO_TRACK_EVENT_TYPE,
|
|
22
|
+
} from '../utils/constants';
|
|
23
|
+
|
|
24
|
+
const logger = new ConsoleLogger('Personalize');
|
|
25
|
+
|
|
26
|
+
export const record = ({
|
|
27
|
+
userId,
|
|
28
|
+
eventId,
|
|
29
|
+
eventType,
|
|
30
|
+
properties,
|
|
31
|
+
}: RecordInput): void => {
|
|
32
|
+
if (!isAnalyticsEnabled()) {
|
|
33
|
+
logger.debug('Analytics is disabled, event will not be recorded.');
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const { region, trackingId, bufferSize, flushSize, flushInterval } =
|
|
38
|
+
resolveConfig();
|
|
39
|
+
resolveCredentials()
|
|
40
|
+
.then(async ({ credentials, identityId }) => {
|
|
41
|
+
const timestamp = Date.now();
|
|
42
|
+
const { sessionId: cachedSessionId, userId: cachedUserId } =
|
|
43
|
+
await resolveCachedSession();
|
|
44
|
+
if (eventType === IDENTIFY_EVENT_TYPE) {
|
|
45
|
+
updateCachedSession(
|
|
46
|
+
typeof properties.userId === 'string' ? properties.userId : '',
|
|
47
|
+
cachedSessionId,
|
|
48
|
+
cachedUserId
|
|
49
|
+
);
|
|
50
|
+
} else if (!!userId) {
|
|
51
|
+
updateCachedSession(userId, cachedSessionId, cachedUserId);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const { sessionId: updatedSessionId, userId: updatedUserId } =
|
|
55
|
+
await resolveCachedSession();
|
|
56
|
+
|
|
57
|
+
const eventBuffer = getEventBuffer({
|
|
58
|
+
region,
|
|
59
|
+
flushSize,
|
|
60
|
+
flushInterval,
|
|
61
|
+
bufferSize,
|
|
62
|
+
credentials,
|
|
63
|
+
identityId,
|
|
64
|
+
userAgentValue: getAnalyticsUserAgentString(AnalyticsAction.Record),
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
if (eventType === MEDIA_AUTO_TRACK_EVENT_TYPE) {
|
|
68
|
+
autoTrackMedia(
|
|
69
|
+
{
|
|
70
|
+
trackingId,
|
|
71
|
+
sessionId: updatedSessionId,
|
|
72
|
+
userId: updatedUserId,
|
|
73
|
+
event: {
|
|
74
|
+
eventId,
|
|
75
|
+
eventType,
|
|
76
|
+
properties,
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
eventBuffer
|
|
80
|
+
);
|
|
81
|
+
} else {
|
|
82
|
+
eventBuffer.append({
|
|
83
|
+
trackingId,
|
|
84
|
+
sessionId: updatedSessionId,
|
|
85
|
+
userId: updatedUserId,
|
|
86
|
+
event: {
|
|
87
|
+
eventId,
|
|
88
|
+
eventType,
|
|
89
|
+
properties,
|
|
90
|
+
},
|
|
91
|
+
timestamp,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (eventBuffer.length >= bufferSize) {
|
|
96
|
+
eventBuffer.flushAll();
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
.catch(e => {
|
|
100
|
+
logger.warn('Failed to record event.', e);
|
|
101
|
+
});
|
|
102
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { PersonalizeEvent } from './';
|
|
5
|
+
import { EventBufferConfig } from '../../../utils';
|
|
6
|
+
import { AWSCredentials } from '@aws-amplify/core/internals/utils';
|
|
7
|
+
|
|
8
|
+
export type PersonalizeBufferEvent = {
|
|
9
|
+
trackingId: string;
|
|
10
|
+
sessionId?: string;
|
|
11
|
+
userId?: string;
|
|
12
|
+
event: PersonalizeEvent;
|
|
13
|
+
timestamp: number;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type PersonalizeBufferConfig = EventBufferConfig & {
|
|
17
|
+
region: string;
|
|
18
|
+
credentials: AWSCredentials;
|
|
19
|
+
identityId?: string;
|
|
20
|
+
userAgentValue?: string;
|
|
21
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export type PersonalizeEvent = {
|
|
5
|
+
userId?: string;
|
|
6
|
+
eventId?: string;
|
|
7
|
+
eventType: string;
|
|
8
|
+
properties: Record<string, unknown>;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type RecordInput = PersonalizeEvent;
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { EventBuffer } from '../../../utils';
|
|
5
|
+
import { PersonalizeBufferEvent, PersonalizeEvent } from '../types';
|
|
6
|
+
import { isBrowser } from '@aws-amplify/core/internals/utils';
|
|
7
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
8
|
+
|
|
9
|
+
enum HTML5_MEDIA_EVENT {
|
|
10
|
+
'PLAY' = 'play',
|
|
11
|
+
'PAUSE' = 'pause',
|
|
12
|
+
'ENDED' = 'Ended',
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
enum MEDIA_TYPE {
|
|
16
|
+
'IFRAME' = 'IFRAME',
|
|
17
|
+
'VIDEO' = 'VIDEO',
|
|
18
|
+
'AUDIO' = 'AUDIO',
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
enum EVENT_TYPE {
|
|
22
|
+
'PLAY' = 'Play',
|
|
23
|
+
'ENDED' = 'Ended',
|
|
24
|
+
'PAUSE' = 'Pause',
|
|
25
|
+
'TIME_WATCHED' = 'TimeWatched',
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface IRecordEvent {
|
|
29
|
+
(eventType: string, properties: Record<string, unknown>): void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type MediaAutoTrackConfig = {
|
|
33
|
+
trackingId: string;
|
|
34
|
+
sessionId: string;
|
|
35
|
+
userId?: string;
|
|
36
|
+
event: PersonalizeEvent;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const logger = new ConsoleLogger('MediaAutoTrack');
|
|
40
|
+
|
|
41
|
+
const startIframeAutoTracking = (
|
|
42
|
+
element: HTMLElement,
|
|
43
|
+
recordEvent: IRecordEvent
|
|
44
|
+
) => {
|
|
45
|
+
let isPlaying = false;
|
|
46
|
+
let player: any;
|
|
47
|
+
const mediaProperties = (): Record<string, unknown> => {
|
|
48
|
+
const duration = Number(parseFloat(player.getDuration()).toFixed(4));
|
|
49
|
+
const currentTime = Number(parseFloat(player.getCurrentTime()).toFixed(4));
|
|
50
|
+
return {
|
|
51
|
+
duration,
|
|
52
|
+
eventValue: Number((currentTime / duration).toFixed(4)),
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const scriptElement = document.createElement('script');
|
|
57
|
+
scriptElement.type = 'text/javascript';
|
|
58
|
+
scriptElement.src = 'https://www.youtube.com/iframe_api';
|
|
59
|
+
document.body.append(scriptElement);
|
|
60
|
+
|
|
61
|
+
const timer = setInterval(() => {
|
|
62
|
+
if (isPlaying && player) {
|
|
63
|
+
recordEvent(EVENT_TYPE.TIME_WATCHED, mediaProperties());
|
|
64
|
+
}
|
|
65
|
+
}, 3_000);
|
|
66
|
+
|
|
67
|
+
element.addEventListener('unload', () => clearInterval(timer));
|
|
68
|
+
|
|
69
|
+
// @ts-ignore
|
|
70
|
+
window.onYouTubeIframeAPIReady = () => {
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
delete window.onYouTubeIframeAPIReady;
|
|
73
|
+
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
player = new window.YT.Player(element.id, {
|
|
76
|
+
events: {
|
|
77
|
+
onStateChange: (event: any) => {
|
|
78
|
+
const iframeEventMapping = {
|
|
79
|
+
0: EVENT_TYPE.ENDED,
|
|
80
|
+
1: EVENT_TYPE.PLAY,
|
|
81
|
+
2: EVENT_TYPE.PAUSE,
|
|
82
|
+
};
|
|
83
|
+
// @ts-ignore
|
|
84
|
+
const eventType = iframeEventMapping[event.data];
|
|
85
|
+
switch (eventType) {
|
|
86
|
+
case EVENT_TYPE.ENDED:
|
|
87
|
+
case EVENT_TYPE.PAUSE:
|
|
88
|
+
isPlaying = false;
|
|
89
|
+
break;
|
|
90
|
+
case EVENT_TYPE.PLAY:
|
|
91
|
+
isPlaying = true;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (eventType) {
|
|
96
|
+
recordEvent(eventType, mediaProperties());
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const startHTMLMediaAutoTracking = (
|
|
105
|
+
element: HTMLMediaElement,
|
|
106
|
+
recordEvent: IRecordEvent
|
|
107
|
+
) => {
|
|
108
|
+
let isPlaying = false;
|
|
109
|
+
const mediaProperties = (): Record<string, unknown> => ({
|
|
110
|
+
duration: element.duration,
|
|
111
|
+
eventValue: Number((element.currentTime / element.duration).toFixed(4)),
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
const timer = setInterval(() => {
|
|
115
|
+
if (isPlaying) {
|
|
116
|
+
recordEvent(EVENT_TYPE.TIME_WATCHED, mediaProperties());
|
|
117
|
+
}
|
|
118
|
+
}, 3_000);
|
|
119
|
+
|
|
120
|
+
element.addEventListener('unload', () => clearInterval(timer));
|
|
121
|
+
|
|
122
|
+
element.addEventListener(HTML5_MEDIA_EVENT.PLAY, () => {
|
|
123
|
+
isPlaying = true;
|
|
124
|
+
recordEvent(EVENT_TYPE.PLAY, mediaProperties());
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
element.addEventListener(HTML5_MEDIA_EVENT.PAUSE, () => {
|
|
128
|
+
isPlaying = false;
|
|
129
|
+
recordEvent(EVENT_TYPE.PAUSE, mediaProperties());
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
element.addEventListener(HTML5_MEDIA_EVENT.ENDED, () => {
|
|
133
|
+
isPlaying = false;
|
|
134
|
+
recordEvent(EVENT_TYPE.ENDED, mediaProperties());
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const checkElementLoaded = (interval: number, maxTries: number) => {
|
|
139
|
+
let retryCount = 0;
|
|
140
|
+
const wait = () => new Promise(r => setTimeout(r, interval));
|
|
141
|
+
const check = async (elementId: string): Promise<boolean> => {
|
|
142
|
+
if (retryCount >= maxTries) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const domElement = document.getElementById(elementId);
|
|
147
|
+
if (domElement && domElement.clientHeight) {
|
|
148
|
+
return true;
|
|
149
|
+
} else {
|
|
150
|
+
retryCount += 1;
|
|
151
|
+
await wait();
|
|
152
|
+
return await check(elementId);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
return check;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const recordEvent =
|
|
159
|
+
(
|
|
160
|
+
config: MediaAutoTrackConfig,
|
|
161
|
+
eventBuffer: EventBuffer<PersonalizeBufferEvent>
|
|
162
|
+
): IRecordEvent =>
|
|
163
|
+
(eventType: string, properties: Record<string, unknown>) => {
|
|
164
|
+
// override eventType and merge properties
|
|
165
|
+
eventBuffer.append({
|
|
166
|
+
...config,
|
|
167
|
+
event: {
|
|
168
|
+
...config.event,
|
|
169
|
+
eventType,
|
|
170
|
+
properties: {
|
|
171
|
+
...config.event.properties,
|
|
172
|
+
...properties,
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
timestamp: Date.now(),
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
export const autoTrackMedia = async (
|
|
180
|
+
config: MediaAutoTrackConfig,
|
|
181
|
+
eventBuffer: EventBuffer<PersonalizeBufferEvent>
|
|
182
|
+
) => {
|
|
183
|
+
const { eventType, properties } = config.event;
|
|
184
|
+
const { domElementId, ...otherProperties } = properties;
|
|
185
|
+
if (!isBrowser()) {
|
|
186
|
+
logger.debug(`${eventType} only for browser`);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (typeof domElementId === 'string' && !domElementId) {
|
|
191
|
+
logger.debug(
|
|
192
|
+
"Missing domElementId field in 'properties' for MediaAutoTrack event type."
|
|
193
|
+
);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const elementId = domElementId as string;
|
|
198
|
+
const isElementLoaded = await checkElementLoaded(500, 5)(elementId);
|
|
199
|
+
if (isElementLoaded) {
|
|
200
|
+
const autoTrackConfigWithoutDomElementId = {
|
|
201
|
+
...config,
|
|
202
|
+
event: {
|
|
203
|
+
...config.event,
|
|
204
|
+
properties: otherProperties,
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
const element = document.getElementById(elementId);
|
|
209
|
+
switch (element?.tagName) {
|
|
210
|
+
case MEDIA_TYPE.IFRAME:
|
|
211
|
+
startIframeAutoTracking(
|
|
212
|
+
element,
|
|
213
|
+
recordEvent(autoTrackConfigWithoutDomElementId, eventBuffer)
|
|
214
|
+
);
|
|
215
|
+
break;
|
|
216
|
+
case MEDIA_TYPE.VIDEO:
|
|
217
|
+
case MEDIA_TYPE.AUDIO:
|
|
218
|
+
if (element instanceof HTMLMediaElement) {
|
|
219
|
+
startHTMLMediaAutoTracking(
|
|
220
|
+
element,
|
|
221
|
+
recordEvent(autoTrackConfigWithoutDomElementId, eventBuffer)
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
break;
|
|
225
|
+
default:
|
|
226
|
+
logger.debug(`Unsupported DOM element tag: ${element?.tagName}`);
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
} else {
|
|
230
|
+
logger.debug('Cannot find the media element.');
|
|
231
|
+
}
|
|
232
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { Cache } from '@aws-amplify/core';
|
|
5
|
+
import { isBrowser, amplifyUuid } from '@aws-amplify/core/internals/utils';
|
|
6
|
+
|
|
7
|
+
const PERSONALIZE_CACHE_USERID = '_awsct_uid';
|
|
8
|
+
const PERSONALIZE_CACHE_SESSIONID = '_awsct_sid';
|
|
9
|
+
const DEFAULT_CACHE_PREFIX = 'personalize';
|
|
10
|
+
const DELIMITER = '.';
|
|
11
|
+
const CACHE_EXPIRY_IN_DAYS = 7;
|
|
12
|
+
|
|
13
|
+
const normalize = (key: string): string =>
|
|
14
|
+
[key, isBrowser() ? window.location.host : DEFAULT_CACHE_PREFIX].join(
|
|
15
|
+
DELIMITER
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
const getCache = (key: string) => Cache.getItem(normalize(key));
|
|
19
|
+
|
|
20
|
+
const setCache = (key: string, value: unknown) => {
|
|
21
|
+
const expiredAt = new Date(
|
|
22
|
+
Date.now() + 3_600_000 * 24 * CACHE_EXPIRY_IN_DAYS
|
|
23
|
+
);
|
|
24
|
+
Cache.setItem(normalize(key), value, {
|
|
25
|
+
expires: expiredAt.getTime(),
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const resolveCachedSession = async () => {
|
|
30
|
+
let sessionId: string | undefined = await getCache(
|
|
31
|
+
PERSONALIZE_CACHE_SESSIONID
|
|
32
|
+
);
|
|
33
|
+
if (!sessionId) {
|
|
34
|
+
sessionId = amplifyUuid();
|
|
35
|
+
setCache(PERSONALIZE_CACHE_SESSIONID, sessionId);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const userId: string | undefined = await getCache(PERSONALIZE_CACHE_USERID);
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
sessionId,
|
|
42
|
+
userId,
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const updateCachedSession = (
|
|
47
|
+
newUserId?: string,
|
|
48
|
+
currentSessionId?: string,
|
|
49
|
+
currentUserId?: string
|
|
50
|
+
) => {
|
|
51
|
+
const isNoCachedSession = !currentSessionId;
|
|
52
|
+
const isSignOutCase = !newUserId && !currentUserId;
|
|
53
|
+
const isSwitchUserCase =
|
|
54
|
+
!!newUserId && !!currentUserId && newUserId !== currentUserId;
|
|
55
|
+
|
|
56
|
+
const isRequireNewSession =
|
|
57
|
+
isNoCachedSession || isSignOutCase || isSwitchUserCase;
|
|
58
|
+
const isRequireUpdateSession =
|
|
59
|
+
!!currentSessionId && !currentUserId && !!newUserId;
|
|
60
|
+
|
|
61
|
+
if (isRequireNewSession) {
|
|
62
|
+
const newSessionId = amplifyUuid();
|
|
63
|
+
setCache(PERSONALIZE_CACHE_SESSIONID, newSessionId);
|
|
64
|
+
setCache(PERSONALIZE_CACHE_USERID, newUserId);
|
|
65
|
+
} else if (isRequireUpdateSession) {
|
|
66
|
+
setCache(PERSONALIZE_CACHE_USERID, newUserId);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export const DEFAULT_PERSONALIZE_CONFIG = {
|
|
5
|
+
flushSize: 5,
|
|
6
|
+
flushInterval: 5_000,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const PERSONALIZE_FLUSH_SIZE_MAX = 10;
|
|
10
|
+
|
|
11
|
+
export const IDENTIFY_EVENT_TYPE = 'Identify';
|
|
12
|
+
export const MEDIA_AUTO_TRACK_EVENT_TYPE = 'MediaAutoTrack';
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { EventBuffer, groupBy, IAnalyticsClient } from '../../../utils';
|
|
5
|
+
import { PersonalizeBufferConfig, PersonalizeBufferEvent } from '../types';
|
|
6
|
+
import {
|
|
7
|
+
PersonalizeEventsClient,
|
|
8
|
+
PutEventsCommand,
|
|
9
|
+
} from '@aws-sdk/client-personalize-events';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* These Records hold cached event buffers and AWS clients.
|
|
13
|
+
* The hash key is determined by the region and session,
|
|
14
|
+
* consisting of a combined value comprising [region, sessionToken, identityId].
|
|
15
|
+
*
|
|
16
|
+
* Only one active session should exist at any given moment.
|
|
17
|
+
* When a new session is initiated, the previous ones should be released.
|
|
18
|
+
* */
|
|
19
|
+
const eventBufferMap: Record<string, EventBuffer<PersonalizeBufferEvent>> = {};
|
|
20
|
+
const cachedClients: Record<string, PersonalizeEventsClient> = {};
|
|
21
|
+
|
|
22
|
+
const DELIMITER = '#';
|
|
23
|
+
|
|
24
|
+
const createPutEventsCommand = (
|
|
25
|
+
ids: string,
|
|
26
|
+
events: PersonalizeBufferEvent[]
|
|
27
|
+
): PutEventsCommand => {
|
|
28
|
+
const [trackingId, sessionId, userId] = ids.split(DELIMITER);
|
|
29
|
+
return new PutEventsCommand({
|
|
30
|
+
trackingId,
|
|
31
|
+
sessionId,
|
|
32
|
+
userId,
|
|
33
|
+
eventList: events.map(event => ({
|
|
34
|
+
eventId: event.event.eventId,
|
|
35
|
+
eventType: event.event.eventType,
|
|
36
|
+
properties: JSON.stringify(event.event.properties),
|
|
37
|
+
sentAt: new Date(event.timestamp),
|
|
38
|
+
})),
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const submitEvents = async (
|
|
43
|
+
events: PersonalizeBufferEvent[],
|
|
44
|
+
client: PersonalizeEventsClient
|
|
45
|
+
): Promise<PersonalizeBufferEvent[]> => {
|
|
46
|
+
const groupedByIds = Object.entries(
|
|
47
|
+
groupBy(
|
|
48
|
+
event =>
|
|
49
|
+
[event.trackingId, event.sessionId, event.userId]
|
|
50
|
+
.filter(id => !!id)
|
|
51
|
+
.join(DELIMITER),
|
|
52
|
+
events
|
|
53
|
+
)
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const requests = groupedByIds
|
|
57
|
+
.map(([ids, events]) => createPutEventsCommand(ids, events))
|
|
58
|
+
.map(command => client.send(command));
|
|
59
|
+
|
|
60
|
+
await Promise.allSettled(requests);
|
|
61
|
+
return Promise.resolve([]);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const getEventBuffer = ({
|
|
65
|
+
region,
|
|
66
|
+
flushSize,
|
|
67
|
+
flushInterval,
|
|
68
|
+
bufferSize,
|
|
69
|
+
credentials,
|
|
70
|
+
identityId,
|
|
71
|
+
userAgentValue,
|
|
72
|
+
}: PersonalizeBufferConfig): EventBuffer<PersonalizeBufferEvent> => {
|
|
73
|
+
const { sessionToken } = credentials;
|
|
74
|
+
const sessionIdentityKey = [region, sessionToken, identityId]
|
|
75
|
+
.filter(x => !!x)
|
|
76
|
+
.join('-');
|
|
77
|
+
|
|
78
|
+
if (!eventBufferMap[sessionIdentityKey]) {
|
|
79
|
+
const getClient = (): IAnalyticsClient<PersonalizeBufferEvent> => {
|
|
80
|
+
if (!cachedClients[sessionIdentityKey]) {
|
|
81
|
+
cachedClients[sessionIdentityKey] = new PersonalizeEventsClient({
|
|
82
|
+
region,
|
|
83
|
+
credentials,
|
|
84
|
+
customUserAgent: userAgentValue,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return events => submitEvents(events, cachedClients[sessionIdentityKey]);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
eventBufferMap[sessionIdentityKey] =
|
|
91
|
+
new EventBuffer<PersonalizeBufferEvent>(
|
|
92
|
+
{
|
|
93
|
+
bufferSize,
|
|
94
|
+
flushSize,
|
|
95
|
+
flushInterval,
|
|
96
|
+
},
|
|
97
|
+
getClient
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const releaseSessionKeys = Object.keys(eventBufferMap).filter(
|
|
101
|
+
key => key !== sessionIdentityKey
|
|
102
|
+
);
|
|
103
|
+
for (const releaseSessionKey of releaseSessionKeys) {
|
|
104
|
+
eventBufferMap[releaseSessionKey].release();
|
|
105
|
+
delete eventBufferMap[releaseSessionKey];
|
|
106
|
+
delete cachedClients[releaseSessionKey];
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return eventBufferMap[sessionIdentityKey];
|
|
111
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export { getEventBuffer } from './getEventBuffer';
|
|
5
|
+
export { resolveConfig } from './resolveConfig';
|
|
6
|
+
export { autoTrackMedia } from './autoTrackMedia';
|
|
7
|
+
export { resolveCachedSession, updateCachedSession } from './cachedSession';
|
|
8
|
+
export {
|
|
9
|
+
DEFAULT_PERSONALIZE_CONFIG,
|
|
10
|
+
PERSONALIZE_FLUSH_SIZE_MAX,
|
|
11
|
+
} from './constants';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { Amplify } from '@aws-amplify/core';
|
|
5
|
+
import {
|
|
6
|
+
AnalyticsValidationErrorCode,
|
|
7
|
+
assertValidationError,
|
|
8
|
+
} from '../../../errors';
|
|
9
|
+
import { DEFAULT_PERSONALIZE_CONFIG, PERSONALIZE_FLUSH_SIZE_MAX } from './';
|
|
10
|
+
|
|
11
|
+
export const resolveConfig = () => {
|
|
12
|
+
const config = Amplify.getConfig().Analytics?.Personalize;
|
|
13
|
+
const {
|
|
14
|
+
region,
|
|
15
|
+
trackingId,
|
|
16
|
+
flushSize = DEFAULT_PERSONALIZE_CONFIG.flushSize,
|
|
17
|
+
flushInterval = DEFAULT_PERSONALIZE_CONFIG.flushInterval,
|
|
18
|
+
} = {
|
|
19
|
+
...DEFAULT_PERSONALIZE_CONFIG,
|
|
20
|
+
...config,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
assertValidationError(!!region, AnalyticsValidationErrorCode.NoRegion);
|
|
24
|
+
assertValidationError(
|
|
25
|
+
!!trackingId,
|
|
26
|
+
AnalyticsValidationErrorCode.NoTrackingId
|
|
27
|
+
);
|
|
28
|
+
assertValidationError(
|
|
29
|
+
flushSize <= PERSONALIZE_FLUSH_SIZE_MAX,
|
|
30
|
+
AnalyticsValidationErrorCode.InvalidFlushSize,
|
|
31
|
+
`FlushSize for Personalize should be less or equal than ${PERSONALIZE_FLUSH_SIZE_MAX}`
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
region,
|
|
36
|
+
trackingId,
|
|
37
|
+
bufferSize: flushSize + 1,
|
|
38
|
+
flushSize,
|
|
39
|
+
flushInterval,
|
|
40
|
+
};
|
|
41
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { AnalyticsValidationErrorCode } from '../../../errors';
|
|
5
|
+
import {
|
|
6
|
+
TrackerType,
|
|
7
|
+
TrackerAttributes,
|
|
8
|
+
TrackerInterface,
|
|
9
|
+
} from '../../../types/trackers';
|
|
10
|
+
import {
|
|
11
|
+
updateProviderTrackers,
|
|
12
|
+
validateTrackerConfiguration,
|
|
13
|
+
} from '../../../utils';
|
|
14
|
+
import { ConfigureAutoTrackInput } from '../types';
|
|
15
|
+
import { record } from './record';
|
|
16
|
+
|
|
17
|
+
// Configured Tracker instances for Pinpoint
|
|
18
|
+
const configuredTrackers: Partial<Record<TrackerType, TrackerInterface>> = {};
|
|
19
|
+
|
|
20
|
+
// Callback that will emit an appropriate event to Pinpoint when required by the Tracker
|
|
21
|
+
const emitTrackingEvent = (
|
|
22
|
+
eventName: string,
|
|
23
|
+
attributes: TrackerAttributes
|
|
24
|
+
) => {
|
|
25
|
+
record({
|
|
26
|
+
name: eventName,
|
|
27
|
+
attributes,
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Configures automatic event tracking for Pinpoint. This API will automatically transmit an analytic event when
|
|
33
|
+
* configured events are detected within your application. This can include: DOM element events (via the `event`
|
|
34
|
+
* tracker), session events (via the `session` tracker), and page view events (via the `pageView` tracker).
|
|
35
|
+
*
|
|
36
|
+
* @remark Only session tracking is currently supported on React Native.
|
|
37
|
+
*
|
|
38
|
+
* @param {ConfigureAutoTrackInput} params The input object to configure auto track behavior.
|
|
39
|
+
*
|
|
40
|
+
* @throws service: {@link UpdateEndpointException} - Thrown when the underlying Pinpoint service returns an error.
|
|
41
|
+
* @throws validation: {@link AnalyticsValidationErrorCode} - Thrown when the provided parameters or library
|
|
42
|
+
* configuration is incorrect.
|
|
43
|
+
*/
|
|
44
|
+
export const configureAutoTrack = (input: ConfigureAutoTrackInput): void => {
|
|
45
|
+
validateTrackerConfiguration(input);
|
|
46
|
+
|
|
47
|
+
// Initialize or update this provider's trackers
|
|
48
|
+
updateProviderTrackers(input, emitTrackingEvent, configuredTrackers);
|
|
49
|
+
};
|