@aws-amplify/analytics 7.0.1-preview-testing.be90020.0 → 7.0.1-ssr-api.df60e41.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/AnalyticsError.js +7 -11
- package/lib/errors/assertValidationError.d.ts +1 -1
- package/lib/errors/assertValidationError.js +9 -5
- package/lib/errors/validation.d.ts +5 -2
- package/lib/errors/validation.js +22 -11
- 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 +35 -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 +46 -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 +72 -0
- package/lib/providers/kinesis/utils/resolveConfig.d.ts +7 -0
- package/lib/providers/kinesis/utils/resolveConfig.js +25 -0
- package/lib/providers/kinesis-firehose/apis/flushEvents.d.ts +8 -0
- package/lib/providers/kinesis-firehose/apis/flushEvents.js +34 -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 +43 -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 +71 -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 +25 -0
- package/lib/providers/personalize/apis/flushEvents.d.ts +8 -0
- package/lib/providers/personalize/apis/flushEvents.js +33 -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 +71 -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 +181 -0
- package/lib/providers/personalize/utils/cachedSession.d.ts +5 -0
- package/lib/providers/personalize/utils/cachedSession.js +49 -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 +73 -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 +26 -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 +25 -0
- package/lib/providers/pinpoint/apis/identifyUser.d.ts +7 -5
- package/lib/providers/pinpoint/apis/identifyUser.js +24 -32
- 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 +31 -34
- 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/resolveConfig.js +5 -6
- package/lib/providers/pinpoint/utils/resolveCredentials.d.ts +1 -6
- package/lib/providers/pinpoint/utils/resolveCredentials.js +7 -15
- package/lib/setupTests.js +1 -1
- package/lib/trackers/EventTracker.d.ts +10 -0
- package/lib/trackers/EventTracker.js +98 -0
- package/lib/trackers/PageViewTracker.d.ts +18 -0
- package/lib/trackers/PageViewTracker.js +112 -0
- package/lib/trackers/SessionTracker.d.ts +13 -0
- package/lib/trackers/SessionTracker.js +67 -0
- package/lib/trackers/SessionTracker.native.d.ts +13 -0
- package/lib/trackers/SessionTracker.native.js +67 -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 +63 -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 +12 -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 +13 -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/utils/userAgent.js +3 -3
- 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 +7 -12
- 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 +22 -11
- 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 +31 -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 +42 -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 +68 -0
- package/lib-esm/providers/kinesis/utils/resolveConfig.d.ts +7 -0
- package/lib-esm/providers/kinesis/utils/resolveConfig.js +21 -0
- package/lib-esm/providers/kinesis-firehose/apis/flushEvents.d.ts +8 -0
- package/lib-esm/providers/kinesis-firehose/apis/flushEvents.js +30 -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 +39 -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 +67 -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 +21 -0
- package/lib-esm/providers/personalize/apis/flushEvents.d.ts +8 -0
- package/lib-esm/providers/personalize/apis/flushEvents.js +29 -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 +67 -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 +177 -0
- package/lib-esm/providers/personalize/utils/cachedSession.d.ts +5 -0
- package/lib-esm/providers/personalize/utils/cachedSession.js +44 -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 +69 -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 +22 -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 +21 -0
- package/lib-esm/providers/pinpoint/apis/identifyUser.d.ts +7 -5
- package/lib-esm/providers/pinpoint/apis/identifyUser.js +22 -30
- 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 +26 -29
- 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/resolveConfig.js +3 -4
- package/lib-esm/providers/pinpoint/utils/resolveCredentials.d.ts +1 -6
- package/lib-esm/providers/pinpoint/utils/resolveCredentials.js +5 -13
- package/lib-esm/setupTests.js +1 -1
- package/lib-esm/trackers/EventTracker.d.ts +10 -0
- package/lib-esm/trackers/EventTracker.js +94 -0
- package/lib-esm/trackers/PageViewTracker.d.ts +18 -0
- package/lib-esm/trackers/PageViewTracker.js +108 -0
- package/lib-esm/trackers/SessionTracker.d.ts +13 -0
- package/lib-esm/trackers/SessionTracker.js +63 -0
- package/lib-esm/trackers/SessionTracker.native.d.ts +13 -0
- package/lib-esm/trackers/SessionTracker.native.js +63 -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 +59 -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 +8 -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 +9 -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/lib-esm/utils/userAgent.js +2 -2
- package/package.json +39 -12
- 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 +109 -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 +117 -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 +110 -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 +105 -0
- package/src/trackers/SessionTracker.ts +105 -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
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import {
|
|
3
|
+
import { Hub, ConsoleLogger } from '@aws-amplify/core';
|
|
4
|
+
import { AMPLIFY_SYMBOL, AnalyticsAction, } from '@aws-amplify/core/internals/utils';
|
|
4
5
|
import { record as recordCore } from '@aws-amplify/core/internals/providers/pinpoint';
|
|
5
6
|
import { AnalyticsValidationErrorCode, assertValidationError, } from '../../../errors';
|
|
6
|
-
import { getAnalyticsUserAgentString } from '../../../utils
|
|
7
|
+
import { getAnalyticsUserAgentString, isAnalyticsEnabled, } from '../../../utils';
|
|
7
8
|
import { resolveConfig, resolveCredentials } from '../utils';
|
|
8
|
-
|
|
9
|
+
const logger = new ConsoleLogger('Analytics');
|
|
9
10
|
/**
|
|
10
11
|
* Records an Analytic event to Pinpoint. Events will be buffered and periodically sent to Pinpoint.
|
|
11
12
|
*
|
|
@@ -17,48 +18,44 @@ var logger = new Logger('Analytics');
|
|
|
17
18
|
* @example
|
|
18
19
|
* ```ts
|
|
19
20
|
* // Send an event to Pinpoint
|
|
20
|
-
* record({
|
|
21
|
-
* event: {
|
|
22
|
-
* name: eventName,
|
|
23
|
-
* }
|
|
24
|
-
* })
|
|
21
|
+
* record({ name: eventName })
|
|
25
22
|
* ```
|
|
26
23
|
*
|
|
27
24
|
* @example
|
|
28
25
|
* ```ts
|
|
29
26
|
* // Send an event to Pinpoint with metrics & custom attributes
|
|
30
27
|
* record({
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* 'my-metric': metricValue
|
|
38
|
-
* }
|
|
28
|
+
* name: eventName,
|
|
29
|
+
* attributes: {
|
|
30
|
+
* 'my-attribute': attributeValue
|
|
31
|
+
* },
|
|
32
|
+
* metrics: {
|
|
33
|
+
* 'my-metric': metricValue
|
|
39
34
|
* }
|
|
40
35
|
* })
|
|
41
36
|
* ```
|
|
42
37
|
*/
|
|
43
|
-
export
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
export const record = (input) => {
|
|
39
|
+
const { appId, region } = resolveConfig();
|
|
40
|
+
if (!isAnalyticsEnabled()) {
|
|
41
|
+
logger.debug('Analytics is disabled, event will not be recorded.');
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
assertValidationError(!!input.name, AnalyticsValidationErrorCode.NoEventName);
|
|
48
45
|
resolveCredentials()
|
|
49
|
-
.then(
|
|
50
|
-
|
|
46
|
+
.then(({ credentials, identityId }) => {
|
|
47
|
+
Hub.dispatch('analytics', { event: 'record', data: input, message: 'Recording Analytics event' }, 'Analytics', AMPLIFY_SYMBOL);
|
|
51
48
|
recordCore({
|
|
52
|
-
appId
|
|
49
|
+
appId,
|
|
53
50
|
category: 'Analytics',
|
|
54
|
-
credentials
|
|
55
|
-
event:
|
|
56
|
-
identityId
|
|
57
|
-
region
|
|
51
|
+
credentials,
|
|
52
|
+
event: input,
|
|
53
|
+
identityId,
|
|
54
|
+
region,
|
|
58
55
|
userAgentValue: getAnalyticsUserAgentString(AnalyticsAction.Record),
|
|
59
56
|
});
|
|
60
57
|
})
|
|
61
|
-
.catch(
|
|
58
|
+
.catch(e => {
|
|
62
59
|
// An error occured while fetching credentials or persisting the event to the buffer
|
|
63
60
|
logger.warn('Failed to record event.', e);
|
|
64
61
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { record, identifyUser } from './apis';
|
|
2
|
-
export { RecordInput, IdentifyUserInput } from './types/inputs';
|
|
1
|
+
export { record, identifyUser, flushEvents, configureAutoTrack } from './apis';
|
|
2
|
+
export { RecordInput, IdentifyUserInput, ConfigureAutoTrackInput, } from './types/inputs';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { RecordInput, IdentifyUserInput, ConfigureAutoTrackInput, } from './inputs';
|
|
2
|
+
export { IdentifyUserOptions } from './options';
|
|
@@ -1,24 +1,15 @@
|
|
|
1
|
-
import { UserProfile } from '@aws-amplify/core';
|
|
2
1
|
import { PinpointAnalyticsEvent } from '@aws-amplify/core/internals/providers/pinpoint';
|
|
2
|
+
import { IdentifyUserOptions } from '.';
|
|
3
|
+
import { AnalyticsConfigureAutoTrackInput, AnalyticsIdentifyUserInput } from '../../../types';
|
|
3
4
|
/**
|
|
4
5
|
* Input type for Pinpoint record API.
|
|
5
6
|
*/
|
|
6
|
-
export type RecordInput =
|
|
7
|
-
/**
|
|
8
|
-
* An event to send to the default Analytics provider.
|
|
9
|
-
*/
|
|
10
|
-
event: PinpointAnalyticsEvent;
|
|
11
|
-
};
|
|
7
|
+
export type RecordInput = PinpointAnalyticsEvent;
|
|
12
8
|
/**
|
|
13
9
|
* Input type for Pinpoint identifyUser API.
|
|
14
10
|
*/
|
|
15
|
-
export type IdentifyUserInput =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Additional information about the user and their device.
|
|
22
|
-
*/
|
|
23
|
-
userProfile: UserProfile;
|
|
24
|
-
};
|
|
11
|
+
export type IdentifyUserInput = AnalyticsIdentifyUserInput<IdentifyUserOptions>;
|
|
12
|
+
/**
|
|
13
|
+
* Input type for Pinpoint configureAutoTrack API.
|
|
14
|
+
*/
|
|
15
|
+
export type ConfigureAutoTrackInput = AnalyticsConfigureAutoTrackInput;
|
|
@@ -5,10 +5,9 @@ import { AnalyticsValidationErrorCode, assertValidationError, } from '../../../e
|
|
|
5
5
|
/**
|
|
6
6
|
* @internal
|
|
7
7
|
*/
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
var _c = (_b = (_a = Amplify.getConfig().Analytics) === null || _a === void 0 ? void 0 : _a.Pinpoint) !== null && _b !== void 0 ? _b : {}, appId = _c.appId, region = _c.region;
|
|
8
|
+
export const resolveConfig = () => {
|
|
9
|
+
const { appId, region } = Amplify.getConfig().Analytics?.Pinpoint ?? {};
|
|
11
10
|
assertValidationError(!!appId, AnalyticsValidationErrorCode.NoAppId);
|
|
12
11
|
assertValidationError(!!region, AnalyticsValidationErrorCode.NoRegion);
|
|
13
|
-
return { appId
|
|
12
|
+
return { appId, region };
|
|
14
13
|
};
|
|
@@ -2,11 +2,6 @@
|
|
|
2
2
|
* @internal
|
|
3
3
|
*/
|
|
4
4
|
export declare const resolveCredentials: () => Promise<{
|
|
5
|
-
credentials:
|
|
6
|
-
accessKeyId: string;
|
|
7
|
-
secretAccessKey: string;
|
|
8
|
-
sessionToken?: string | undefined;
|
|
9
|
-
expiration?: Date | undefined;
|
|
10
|
-
};
|
|
5
|
+
credentials: import("@aws-amplify/core/lib-esm/libraryUtils").AWSCredentials;
|
|
11
6
|
identityId: string | undefined;
|
|
12
7
|
}>;
|
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { __awaiter, __generator } from "tslib";
|
|
4
3
|
import { fetchAuthSession } from '@aws-amplify/core';
|
|
5
4
|
import { AnalyticsValidationErrorCode, assertValidationError, } from '../../../errors';
|
|
6
5
|
/**
|
|
7
6
|
* @internal
|
|
8
7
|
*/
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
case 1:
|
|
15
|
-
_a = _b.sent(), credentials = _a.credentials, identityId = _a.identityId;
|
|
16
|
-
assertValidationError(!!credentials, AnalyticsValidationErrorCode.NoCredentials);
|
|
17
|
-
return [2 /*return*/, { credentials: credentials, identityId: identityId }];
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
}); };
|
|
8
|
+
export const resolveCredentials = async () => {
|
|
9
|
+
const { credentials, identityId } = await fetchAuthSession();
|
|
10
|
+
assertValidationError(!!credentials, AnalyticsValidationErrorCode.NoCredentials);
|
|
11
|
+
return { credentials, identityId };
|
|
12
|
+
};
|
package/lib-esm/setupTests.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
|
|
4
|
+
const anyGlobal = global;
|
|
5
5
|
anyGlobal.navigator = anyGlobal.navigator || {};
|
|
6
6
|
// @ts-ignore
|
|
7
7
|
anyGlobal.navigator.sendBeacon = anyGlobal.navigator.sendBeacon || jest.fn();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { EventTrackingOptions, TrackerEventRecorder, TrackerInterface } from '../types/trackers';
|
|
2
|
+
export declare class EventTracker implements TrackerInterface {
|
|
3
|
+
private trackerActive;
|
|
4
|
+
private options;
|
|
5
|
+
private eventRecorder;
|
|
6
|
+
constructor(eventRecorder: TrackerEventRecorder, options?: EventTrackingOptions);
|
|
7
|
+
configure(eventRecorder: TrackerEventRecorder, options?: EventTrackingOptions): void;
|
|
8
|
+
cleanup(): void;
|
|
9
|
+
private handleDocEvent;
|
|
10
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
4
|
+
import { isBrowser } from '@aws-amplify/core/internals/utils';
|
|
5
|
+
const DEFAULT_EVENTS = ['click'];
|
|
6
|
+
const DEFAULT_SELECTOR_PREFIX = 'data-amplify-analytics-';
|
|
7
|
+
const DEFAULT_EVENT_NAME = 'event'; // Default event name as sent to the analytics provider
|
|
8
|
+
const logger = new ConsoleLogger('EventTracker');
|
|
9
|
+
export class EventTracker {
|
|
10
|
+
constructor(eventRecorder, options) {
|
|
11
|
+
this.options = {};
|
|
12
|
+
this.trackerActive = false;
|
|
13
|
+
this.eventRecorder = eventRecorder;
|
|
14
|
+
this.handleDocEvent = this.handleDocEvent.bind(this);
|
|
15
|
+
this.configure(eventRecorder, options);
|
|
16
|
+
}
|
|
17
|
+
configure(eventRecorder, options) {
|
|
18
|
+
this.eventRecorder = eventRecorder;
|
|
19
|
+
// Clean up any existing listeners
|
|
20
|
+
this.cleanup();
|
|
21
|
+
// Apply defaults
|
|
22
|
+
this.options = {
|
|
23
|
+
attributes: options?.attributes ?? undefined,
|
|
24
|
+
events: options?.events ?? DEFAULT_EVENTS,
|
|
25
|
+
selectorPrefix: options?.selectorPrefix ?? DEFAULT_SELECTOR_PREFIX,
|
|
26
|
+
};
|
|
27
|
+
// Register event listeners
|
|
28
|
+
if (isBrowser()) {
|
|
29
|
+
this.options.events?.forEach(targetEvent => {
|
|
30
|
+
document.addEventListener(targetEvent, this.handleDocEvent, {
|
|
31
|
+
capture: true,
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
this.trackerActive = true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
cleanup() {
|
|
38
|
+
// No-op if document listener is not active
|
|
39
|
+
if (!this.trackerActive) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
// Clean up event listeners
|
|
43
|
+
this.options.events?.forEach(targetEvent => {
|
|
44
|
+
document.removeEventListener(targetEvent, this.handleDocEvent, {
|
|
45
|
+
capture: true,
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
handleDocEvent(event) {
|
|
50
|
+
/**
|
|
51
|
+
* Example DOM element:
|
|
52
|
+
*
|
|
53
|
+
* ```
|
|
54
|
+
* <button
|
|
55
|
+
* data-amplify-analytics-on="click"
|
|
56
|
+
* data-amplify-analytics-name="click"
|
|
57
|
+
* data-amplify-analytics-attrs="attr1:attr1_value,attr2:attr2_value"
|
|
58
|
+
* />
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
const triggerSelector = `[${this.options.selectorPrefix}on]`;
|
|
62
|
+
const attrSelector = `${this.options.selectorPrefix}attrs`;
|
|
63
|
+
const eventNameSelector = `${this.options.selectorPrefix}name`;
|
|
64
|
+
const eventSource = event.target;
|
|
65
|
+
// Validate that the triggering event type is being tracked
|
|
66
|
+
if (!this.options.events?.includes(event.type)) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (eventSource instanceof HTMLElement) {
|
|
70
|
+
const target = eventSource.closest(triggerSelector);
|
|
71
|
+
if (target) {
|
|
72
|
+
// Parse event name from the element
|
|
73
|
+
const eventName = target.getAttribute(eventNameSelector) || DEFAULT_EVENT_NAME;
|
|
74
|
+
// Parse attributes from the element
|
|
75
|
+
const elementAttributes = {};
|
|
76
|
+
const rawElementAttributes = target.getAttribute(attrSelector);
|
|
77
|
+
rawElementAttributes?.split(/\s*,\s*/).forEach(attr => {
|
|
78
|
+
const tmp = attr.trim().split(/\s*:\s*/);
|
|
79
|
+
elementAttributes[tmp[0]] = tmp[1];
|
|
80
|
+
});
|
|
81
|
+
// Assemble final list of attributes
|
|
82
|
+
const attributes = Object.assign({
|
|
83
|
+
type: event.type,
|
|
84
|
+
target: `${target.localName} with id ${target.id}`,
|
|
85
|
+
}, this.options.attributes, elementAttributes);
|
|
86
|
+
logger.debug('Recording automatically tracked DOM event', {
|
|
87
|
+
eventName,
|
|
88
|
+
attributes,
|
|
89
|
+
});
|
|
90
|
+
this.eventRecorder(eventName, attributes);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PageViewTrackingOptions, TrackerEventRecorder, TrackerInterface } from '../types/trackers';
|
|
2
|
+
export declare class PageViewTracker implements TrackerInterface {
|
|
3
|
+
private trackerActive;
|
|
4
|
+
private options;
|
|
5
|
+
private eventRecorder;
|
|
6
|
+
private spaTrackingActive;
|
|
7
|
+
private pushStateProxy?;
|
|
8
|
+
private replaceStateProxy?;
|
|
9
|
+
private originalPushState;
|
|
10
|
+
private originalReplaceState;
|
|
11
|
+
constructor(eventRecorder: TrackerEventRecorder, options?: PageViewTrackingOptions);
|
|
12
|
+
configure(eventRecorder: TrackerEventRecorder, options?: PageViewTrackingOptions): void;
|
|
13
|
+
cleanup(): void;
|
|
14
|
+
private setupSPATracking;
|
|
15
|
+
private setupMPATracking;
|
|
16
|
+
private handleLocationChange;
|
|
17
|
+
private urlHasChanged;
|
|
18
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
4
|
+
import { isBrowser } from '@aws-amplify/core/internals/utils';
|
|
5
|
+
const logger = new ConsoleLogger('PageViewTracker');
|
|
6
|
+
const DEFAULT_EVENT_NAME = 'pageView';
|
|
7
|
+
const DEFAULT_APP_TYPE = 'singlePage';
|
|
8
|
+
const DEFAULT_URL_PROVIDER = () => {
|
|
9
|
+
return window.location.origin + window.location.pathname;
|
|
10
|
+
};
|
|
11
|
+
const PREV_URL_STORAGE_KEY = 'aws-amplify-analytics-prevUrl';
|
|
12
|
+
export class PageViewTracker {
|
|
13
|
+
constructor(eventRecorder, options) {
|
|
14
|
+
this.options = {};
|
|
15
|
+
this.trackerActive = true;
|
|
16
|
+
this.eventRecorder = eventRecorder;
|
|
17
|
+
this.spaTrackingActive = false;
|
|
18
|
+
this.handleLocationChange = this.handleLocationChange.bind(this);
|
|
19
|
+
this.configure(eventRecorder, options);
|
|
20
|
+
}
|
|
21
|
+
configure(eventRecorder, options) {
|
|
22
|
+
this.eventRecorder = eventRecorder;
|
|
23
|
+
// Clean up any existing listeners
|
|
24
|
+
this.cleanup();
|
|
25
|
+
// Apply defaults
|
|
26
|
+
this.options = {
|
|
27
|
+
appType: options?.appType ?? DEFAULT_APP_TYPE,
|
|
28
|
+
attributes: options?.attributes ?? undefined,
|
|
29
|
+
eventName: this.options?.eventName ?? DEFAULT_EVENT_NAME,
|
|
30
|
+
urlProvider: this.options?.urlProvider ?? DEFAULT_URL_PROVIDER,
|
|
31
|
+
};
|
|
32
|
+
// Configure SPA or MPA page view tracking
|
|
33
|
+
if (isBrowser()) {
|
|
34
|
+
if (this.options.appType === 'singlePage') {
|
|
35
|
+
this.setupSPATracking();
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
this.setupMPATracking();
|
|
39
|
+
}
|
|
40
|
+
this.trackerActive = true;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
cleanup() {
|
|
44
|
+
// No-op if document listener is not active
|
|
45
|
+
if (!this.trackerActive) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
// Clean up SPA page view listeners
|
|
49
|
+
if (this.spaTrackingActive) {
|
|
50
|
+
window.history.pushState = this.originalPushState;
|
|
51
|
+
window.history.replaceState = this.originalReplaceState;
|
|
52
|
+
this.pushStateProxy?.revoke();
|
|
53
|
+
this.replaceStateProxy?.revoke();
|
|
54
|
+
window.removeEventListener('popstate', this.handleLocationChange);
|
|
55
|
+
this.spaTrackingActive = false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
setupSPATracking() {
|
|
59
|
+
if (!this.spaTrackingActive) {
|
|
60
|
+
// Configure proxies on History APIs
|
|
61
|
+
this.pushStateProxy = Proxy.revocable(window.history.pushState, {
|
|
62
|
+
apply: (target, thisArg, args) => {
|
|
63
|
+
const proxiedResult = target.apply(thisArg, args);
|
|
64
|
+
this.handleLocationChange();
|
|
65
|
+
return proxiedResult;
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
this.replaceStateProxy = Proxy.revocable(window.history.replaceState, {
|
|
69
|
+
apply: (target, thisArg, args) => {
|
|
70
|
+
const proxiedResult = target.apply(thisArg, args);
|
|
71
|
+
this.handleLocationChange();
|
|
72
|
+
return proxiedResult;
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
this.originalPushState = window.history.pushState;
|
|
76
|
+
this.originalReplaceState = window.history.replaceState;
|
|
77
|
+
window.history.pushState = this.pushStateProxy.proxy;
|
|
78
|
+
window.history.replaceState = this.replaceStateProxy.proxy;
|
|
79
|
+
window.addEventListener('popstate', this.handleLocationChange);
|
|
80
|
+
sessionStorage.removeItem(PREV_URL_STORAGE_KEY);
|
|
81
|
+
this.spaTrackingActive = true;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
setupMPATracking() {
|
|
85
|
+
this.handleLocationChange();
|
|
86
|
+
}
|
|
87
|
+
handleLocationChange() {
|
|
88
|
+
const currentUrl = this.options.urlProvider();
|
|
89
|
+
const eventName = this.options.eventName || DEFAULT_EVENT_NAME;
|
|
90
|
+
if (this.urlHasChanged()) {
|
|
91
|
+
sessionStorage.setItem(PREV_URL_STORAGE_KEY, currentUrl);
|
|
92
|
+
// Assemble attribute list
|
|
93
|
+
const attributes = Object.assign({
|
|
94
|
+
url: currentUrl,
|
|
95
|
+
}, this.options.attributes);
|
|
96
|
+
logger.debug('Recording automatically tracked page view event', {
|
|
97
|
+
eventName,
|
|
98
|
+
attributes,
|
|
99
|
+
});
|
|
100
|
+
this.eventRecorder(eventName, attributes);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
urlHasChanged() {
|
|
104
|
+
const prevUrl = sessionStorage.getItem(PREV_URL_STORAGE_KEY);
|
|
105
|
+
const currUrl = this.options.urlProvider();
|
|
106
|
+
return currUrl !== prevUrl;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SessionTrackingOptions, TrackerEventRecorder, TrackerInterface } from '../types/trackers';
|
|
2
|
+
export declare class SessionTracker implements TrackerInterface {
|
|
3
|
+
private options;
|
|
4
|
+
private eventRecorder;
|
|
5
|
+
private sessionTrackingActive;
|
|
6
|
+
private initialEventSent;
|
|
7
|
+
constructor(eventRecorder: TrackerEventRecorder, options?: SessionTrackingOptions);
|
|
8
|
+
configure(eventRecorder: TrackerEventRecorder, options?: SessionTrackingOptions): void;
|
|
9
|
+
cleanup(): void;
|
|
10
|
+
private handleStateChange;
|
|
11
|
+
private sessionStarted;
|
|
12
|
+
private sessionStopped;
|
|
13
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { sessionListener, SESSION_START_EVENT, SESSION_STOP_EVENT, } from '@aws-amplify/core/internals/utils';
|
|
4
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
5
|
+
const logger = new ConsoleLogger('SessionTracker');
|
|
6
|
+
export class SessionTracker {
|
|
7
|
+
constructor(eventRecorder, options) {
|
|
8
|
+
this.options = {};
|
|
9
|
+
this.eventRecorder = eventRecorder;
|
|
10
|
+
this.sessionTrackingActive = false;
|
|
11
|
+
this.initialEventSent = false;
|
|
12
|
+
this.handleStateChange = this.handleStateChange.bind(this);
|
|
13
|
+
this.configure(eventRecorder, options);
|
|
14
|
+
}
|
|
15
|
+
configure(eventRecorder, options) {
|
|
16
|
+
this.eventRecorder = eventRecorder;
|
|
17
|
+
// Clean up any existing listeners
|
|
18
|
+
this.cleanup();
|
|
19
|
+
// Apply defaults
|
|
20
|
+
this.options = {
|
|
21
|
+
attributes: options?.attributes ?? {},
|
|
22
|
+
};
|
|
23
|
+
// Setup state listeners
|
|
24
|
+
if (!this.sessionTrackingActive) {
|
|
25
|
+
sessionListener.addStateChangeListener(this.handleStateChange, !this.initialEventSent);
|
|
26
|
+
this.sessionTrackingActive = true;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
cleanup() {
|
|
30
|
+
if (this.sessionTrackingActive) {
|
|
31
|
+
sessionListener.removeStateChangeListener(this.handleStateChange);
|
|
32
|
+
}
|
|
33
|
+
this.sessionTrackingActive = false;
|
|
34
|
+
}
|
|
35
|
+
handleStateChange(state) {
|
|
36
|
+
if (state === 'started') {
|
|
37
|
+
this.sessionStarted();
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
this.sessionStopped();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
sessionStarted() {
|
|
44
|
+
const attributes = this.options.attributes ?? {};
|
|
45
|
+
logger.debug('Recording automatically tracked page view event', {
|
|
46
|
+
SESSION_START_EVENT,
|
|
47
|
+
attributes,
|
|
48
|
+
});
|
|
49
|
+
this.eventRecorder(SESSION_START_EVENT, attributes);
|
|
50
|
+
// NOTE: The initial event will not be re-sent on re-configuration (e.g. to add additional custom attributes)
|
|
51
|
+
if (!this.initialEventSent) {
|
|
52
|
+
this.initialEventSent = true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
sessionStopped() {
|
|
56
|
+
const attributes = this.options.attributes ?? {};
|
|
57
|
+
logger.debug('Recording automatically tracked page view event', {
|
|
58
|
+
SESSION_STOP_EVENT,
|
|
59
|
+
attributes,
|
|
60
|
+
});
|
|
61
|
+
this.eventRecorder(SESSION_STOP_EVENT, attributes);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SessionTrackingOptions, TrackerEventRecorder, TrackerInterface } from '../types/trackers';
|
|
2
|
+
export declare class SessionTracker implements TrackerInterface {
|
|
3
|
+
private options;
|
|
4
|
+
private eventRecorder;
|
|
5
|
+
private initialEventSent;
|
|
6
|
+
private sessionTrackingActive;
|
|
7
|
+
constructor(eventRecorder: TrackerEventRecorder, options?: SessionTrackingOptions);
|
|
8
|
+
configure(eventRecorder: TrackerEventRecorder, options?: SessionTrackingOptions): void;
|
|
9
|
+
cleanup(): void;
|
|
10
|
+
private handleStateChange;
|
|
11
|
+
private sessionStarted;
|
|
12
|
+
private sessionStopped;
|
|
13
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { sessionListener, SESSION_START_EVENT, SESSION_STOP_EVENT, } from '@aws-amplify/core/internals/utils';
|
|
4
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
5
|
+
const logger = new ConsoleLogger('SessionTracker');
|
|
6
|
+
export class SessionTracker {
|
|
7
|
+
constructor(eventRecorder, options) {
|
|
8
|
+
this.options = {};
|
|
9
|
+
this.eventRecorder = eventRecorder;
|
|
10
|
+
this.initialEventSent = false;
|
|
11
|
+
this.sessionTrackingActive = false;
|
|
12
|
+
this.handleStateChange = this.handleStateChange.bind(this);
|
|
13
|
+
this.configure(eventRecorder, options);
|
|
14
|
+
}
|
|
15
|
+
configure(eventRecorder, options) {
|
|
16
|
+
this.eventRecorder = eventRecorder;
|
|
17
|
+
// Clean up any existing listeners
|
|
18
|
+
this.cleanup();
|
|
19
|
+
// Apply defaults
|
|
20
|
+
this.options = {
|
|
21
|
+
attributes: options?.attributes ?? {},
|
|
22
|
+
};
|
|
23
|
+
// Setup state listeners
|
|
24
|
+
if (!this.sessionTrackingActive) {
|
|
25
|
+
sessionListener.addStateChangeListener(this.handleStateChange, !this.initialEventSent);
|
|
26
|
+
this.sessionTrackingActive = true;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
cleanup() {
|
|
30
|
+
if (this.sessionTrackingActive) {
|
|
31
|
+
sessionListener.removeStateChangeListener(this.handleStateChange);
|
|
32
|
+
}
|
|
33
|
+
this.sessionTrackingActive = false;
|
|
34
|
+
}
|
|
35
|
+
handleStateChange(state) {
|
|
36
|
+
if (state === 'started') {
|
|
37
|
+
this.sessionStarted();
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
this.sessionStopped();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
sessionStarted() {
|
|
44
|
+
const attributes = this.options.attributes ?? {};
|
|
45
|
+
logger.debug('Recording automatically tracked page view event', {
|
|
46
|
+
SESSION_START_EVENT,
|
|
47
|
+
attributes,
|
|
48
|
+
});
|
|
49
|
+
this.eventRecorder(SESSION_START_EVENT, attributes);
|
|
50
|
+
// NOTE: The initial event will not be re-sent on re-configuration (e.g. to add additional custom attributes)
|
|
51
|
+
if (!this.initialEventSent) {
|
|
52
|
+
this.initialEventSent = true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
sessionStopped() {
|
|
56
|
+
const attributes = this.options.attributes ?? {};
|
|
57
|
+
logger.debug('Recording automatically tracked page view event', {
|
|
58
|
+
SESSION_STOP_EVENT,
|
|
59
|
+
attributes,
|
|
60
|
+
});
|
|
61
|
+
this.eventRecorder(SESSION_STOP_EVENT, attributes);
|
|
62
|
+
}
|
|
63
|
+
}
|