@aws-amplify/analytics 7.0.1-api-v6-models.9351bcf.0 → 7.0.1-api-v6-models.891fe0d.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/lib/apis/disable.js +1 -1
- package/lib/apis/enable.js +1 -1
- package/lib/errors/AnalyticsError.js +7 -11
- package/lib/errors/assertValidationError.js +6 -6
- package/lib/errors/validation.js +10 -11
- package/lib/providers/kinesis/apis/flushEvents.js +20 -23
- package/lib/providers/kinesis/apis/record.js +24 -26
- package/lib/providers/kinesis/utils/getEventBuffer.js +39 -70
- package/lib/providers/kinesis/utils/resolveConfig.js +14 -13
- package/lib/providers/kinesis-firehose/apis/flushEvents.js +19 -22
- package/lib/providers/kinesis-firehose/apis/record.js +22 -24
- package/lib/providers/kinesis-firehose/utils/getEventBuffer.js +39 -68
- package/lib/providers/kinesis-firehose/utils/resolveConfig.js +14 -13
- package/lib/providers/personalize/apis/flushEvents.js +18 -21
- package/lib/providers/personalize/apis/record.js +55 -71
- package/lib/providers/personalize/utils/autoTrackMedia.js +96 -98
- package/lib/providers/personalize/utils/cachedSession.js +30 -42
- package/lib/providers/personalize/utils/getEventBuffer.js +35 -62
- package/lib/providers/personalize/utils/resolveConfig.js +14 -13
- package/lib/providers/pinpoint/apis/configureAutoTrack.js +6 -6
- package/lib/providers/pinpoint/apis/flushEvents.js +10 -13
- package/lib/providers/pinpoint/apis/identifyUser.js +18 -30
- package/lib/providers/pinpoint/apis/record.js +15 -16
- package/lib/providers/pinpoint/utils/resolveConfig.js +5 -6
- package/lib/providers/pinpoint/utils/resolveCredentials.js +7 -15
- package/lib/setupTests.js +1 -1
- package/lib/trackers/EventTracker.js +39 -45
- package/lib/trackers/PageViewTracker.js +41 -45
- package/lib/trackers/SessionTracker.js +25 -31
- package/lib/trackers/SessionTracker.native.js +25 -31
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/utils/eventBuffer/EventBuffer.js +34 -62
- package/lib/utils/groupBy.js +4 -7
- package/lib/utils/resolveCredentials.js +7 -15
- package/lib/utils/statusHelpers.js +4 -4
- package/lib/utils/trackerConfigHelpers.js +2 -2
- package/lib/utils/trackerConfigHelpers.native.js +2 -2
- package/lib/utils/trackerHelpers.js +5 -5
- package/lib/utils/userAgent.js +3 -3
- package/lib-esm/apis/disable.js +1 -1
- package/lib-esm/apis/enable.js +1 -1
- package/lib-esm/errors/AnalyticsError.js +6 -11
- package/lib-esm/errors/assertValidationError.js +4 -4
- package/lib-esm/errors/validation.js +10 -11
- package/lib-esm/providers/kinesis/apis/flushEvents.js +15 -18
- package/lib-esm/providers/kinesis/apis/record.js +18 -20
- package/lib-esm/providers/kinesis/utils/constants.js +1 -1
- package/lib-esm/providers/kinesis/utils/getEventBuffer.js +37 -68
- package/lib-esm/providers/kinesis/utils/resolveConfig.js +11 -10
- package/lib-esm/providers/kinesis-firehose/apis/flushEvents.js +15 -18
- package/lib-esm/providers/kinesis-firehose/apis/record.js +17 -19
- package/lib-esm/providers/kinesis-firehose/utils/constants.js +1 -1
- package/lib-esm/providers/kinesis-firehose/utils/getEventBuffer.js +37 -66
- package/lib-esm/providers/kinesis-firehose/utils/resolveConfig.js +11 -10
- package/lib-esm/providers/personalize/apis/flushEvents.js +14 -17
- package/lib-esm/providers/personalize/apis/record.js +50 -66
- package/lib-esm/providers/personalize/utils/autoTrackMedia.js +94 -96
- package/lib-esm/providers/personalize/utils/cachedSession.js +28 -40
- package/lib-esm/providers/personalize/utils/constants.js +4 -4
- package/lib-esm/providers/personalize/utils/getEventBuffer.js +33 -60
- package/lib-esm/providers/personalize/utils/resolveConfig.js +11 -10
- package/lib-esm/providers/pinpoint/apis/configureAutoTrack.js +4 -4
- package/lib-esm/providers/pinpoint/apis/flushEvents.js +5 -8
- package/lib-esm/providers/pinpoint/apis/identifyUser.js +14 -26
- package/lib-esm/providers/pinpoint/apis/record.js +9 -10
- package/lib-esm/providers/pinpoint/utils/resolveConfig.js +3 -4
- package/lib-esm/providers/pinpoint/utils/resolveCredentials.js +5 -13
- package/lib-esm/setupTests.js +1 -1
- package/lib-esm/trackers/EventTracker.js +37 -44
- package/lib-esm/trackers/PageViewTracker.js +39 -44
- package/lib-esm/trackers/SessionTracker.js +22 -29
- package/lib-esm/trackers/SessionTracker.native.js +22 -29
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/utils/eventBuffer/EventBuffer.js +33 -62
- package/lib-esm/utils/groupBy.js +4 -7
- package/lib-esm/utils/resolveCredentials.js +5 -13
- package/lib-esm/utils/statusHelpers.js +4 -4
- package/lib-esm/utils/trackerConfigHelpers.js +1 -1
- package/lib-esm/utils/trackerConfigHelpers.native.js +1 -1
- package/lib-esm/utils/trackerHelpers.js +4 -4
- package/lib-esm/utils/userAgent.js +2 -2
- package/package.json +6 -9
- package/src/providers/kinesis/utils/getEventBuffer.ts +6 -7
- package/src/providers/kinesis-firehose/utils/getEventBuffer.ts +6 -7
- package/src/providers/personalize/utils/getEventBuffer.ts +6 -7
- package/src/trackers/SessionTracker.native.ts +2 -3
- package/src/trackers/SessionTracker.ts +2 -3
|
@@ -3,54 +3,42 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.updateCachedSession = exports.resolveCachedSession = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var getCache = function (key) { return core_1.Cache.getItem(normalize(key)); };
|
|
18
|
-
var setCache = function (key, value) {
|
|
19
|
-
var expiredAt = new Date(Date.now() + 3600000 * 24 * CACHE_EXPIRY_IN_DAYS);
|
|
6
|
+
const core_1 = require("@aws-amplify/core");
|
|
7
|
+
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
8
|
+
const PERSONALIZE_CACHE_USERID = '_awsct_uid';
|
|
9
|
+
const PERSONALIZE_CACHE_SESSIONID = '_awsct_sid';
|
|
10
|
+
const DEFAULT_CACHE_PREFIX = 'personalize';
|
|
11
|
+
const DELIMITER = '.';
|
|
12
|
+
const CACHE_EXPIRY_IN_DAYS = 7;
|
|
13
|
+
const normalize = (key) => [key, (0, utils_1.isBrowser)() ? window.location.host : DEFAULT_CACHE_PREFIX].join(DELIMITER);
|
|
14
|
+
const getCache = (key) => core_1.Cache.getItem(normalize(key));
|
|
15
|
+
const setCache = (key, value) => {
|
|
16
|
+
const expiredAt = new Date(Date.now() + 3600000 * 24 * CACHE_EXPIRY_IN_DAYS);
|
|
20
17
|
core_1.Cache.setItem(normalize(key), value, {
|
|
21
18
|
expires: expiredAt.getTime(),
|
|
22
19
|
});
|
|
23
20
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
case 2:
|
|
37
|
-
userId = _a.sent();
|
|
38
|
-
return [2 /*return*/, {
|
|
39
|
-
sessionId: sessionId,
|
|
40
|
-
userId: userId,
|
|
41
|
-
}];
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}); };
|
|
21
|
+
const resolveCachedSession = async () => {
|
|
22
|
+
let sessionId = await getCache(PERSONALIZE_CACHE_SESSIONID);
|
|
23
|
+
if (!sessionId) {
|
|
24
|
+
sessionId = (0, utils_1.amplifyUuid)();
|
|
25
|
+
setCache(PERSONALIZE_CACHE_SESSIONID, sessionId);
|
|
26
|
+
}
|
|
27
|
+
const userId = await getCache(PERSONALIZE_CACHE_USERID);
|
|
28
|
+
return {
|
|
29
|
+
sessionId,
|
|
30
|
+
userId,
|
|
31
|
+
};
|
|
32
|
+
};
|
|
45
33
|
exports.resolveCachedSession = resolveCachedSession;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
34
|
+
const updateCachedSession = (newUserId, currentSessionId, currentUserId) => {
|
|
35
|
+
const isNoCachedSession = !currentSessionId;
|
|
36
|
+
const isSignOutCase = !newUserId && !currentUserId;
|
|
37
|
+
const isSwitchUserCase = !!newUserId && !!currentUserId && newUserId !== currentUserId;
|
|
38
|
+
const isRequireNewSession = isNoCachedSession || isSignOutCase || isSwitchUserCase;
|
|
39
|
+
const isRequireUpdateSession = !!currentSessionId && !currentUserId && !!newUserId;
|
|
52
40
|
if (isRequireNewSession) {
|
|
53
|
-
|
|
41
|
+
const newSessionId = (0, utils_1.amplifyUuid)();
|
|
54
42
|
setCache(PERSONALIZE_CACHE_SESSIONID, newSessionId);
|
|
55
43
|
setCache(PERSONALIZE_CACHE_USERID, newUserId);
|
|
56
44
|
}
|
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.getEventBuffer = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var client_personalize_events_1 = require("@aws-sdk/client-personalize-events");
|
|
6
|
+
const utils_1 = require("../../../utils");
|
|
7
|
+
const client_personalize_events_1 = require("@aws-sdk/client-personalize-events");
|
|
9
8
|
/**
|
|
10
9
|
* These Records hold cached event buffers and AWS clients.
|
|
11
10
|
* The hash key is determined by the region and session,
|
|
@@ -14,85 +13,59 @@ var client_personalize_events_1 = require("@aws-sdk/client-personalize-events");
|
|
|
14
13
|
* Only one active session should exist at any given moment.
|
|
15
14
|
* When a new session is initiated, the previous ones should be released.
|
|
16
15
|
* */
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
const eventBufferMap = {};
|
|
17
|
+
const cachedClients = {};
|
|
18
|
+
const DELIMITER = '#';
|
|
19
|
+
const createPutEventsCommand = (ids, events) => {
|
|
20
|
+
const [trackingId, sessionId, userId] = ids.split(DELIMITER);
|
|
22
21
|
return new client_personalize_events_1.PutEventsCommand({
|
|
23
|
-
trackingId
|
|
24
|
-
sessionId
|
|
25
|
-
userId
|
|
26
|
-
eventList: events.map(
|
|
22
|
+
trackingId,
|
|
23
|
+
sessionId,
|
|
24
|
+
userId,
|
|
25
|
+
eventList: events.map(event => ({
|
|
27
26
|
eventId: event.event.eventId,
|
|
28
27
|
eventType: event.event.eventType,
|
|
29
28
|
properties: JSON.stringify(event.event.properties),
|
|
30
29
|
sentAt: new Date(event.timestamp),
|
|
31
|
-
})
|
|
30
|
+
})),
|
|
32
31
|
});
|
|
33
32
|
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
var _b = tslib_1.__read(_a, 2), ids = _b[0], events = _b[1];
|
|
47
|
-
return createPutEventsCommand(ids, events);
|
|
48
|
-
})
|
|
49
|
-
.map(function (command) { return client.send(command); });
|
|
50
|
-
return [4 /*yield*/, Promise.allSettled(requests)];
|
|
51
|
-
case 1:
|
|
52
|
-
_a.sent();
|
|
53
|
-
return [2 /*return*/, Promise.resolve([])];
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}); };
|
|
57
|
-
var getEventBuffer = function (_a) {
|
|
58
|
-
var e_1, _b;
|
|
59
|
-
var region = _a.region, flushSize = _a.flushSize, flushInterval = _a.flushInterval, bufferSize = _a.bufferSize, credentials = _a.credentials, identityId = _a.identityId, userAgentValue = _a.userAgentValue;
|
|
60
|
-
var sessionToken = credentials.sessionToken;
|
|
61
|
-
var sessionIdentityKey = [region, sessionToken, identityId]
|
|
62
|
-
.filter(function (x) { return !!x; })
|
|
63
|
-
.join('-');
|
|
33
|
+
const submitEvents = async (events, client) => {
|
|
34
|
+
const groupedByIds = Object.entries((0, utils_1.groupBy)(event => [event.trackingId, event.sessionId, event.userId]
|
|
35
|
+
.filter(id => !!id)
|
|
36
|
+
.join(DELIMITER), events));
|
|
37
|
+
const requests = groupedByIds
|
|
38
|
+
.map(([ids, events]) => createPutEventsCommand(ids, events))
|
|
39
|
+
.map(command => client.send(command));
|
|
40
|
+
await Promise.allSettled(requests);
|
|
41
|
+
return Promise.resolve([]);
|
|
42
|
+
};
|
|
43
|
+
const getEventBuffer = ({ region, flushSize, flushInterval, bufferSize, credentials, identityId, userAgentValue, }) => {
|
|
44
|
+
const sessionIdentityKey = [region, identityId].filter(x => !!x).join('-');
|
|
64
45
|
if (!eventBufferMap[sessionIdentityKey]) {
|
|
65
|
-
|
|
46
|
+
const getClient = () => {
|
|
66
47
|
if (!cachedClients[sessionIdentityKey]) {
|
|
67
48
|
cachedClients[sessionIdentityKey] = new client_personalize_events_1.PersonalizeEventsClient({
|
|
68
|
-
region
|
|
69
|
-
credentials
|
|
49
|
+
region,
|
|
50
|
+
credentials,
|
|
70
51
|
customUserAgent: userAgentValue,
|
|
71
52
|
});
|
|
72
53
|
}
|
|
73
|
-
return
|
|
54
|
+
return events => submitEvents(events, cachedClients[sessionIdentityKey]);
|
|
74
55
|
};
|
|
75
56
|
eventBufferMap[sessionIdentityKey] =
|
|
76
57
|
new utils_1.EventBuffer({
|
|
77
|
-
bufferSize
|
|
78
|
-
flushSize
|
|
79
|
-
flushInterval
|
|
58
|
+
bufferSize,
|
|
59
|
+
flushSize,
|
|
60
|
+
flushInterval,
|
|
80
61
|
}, getClient);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
var releaseSessionKey = releaseSessionKeys_1_1.value;
|
|
62
|
+
const releaseSessionKeys = Object.keys(eventBufferMap).filter(key => key !== sessionIdentityKey);
|
|
63
|
+
for (const releaseSessionKey of releaseSessionKeys) {
|
|
64
|
+
eventBufferMap[releaseSessionKey].flushAll().finally(() => {
|
|
85
65
|
eventBufferMap[releaseSessionKey].release();
|
|
86
66
|
delete eventBufferMap[releaseSessionKey];
|
|
87
67
|
delete cachedClients[releaseSessionKey];
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
91
|
-
finally {
|
|
92
|
-
try {
|
|
93
|
-
if (releaseSessionKeys_1_1 && !releaseSessionKeys_1_1.done && (_b = releaseSessionKeys_1.return)) _b.call(releaseSessionKeys_1);
|
|
94
|
-
}
|
|
95
|
-
finally { if (e_1) throw e_1.error; }
|
|
68
|
+
});
|
|
96
69
|
}
|
|
97
70
|
}
|
|
98
71
|
return eventBufferMap[sessionIdentityKey];
|
|
@@ -3,23 +3,24 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.resolveConfig = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
const core_1 = require("@aws-amplify/core");
|
|
7
|
+
const errors_1 = require("../../../errors");
|
|
8
|
+
const _1 = require("./");
|
|
9
|
+
const resolveConfig = () => {
|
|
10
|
+
const config = core_1.Amplify.getConfig().Analytics?.Personalize;
|
|
11
|
+
const { region, trackingId, flushSize = _1.DEFAULT_PERSONALIZE_CONFIG.flushSize, flushInterval = _1.DEFAULT_PERSONALIZE_CONFIG.flushInterval, } = {
|
|
12
|
+
..._1.DEFAULT_PERSONALIZE_CONFIG,
|
|
13
|
+
...config,
|
|
14
|
+
};
|
|
14
15
|
(0, errors_1.assertValidationError)(!!region, errors_1.AnalyticsValidationErrorCode.NoRegion);
|
|
15
16
|
(0, errors_1.assertValidationError)(!!trackingId, errors_1.AnalyticsValidationErrorCode.NoTrackingId);
|
|
16
|
-
(0, errors_1.assertValidationError)(flushSize <= _1.PERSONALIZE_FLUSH_SIZE_MAX, errors_1.AnalyticsValidationErrorCode.InvalidFlushSize,
|
|
17
|
+
(0, errors_1.assertValidationError)(flushSize <= _1.PERSONALIZE_FLUSH_SIZE_MAX, errors_1.AnalyticsValidationErrorCode.InvalidFlushSize, `FlushSize for Personalize should be less or equal than ${_1.PERSONALIZE_FLUSH_SIZE_MAX}`);
|
|
17
18
|
return {
|
|
18
|
-
region
|
|
19
|
-
trackingId
|
|
19
|
+
region,
|
|
20
|
+
trackingId,
|
|
20
21
|
bufferSize: flushSize + 1,
|
|
21
|
-
flushSize
|
|
22
|
-
flushInterval
|
|
22
|
+
flushSize,
|
|
23
|
+
flushInterval,
|
|
23
24
|
};
|
|
24
25
|
};
|
|
25
26
|
exports.resolveConfig = resolveConfig;
|
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.configureAutoTrack = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const utils_1 = require("../../../utils");
|
|
7
|
+
const record_1 = require("./record");
|
|
8
8
|
// Configured Tracker instances for Pinpoint
|
|
9
|
-
|
|
9
|
+
const configuredTrackers = {};
|
|
10
10
|
// Callback that will emit an appropriate event to Pinpoint when required by the Tracker
|
|
11
|
-
|
|
11
|
+
const emitTrackingEvent = (eventName, attributes) => {
|
|
12
12
|
(0, record_1.record)({
|
|
13
13
|
name: eventName,
|
|
14
|
-
attributes
|
|
14
|
+
attributes,
|
|
15
15
|
});
|
|
16
16
|
};
|
|
17
17
|
/**
|
|
@@ -27,7 +27,7 @@ var emitTrackingEvent = function (eventName, attributes) {
|
|
|
27
27
|
* @throws validation: {@link AnalyticsValidationErrorCode} - Thrown when the provided parameters or library
|
|
28
28
|
* configuration is incorrect.
|
|
29
29
|
*/
|
|
30
|
-
|
|
30
|
+
const configureAutoTrack = (input) => {
|
|
31
31
|
(0, utils_1.validateTrackerConfiguration)(input);
|
|
32
32
|
// Initialize or update this provider's trackers
|
|
33
33
|
(0, utils_1.updateProviderTrackers)(input, emitTrackingEvent, configuredTrackers);
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.flushEvents = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const pinpoint_1 = require("@aws-amplify/core/internals/providers/pinpoint");
|
|
8
|
+
const utils_2 = require("@aws-amplify/core/internals/utils");
|
|
9
|
+
const core_1 = require("@aws-amplify/core");
|
|
10
|
+
const utils_3 = require("../../../utils");
|
|
11
|
+
const logger = new core_1.ConsoleLogger('Analytics');
|
|
12
12
|
/**
|
|
13
13
|
* Flushes all buffered Pinpoint events to the service.
|
|
14
14
|
*
|
|
@@ -16,13 +16,10 @@ var logger = new core_1.ConsoleLogger('Analytics');
|
|
|
16
16
|
* This API will make a best-effort attempt to flush events from the buffer. Events recorded immediately after invoking
|
|
17
17
|
* this API may not be included in the flush.
|
|
18
18
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
const flushEvents = () => {
|
|
20
|
+
const { appId, region } = (0, utils_1.resolveConfig)();
|
|
21
21
|
(0, utils_1.resolveCredentials)()
|
|
22
|
-
.then(
|
|
23
|
-
|
|
24
|
-
return (0, pinpoint_1.flushEvents)(appId, region, credentials, identityId, (0, utils_3.getAnalyticsUserAgentString)(utils_2.AnalyticsAction.Record));
|
|
25
|
-
})
|
|
26
|
-
.catch(function (e) { return logger.warn('Failed to flush events', e); });
|
|
22
|
+
.then(({ credentials, identityId }) => (0, pinpoint_1.flushEvents)(appId, region, credentials, identityId, (0, utils_3.getAnalyticsUserAgentString)(utils_2.AnalyticsAction.Record)))
|
|
23
|
+
.catch(e => logger.warn('Failed to flush events', e));
|
|
27
24
|
};
|
|
28
25
|
exports.flushEvents = flushEvents;
|
|
@@ -3,11 +3,10 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.identifyUser = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var utils_3 = require("../utils");
|
|
6
|
+
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
7
|
+
const pinpoint_1 = require("@aws-amplify/core/internals/providers/pinpoint");
|
|
8
|
+
const utils_2 = require("../../../utils");
|
|
9
|
+
const utils_3 = require("../utils");
|
|
11
10
|
/**
|
|
12
11
|
* Sends information about a user to Pinpoint. Sending user information allows you to associate a user to their user
|
|
13
12
|
* profile and activities or actions in your application. Activity can be tracked across devices & platforms by using
|
|
@@ -53,31 +52,20 @@ var utils_3 = require("../utils");
|
|
|
53
52
|
* }
|
|
54
53
|
* });
|
|
55
54
|
*/
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
credentials: credentials,
|
|
71
|
-
identityId: identityId,
|
|
72
|
-
region: region,
|
|
73
|
-
userAttributes: userAttributes,
|
|
74
|
-
userId: userId,
|
|
75
|
-
userProfile: userProfile,
|
|
76
|
-
userAgentValue: (0, utils_2.getAnalyticsUserAgentString)(utils_1.AnalyticsAction.IdentifyUser),
|
|
77
|
-
});
|
|
78
|
-
return [2 /*return*/];
|
|
79
|
-
}
|
|
80
|
-
});
|
|
55
|
+
const identifyUser = async ({ userId, userProfile, options, }) => {
|
|
56
|
+
const { credentials, identityId } = await (0, utils_3.resolveCredentials)();
|
|
57
|
+
const { appId, region } = (0, utils_3.resolveConfig)();
|
|
58
|
+
const { userAttributes } = options ?? {};
|
|
59
|
+
(0, pinpoint_1.updateEndpoint)({
|
|
60
|
+
appId,
|
|
61
|
+
category: 'Analytics',
|
|
62
|
+
credentials,
|
|
63
|
+
identityId,
|
|
64
|
+
region,
|
|
65
|
+
userAttributes,
|
|
66
|
+
userId,
|
|
67
|
+
userProfile,
|
|
68
|
+
userAgentValue: (0, utils_2.getAnalyticsUserAgentString)(utils_1.AnalyticsAction.IdentifyUser),
|
|
81
69
|
});
|
|
82
70
|
};
|
|
83
71
|
exports.identifyUser = identifyUser;
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.record = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
const core_1 = require("@aws-amplify/core");
|
|
7
|
+
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
8
|
+
const pinpoint_1 = require("@aws-amplify/core/internals/providers/pinpoint");
|
|
9
|
+
const errors_1 = require("../../../errors");
|
|
10
|
+
const utils_2 = require("../../../utils");
|
|
11
|
+
const utils_3 = require("../utils");
|
|
12
|
+
const logger = new core_1.ConsoleLogger('Analytics');
|
|
13
13
|
/**
|
|
14
14
|
* Records an Analytic event to Pinpoint. Events will be buffered and periodically sent to Pinpoint.
|
|
15
15
|
*
|
|
@@ -38,28 +38,27 @@ var logger = new core_1.ConsoleLogger('Analytics');
|
|
|
38
38
|
* })
|
|
39
39
|
* ```
|
|
40
40
|
*/
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
const record = (input) => {
|
|
42
|
+
const { appId, region } = (0, utils_3.resolveConfig)();
|
|
43
43
|
if (!(0, utils_2.isAnalyticsEnabled)()) {
|
|
44
44
|
logger.debug('Analytics is disabled, event will not be recorded.');
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
47
|
(0, errors_1.assertValidationError)(!!input.name, errors_1.AnalyticsValidationErrorCode.NoEventName);
|
|
48
48
|
(0, utils_3.resolveCredentials)()
|
|
49
|
-
.then(
|
|
50
|
-
var credentials = _a.credentials, identityId = _a.identityId;
|
|
49
|
+
.then(({ credentials, identityId }) => {
|
|
51
50
|
core_1.Hub.dispatch('analytics', { event: 'record', data: input, message: 'Recording Analytics event' }, 'Analytics', utils_1.AMPLIFY_SYMBOL);
|
|
52
51
|
(0, pinpoint_1.record)({
|
|
53
|
-
appId
|
|
52
|
+
appId,
|
|
54
53
|
category: 'Analytics',
|
|
55
|
-
credentials
|
|
54
|
+
credentials,
|
|
56
55
|
event: input,
|
|
57
|
-
identityId
|
|
58
|
-
region
|
|
56
|
+
identityId,
|
|
57
|
+
region,
|
|
59
58
|
userAgentValue: (0, utils_2.getAnalyticsUserAgentString)(utils_1.AnalyticsAction.Record),
|
|
60
59
|
});
|
|
61
60
|
})
|
|
62
|
-
.catch(
|
|
61
|
+
.catch(e => {
|
|
63
62
|
// An error occured while fetching credentials or persisting the event to the buffer
|
|
64
63
|
logger.warn('Failed to record event.', e);
|
|
65
64
|
});
|
|
@@ -3,16 +3,15 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.resolveConfig = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const core_1 = require("@aws-amplify/core");
|
|
7
|
+
const errors_1 = require("../../../errors");
|
|
8
8
|
/**
|
|
9
9
|
* @internal
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var _c = (_b = (_a = core_1.Amplify.getConfig().Analytics) === null || _a === void 0 ? void 0 : _a.Pinpoint) !== null && _b !== void 0 ? _b : {}, appId = _c.appId, region = _c.region;
|
|
11
|
+
const resolveConfig = () => {
|
|
12
|
+
const { appId, region } = core_1.Amplify.getConfig().Analytics?.Pinpoint ?? {};
|
|
14
13
|
(0, errors_1.assertValidationError)(!!appId, errors_1.AnalyticsValidationErrorCode.NoAppId);
|
|
15
14
|
(0, errors_1.assertValidationError)(!!region, errors_1.AnalyticsValidationErrorCode.NoRegion);
|
|
16
|
-
return { appId
|
|
15
|
+
return { appId, region };
|
|
17
16
|
};
|
|
18
17
|
exports.resolveConfig = resolveConfig;
|
|
@@ -3,22 +3,14 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.resolveCredentials = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var errors_1 = require("../../../errors");
|
|
6
|
+
const core_1 = require("@aws-amplify/core");
|
|
7
|
+
const errors_1 = require("../../../errors");
|
|
9
8
|
/**
|
|
10
9
|
* @internal
|
|
11
10
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
case 1:
|
|
18
|
-
_a = _b.sent(), credentials = _a.credentials, identityId = _a.identityId;
|
|
19
|
-
(0, errors_1.assertValidationError)(!!credentials, errors_1.AnalyticsValidationErrorCode.NoCredentials);
|
|
20
|
-
return [2 /*return*/, { credentials: credentials, identityId: identityId }];
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
}); };
|
|
11
|
+
const resolveCredentials = async () => {
|
|
12
|
+
const { credentials, identityId } = await (0, core_1.fetchAuthSession)();
|
|
13
|
+
(0, errors_1.assertValidationError)(!!credentials, errors_1.AnalyticsValidationErrorCode.NoCredentials);
|
|
14
|
+
return { credentials, identityId };
|
|
15
|
+
};
|
|
24
16
|
exports.resolveCredentials = resolveCredentials;
|
package/lib/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();
|