@amplitude/analytics-browser 2.46.0 → 2.47.0-video-analytics-5.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.
Files changed (55) hide show
  1. package/README.md +1 -1
  2. package/lib/cjs/config.d.ts +9 -2
  3. package/lib/cjs/config.d.ts.map +1 -1
  4. package/lib/cjs/config.js +28 -3
  5. package/lib/cjs/config.js.map +1 -1
  6. package/lib/cjs/constants.d.ts +2 -0
  7. package/lib/cjs/constants.d.ts.map +1 -1
  8. package/lib/cjs/constants.js +3 -1
  9. package/lib/cjs/constants.js.map +1 -1
  10. package/lib/cjs/version.d.ts +1 -1
  11. package/lib/cjs/version.d.ts.map +1 -1
  12. package/lib/cjs/version.js +1 -1
  13. package/lib/cjs/version.js.map +1 -1
  14. package/lib/cjs/video-capture/video-capture.d.ts +32 -10
  15. package/lib/cjs/video-capture/video-capture.d.ts.map +1 -1
  16. package/lib/cjs/video-capture/video-capture.js +118 -15
  17. package/lib/cjs/video-capture/video-capture.js.map +1 -1
  18. package/lib/esm/config.d.ts +9 -2
  19. package/lib/esm/config.d.ts.map +1 -1
  20. package/lib/esm/config.js +26 -2
  21. package/lib/esm/config.js.map +1 -1
  22. package/lib/esm/constants.d.ts +2 -0
  23. package/lib/esm/constants.d.ts.map +1 -1
  24. package/lib/esm/constants.js +2 -0
  25. package/lib/esm/constants.js.map +1 -1
  26. package/lib/esm/version.d.ts +1 -1
  27. package/lib/esm/version.d.ts.map +1 -1
  28. package/lib/esm/version.js +1 -1
  29. package/lib/esm/version.js.map +1 -1
  30. package/lib/esm/video-capture/video-capture.d.ts +32 -10
  31. package/lib/esm/video-capture/video-capture.d.ts.map +1 -1
  32. package/lib/esm/video-capture/video-capture.js +120 -17
  33. package/lib/esm/video-capture/video-capture.js.map +1 -1
  34. package/lib/scripts/amplitude-bookmarklet-snippet-min.js +1 -1
  35. package/lib/scripts/amplitude-bookmarklet.html +1 -1
  36. package/lib/scripts/amplitude-gtm-min.js +1 -1
  37. package/lib/scripts/amplitude-gtm-min.js.gz +0 -0
  38. package/lib/scripts/amplitude-gtm-min.js.map +1 -1
  39. package/lib/scripts/amplitude-gtm-snippet-min.js +1 -1
  40. package/lib/scripts/amplitude-min.js +1 -1
  41. package/lib/scripts/amplitude-min.js.gz +0 -0
  42. package/lib/scripts/amplitude-min.js.map +1 -1
  43. package/lib/scripts/amplitude-min.umd.js +1 -1
  44. package/lib/scripts/amplitude-min.umd.js.gz +0 -0
  45. package/lib/scripts/amplitude-snippet-instructions.html +1 -1
  46. package/lib/scripts/amplitude-snippet-min.js +1 -1
  47. package/lib/scripts/config.d.ts +9 -2
  48. package/lib/scripts/config.d.ts.map +1 -1
  49. package/lib/scripts/constants.d.ts +2 -0
  50. package/lib/scripts/constants.d.ts.map +1 -1
  51. package/lib/scripts/version.d.ts +1 -1
  52. package/lib/scripts/version.d.ts.map +1 -1
  53. package/lib/scripts/video-capture/video-capture.d.ts +32 -10
  54. package/lib/scripts/video-capture/video-capture.d.ts.map +1 -1
  55. package/package.json +8 -8
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "2.46.0";
1
+ export declare const VERSION = "2.47.0-video-analytics-5.0";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,WAAW,CAAC"}
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,+BAA+B,CAAC"}
@@ -1,2 +1,2 @@
1
- export var VERSION = '2.46.0';
1
+ export var VERSION = '2.47.0-video-analytics-5.0';
2
2
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["export const VERSION = '2.46.0';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,OAAO,GAAG,4BAA4B,CAAC","sourcesContent":["export const VERSION = '2.47.0-video-analytics-5.0';\n"]}
@@ -1,20 +1,24 @@
1
- import { BrowserClient, EmbeddedVideoPlayer, VideoVendor } from '@amplitude/analytics-core';
1
+ import { VideoState, BrowserClient, EmbeddedVideoPlayer, VideoVendor } from '@amplitude/analytics-core';
2
2
  export declare class VideoCapture {
3
3
  private readonly amplitude;
4
4
  private videoEl;
5
+ private heartbeat;
5
6
  private embeddedVideoPlayer;
6
7
  private vendor?;
7
8
  private extraEventProperties;
9
+ private stopEvent;
8
10
  private listeners;
9
11
  private onRemoveListeners;
12
+ private playId;
13
+ private playStartTime;
10
14
  constructor(amplitude: BrowserClient);
11
15
  /**
12
- * Specify a video element to capture events from
16
+ * Specify a video or audio element to capture events from
13
17
  *
14
- * @param videoEl - The HTML video element to capture events from.
18
+ * @param videoEl - The HTML video or audio element to capture events from.
15
19
  * @returns The VideoCapture instance.
16
20
  */
17
- withVideoElement(videoEl: HTMLVideoElement): VideoCapture;
21
+ withVideoElement(videoEl: HTMLMediaElement): VideoCapture;
18
22
  /**
19
23
  * Specify an embedded video player.js instance to capture events from
20
24
  * @param player - The embedded video player.js instance to capture events from.
@@ -36,22 +40,40 @@ export declare class VideoCapture {
36
40
  */
37
41
  withExtraEventProperties(properties: Record<string, string | number | boolean>): VideoCapture;
38
42
  /**
39
- * Track a "Video Content Started" event every time the video starts playing
43
+ * Track a "[Amplitude] Content Started" event every time the video starts playing
40
44
  * @returns The VideoCapture instance.
41
45
  */
42
46
  captureVideoStarted(): VideoCapture;
43
47
  /**
44
- * Track a "Video Content Stopped" event every time the video stops playing
48
+ * Track a "[Amplitude] Content Stopped" event every time the video stops playing
45
49
  * @returns The VideoCapture instance.
46
50
  */
47
51
  captureVideoStopped(): VideoCapture;
52
+ /**
53
+ * End the current play session by ingesting its queued delayed stop event immediately.
54
+ *
55
+ * The heartbeat is shared by every capture on the same Amplitude client, so the event is
56
+ * flushed rather than the heartbeat stopped, which would discard other captures' events.
57
+ * Flushing also drops the event from the heartbeat queue once ingested, so the interval
58
+ * winds down on its own. No-op when no play session is in progress.
59
+ */
60
+ private flushStopEvent;
48
61
  /**
49
62
  * Start capturing analytics events for the video element
50
63
  * @returns The VideoCapture instance.
51
64
  * @throws An error if the video element is not specified.
52
65
  */
53
66
  start(): VideoCapture;
67
+ /**
68
+ * Stop capturing analytics events for the video element.
69
+ *
70
+ * Observers are detached first so no playback state change can race with the final
71
+ * event, then any in-progress play session is closed out.
72
+ */
54
73
  stop(): void;
74
+ parseStartEventProperties(nextState: VideoState): Record<string, string | number | boolean>;
75
+ private getDeliveryMode;
76
+ parseStopEventProperties(nextState: VideoState): Record<string, string | number | boolean>;
55
77
  }
56
78
  export type VideoCaptureOptions = {
57
79
  vendor?: VideoVendor;
@@ -60,16 +82,16 @@ export type VideoCaptureOptions = {
60
82
  type UntrackVideoResult = () => void;
61
83
  export type TrackVideoResult = UntrackVideoResult | Error;
62
84
  /**
63
- * Track video analytics events for an HTML video element or embedded video player.js instance.
85
+ * Track video analytics events for an HTML video or audio element or embedded video player.js instance.
64
86
  *
65
- * Captures Video Started and Video Stopped events.
87
+ * Captures [Amplitude] Content Started and [Amplitude] Content Stopped events.
66
88
  *
67
89
  * @experimental This function is experimental and may not be stable.
68
90
  * @param amplitude - The Amplitude client instance.
69
- * @param videoEl - The HTML video element or embedded video player.js instance to capture events from.
91
+ * @param videoEl - The HTML video or audio element or embedded video player.js instance to capture events from.
70
92
  * @param options - The options for the video capture.
71
93
  * @returns A function to stop the video capture.
72
94
  */
73
- export declare function trackVideo(amplitude: BrowserClient, videoEl: HTMLVideoElement | EmbeddedVideoPlayer, options?: VideoCaptureOptions): TrackVideoResult;
95
+ export declare function trackVideo(amplitude: BrowserClient, videoEl: HTMLMediaElement | EmbeddedVideoPlayer, options?: VideoCaptureOptions): TrackVideoResult;
74
96
  export {};
75
97
  //# sourceMappingURL=video-capture.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"video-capture.d.ts","sourceRoot":"","sources":["../../../src/video-capture/video-capture.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,aAAa,EACb,mBAAmB,EACnB,WAAW,EAEZ,MAAM,2BAA2B,CAAC;AAEnC,qBAAa,YAAY;IASX,OAAO,CAAC,QAAQ,CAAC,SAAS;IARtC,OAAO,CAAC,OAAO,CAAiC;IAChD,OAAO,CAAC,mBAAmB,CAAoC;IAC/D,OAAO,CAAC,MAAM,CAAC,CAAc;IAC7B,OAAO,CAAC,oBAAoB,CAAiD;IAE7E,OAAO,CAAC,SAAS,CAAsE;IACvF,OAAO,CAAC,iBAAiB,CAAsB;gBAElB,SAAS,EAAE,aAAa;IAErD;;;;;OAKG;IACH,gBAAgB,CAAC,OAAO,EAAE,gBAAgB,GAAG,YAAY;IAKzD;;;;OAIG;IACH,kBAAkB,CAAC,MAAM,EAAE,mBAAmB,GAAG,YAAY;IAK7D;;;;;OAKG;IACH,UAAU,CAAC,MAAM,EAAE,WAAW,GAAG,YAAY;IAK7C;;;;;OAKG;IACH,wBAAwB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,GAAG,YAAY;IAK7F;;;OAGG;IACH,mBAAmB,IAAI,YAAY;IAanC;;;OAGG;IACH,mBAAmB,IAAI,YAAY;IAkBnC;;;;OAIG;IACH,KAAK,IAAI,YAAY;IA2BrB,IAAI;CAIL;AAED,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;CAClE,CAAC;AAEF,KAAK,kBAAkB,GAAG,MAAM,IAAI,CAAC;AAErC,MAAM,M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,CAAC,cAAc;IAmBtB;;;;OAIG;IACH,KAAK,IAAI,YAAY;IA2BrB;;;;;OAKG;IACH,IAAI;IAMJ,yBAAyB,CAAC,SAAS,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;IAU3F,OAAO,CAAC,eAAe;IAIvB,wBAAwB,CAAC,SAAS,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;CAW3F;AASD,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;CAClE,CAAC;AAEF,KAAK,kBAAkB,GAAG,MAAM,IAAI,CAAC;AAErC,MAAM,MAAM,gBAAgB,GAAG,kBAAkB,GAAG,KAAK,CAAC;AAE1D;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CACxB,SAAS,EAAE,aAAa,EACxB,OAAO,EAAE,gBAAgB,GAAG,mBAAmB,EAC/C,OAAO,GAAE,mBAAwB,GAChC,gBAAgB,CA0BlB"}
@@ -1,18 +1,56 @@
1
- import { __assign } from "tslib";
2
- import { VideoObserver, UUID, } from '@amplitude/analytics-core';
1
+ import { __assign, __read, __values } from "tslib";
2
+ import { VideoObserver, UUID, getHeartbeatInstance, } from '@amplitude/analytics-core';
3
+ import { DEFAULT_CONTENT_STARTED_EVENT, DEFAULT_CONTENT_STOPPED_EVENT } from '../constants';
4
+ /** Playback states where a view session is still in progress (e.g. buffering). */
5
+ var ACTIVE_PLAYBACK_STATES = new Set(['playing', 'waiting']);
6
+ /**
7
+ * Observer fields that never reach event properties from `lastEvent`: `position` is taken from
8
+ * observer state instead, and `percent_completed`/`stop_reason` describe the player event rather
9
+ * than the play session, which tracks its own values.
10
+ */
11
+ var OMITTED_VIDEO_EVENT_PROPERTIES = new Set(['position', 'percent_completed', 'stop_reason']);
12
+ /**
13
+ * Copy remaining player-event fields (vendor metadata such as `mux_playback_id`, ids, titles)
14
+ * onto the Amplitude event, dropping empty values so absent metadata is omitted.
15
+ */
16
+ function parseVideoEventProperties(lastEvent) {
17
+ var e_1, _a;
18
+ var properties = {};
19
+ try {
20
+ for (var _b = __values(Object.entries(lastEvent !== null && lastEvent !== void 0 ? lastEvent : {})), _c = _b.next(); !_c.done; _c = _b.next()) {
21
+ var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
22
+ if (OMITTED_VIDEO_EVENT_PROPERTIES.has(key) || value === null || value === undefined) {
23
+ continue;
24
+ }
25
+ properties[key] = value;
26
+ }
27
+ }
28
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
29
+ finally {
30
+ try {
31
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
32
+ }
33
+ finally { if (e_1) throw e_1.error; }
34
+ }
35
+ return properties;
36
+ }
3
37
  var VideoCapture = /** @class */ (function () {
4
38
  function VideoCapture(amplitude) {
5
39
  this.amplitude = amplitude;
6
40
  this.videoEl = null;
7
41
  this.embeddedVideoPlayer = null;
8
42
  this.extraEventProperties = {};
43
+ this.stopEvent = null;
9
44
  this.listeners = [];
10
45
  this.onRemoveListeners = [];
46
+ this.playId = null;
47
+ this.playStartTime = null;
48
+ this.heartbeat = getHeartbeatInstance(this.amplitude);
11
49
  }
12
50
  /**
13
- * Specify a video element to capture events from
51
+ * Specify a video or audio element to capture events from
14
52
  *
15
- * @param videoEl - The HTML video element to capture events from.
53
+ * @param videoEl - The HTML video or audio element to capture events from.
16
54
  * @returns The VideoCapture instance.
17
55
  */
18
56
  VideoCapture.prototype.withVideoElement = function (videoEl) {
@@ -49,33 +87,71 @@ var VideoCapture = /** @class */ (function () {
49
87
  return this;
50
88
  };
51
89
  /**
52
- * Track a "Video Content Started" event every time the video starts playing
90
+ * Track a "[Amplitude] Content Started" event every time the video starts playing
53
91
  * @returns The VideoCapture instance.
54
92
  */
55
93
  VideoCapture.prototype.captureVideoStarted = function () {
56
94
  var _this = this;
57
95
  this.listeners.push(function (previousState, nextState) {
58
- if (previousState.playbackState !== 'playing' && nextState.playbackState === 'playing') {
59
- // TODO: placeholder for Heartbeat Start Event
60
- _this.amplitude.track('Video Content Started', __assign(__assign({}, nextState.lastEvent), _this.extraEventProperties));
96
+ var _a, _b;
97
+ if (!ACTIVE_PLAYBACK_STATES.has(previousState.playbackState) && nextState.playbackState === 'playing') {
98
+ _this.playId = UUID();
99
+ /* istanbul ignore next */
100
+ _this.playStartTime = (_b = (_a = nextState.lastEvent) === null || _a === void 0 ? void 0 : _a.start_time) !== null && _b !== void 0 ? _b : 0;
101
+ var now = new Date().getTime();
102
+ var startEvent = {
103
+ insert_id: UUID(),
104
+ event_type: DEFAULT_CONTENT_STARTED_EVENT,
105
+ time: now,
106
+ event_properties: __assign(__assign(__assign({}, _this.parseStartEventProperties(nextState)), _this.extraEventProperties), { play_id: _this.playId }),
107
+ };
108
+ _this.stopEvent = __assign(__assign({}, startEvent), { insert_id: UUID(), event_type: DEFAULT_CONTENT_STOPPED_EVENT, time: now + 1, event_properties: __assign(__assign(__assign({}, _this.parseStopEventProperties(nextState)), _this.extraEventProperties), { stop_reason: 'timeout', play_id: _this.playId }) });
109
+ _this.heartbeat.trackNoDelay(startEvent).catch(_this.stop.bind(_this));
110
+ _this.heartbeat.track(_this.stopEvent).catch(_this.stop.bind(_this));
61
111
  }
62
112
  });
63
113
  return this;
64
114
  };
65
115
  /**
66
- * Track a "Video Content Stopped" event every time the video stops playing
116
+ * Track a "[Amplitude] Content Stopped" event every time the video stops playing
67
117
  * @returns The VideoCapture instance.
68
118
  */
69
119
  VideoCapture.prototype.captureVideoStopped = function () {
70
120
  var _this = this;
71
121
  this.listeners.push(function (previousState, nextState) {
72
- if (previousState.playbackState === 'playing' && nextState.playbackState !== 'playing') {
73
- // placeholder for Heartbeat Stop Event
74
- _this.amplitude.track('Video Content Stopped', __assign(__assign(__assign({}, nextState.lastEvent), { watch_duration: nextState.watchTime }), _this.extraEventProperties));
122
+ // update the delayed event properties to have
123
+ // the most up-to-date values
124
+ if (_this.stopEvent) {
125
+ _this.stopEvent.event_properties = __assign(__assign(__assign({}, _this.stopEvent.event_properties), _this.parseStopEventProperties(nextState)), _this.extraEventProperties);
126
+ _this.stopEvent.time = new Date().getTime();
127
+ void _this.heartbeat.update(_this.stopEvent);
128
+ }
129
+ if (ACTIVE_PLAYBACK_STATES.has(previousState.playbackState) &&
130
+ !ACTIVE_PLAYBACK_STATES.has(nextState.playbackState)) {
131
+ _this.flushStopEvent(nextState.playbackState);
75
132
  }
76
133
  });
77
134
  return this;
78
135
  };
136
+ /**
137
+ * End the current play session by ingesting its queued delayed stop event immediately.
138
+ *
139
+ * The heartbeat is shared by every capture on the same Amplitude client, so the event is
140
+ * flushed rather than the heartbeat stopped, which would discard other captures' events.
141
+ * Flushing also drops the event from the heartbeat queue once ingested, so the interval
142
+ * winds down on its own. No-op when no play session is in progress.
143
+ */
144
+ VideoCapture.prototype.flushStopEvent = function (stopReason) {
145
+ var stopEvent = this.stopEvent;
146
+ if (!stopEvent) {
147
+ return;
148
+ }
149
+ // the next play queues a fresh delayed stop event
150
+ this.stopEvent = null;
151
+ this.playStartTime = null;
152
+ stopEvent.event_properties = __assign(__assign({}, stopEvent.event_properties), { stop_reason: stopReason });
153
+ this.heartbeat.trackNoDelay(stopEvent).catch(this.stop.bind(this));
154
+ };
79
155
  // Placeholder: may need a generic state change listener to capture unusual events or to have
80
156
  // more control over the event tracking.
81
157
  // withStateChangeListener(listener: (previousState: VideoState, nextState: VideoState) => void): VideoCapture {
@@ -107,21 +183,48 @@ var VideoCapture = /** @class */ (function () {
107
183
  });
108
184
  return this;
109
185
  };
186
+ /**
187
+ * Stop capturing analytics events for the video element.
188
+ *
189
+ * Observers are detached first so no playback state change can race with the final
190
+ * event, then any in-progress play session is closed out.
191
+ */
110
192
  VideoCapture.prototype.stop = function () {
111
193
  this.onRemoveListeners.forEach(function (listener) { return listener(); });
112
194
  this.onRemoveListeners = [];
195
+ this.flushStopEvent('untracked');
196
+ };
197
+ VideoCapture.prototype.parseStartEventProperties = function (nextState) {
198
+ var _a, _b, _c, _d, _e;
199
+ return __assign(__assign({}, parseVideoEventProperties(nextState.lastEvent)), { duration: (_b = (_a = nextState.lastEvent) === null || _a === void 0 ? void 0 : _a.duration) !== null && _b !== void 0 ? _b : 0, start_time: (_d = (_c = nextState.lastEvent) === null || _c === void 0 ? void 0 : _c.start_time) !== null && _d !== void 0 ? _d : 0, position: (_e = nextState.position) !== null && _e !== void 0 ? _e : 0, delivery_mode: this.getDeliveryMode() });
200
+ };
201
+ VideoCapture.prototype.getDeliveryMode = function () {
202
+ return this.videoEl instanceof HTMLAudioElement ? 'audio' : 'video';
203
+ };
204
+ VideoCapture.prototype.parseStopEventProperties = function (nextState) {
205
+ var _a, _b, _c, _d, _e, _f, _g;
206
+ return __assign(__assign(__assign({}, this.parseStartEventProperties(nextState)), {
207
+ // lastEvent.start_time is the playhead at the time of the event, which for a stop event is
208
+ // where playback ended, so the position captured when the play session began is preferred.
209
+ start_time: (_c = (_a = this.playStartTime) !== null && _a !== void 0 ? _a : (_b = nextState.lastEvent) === null || _b === void 0 ? void 0 : _b.start_time) !== null && _c !== void 0 ? _c : 0, stream_duration: (_d = nextState.watchTime) !== null && _d !== void 0 ? _d : 0, percent_completed: calculatePercentCompleted((_e = nextState.position) !== null && _e !== void 0 ? _e : 0, (_g = (_f = nextState.lastEvent) === null || _f === void 0 ? void 0 : _f.duration) !== null && _g !== void 0 ? _g : 0) }), (nextState.errorMessage ? { error_message: nextState.errorMessage } : {}));
113
210
  };
114
211
  return VideoCapture;
115
212
  }());
116
213
  export { VideoCapture };
214
+ function calculatePercentCompleted(currentTime, duration) {
215
+ if (!Number.isFinite(currentTime) || !Number.isFinite(duration) || duration <= 0) {
216
+ return 0;
217
+ }
218
+ return Math.min(100, Math.max(0, (currentTime / duration) * 100));
219
+ }
117
220
  /**
118
- * Track video analytics events for an HTML video element or embedded video player.js instance.
221
+ * Track video analytics events for an HTML video or audio element or embedded video player.js instance.
119
222
  *
120
- * Captures Video Started and Video Stopped events.
223
+ * Captures [Amplitude] Content Started and [Amplitude] Content Stopped events.
121
224
  *
122
225
  * @experimental This function is experimental and may not be stable.
123
226
  * @param amplitude - The Amplitude client instance.
124
- * @param videoEl - The HTML video element or embedded video player.js instance to capture events from.
227
+ * @param videoEl - The HTML video or audio element or embedded video player.js instance to capture events from.
125
228
  * @param options - The options for the video capture.
126
229
  * @returns A function to stop the video capture.
127
230
  */
@@ -129,7 +232,7 @@ export function trackVideo(amplitude, videoEl, options) {
129
232
  var _a;
130
233
  if (options === void 0) { options = {}; }
131
234
  var videoCapture = new VideoCapture(amplitude);
132
- if (videoEl instanceof HTMLVideoElement) {
235
+ if (videoEl instanceof HTMLMediaElement) {
133
236
  videoCapture.withVideoElement(videoEl);
134
237
  }
135
238
  else {
@@ -141,7 +244,7 @@ export function trackVideo(amplitude, videoEl, options) {
141
244
  var extraEventProperties = (_a = options.extraEventProperties) !== null && _a !== void 0 ? _a : {};
142
245
  try {
143
246
  videoCapture
144
- .withExtraEventProperties(__assign({ view_session_id: UUID() }, extraEventProperties))
247
+ .withExtraEventProperties(__assign({ stream_session_id: UUID() }, extraEventProperties))
145
248
  .captureVideoStarted()
146
249
  .captureVideoStopped()
147
250
  .start();
@@ -1 +1 @@
1
- {"version":3,"file":"video-capture.js","sourceRoot":"","sources":["../../../src/video-capture/video-capture.ts"],"names":[],"mappings":";AAAA,OAAO,EAEL,aAAa,EAIb,IAAI,GACL,MAAM,2BAA2B,CAAC;AAEnC;IASE,sBAA6B,SAAwB;QAAxB,cAAS,GAAT,SAAS,CAAe;QAR7C,YAAO,GAA4B,IAAI,CAAC;QACxC,wBAAmB,GAA+B,IAAI,CAAC;QAEvD,yBAAoB,GAA8C,EAAE,CAAC;QAErE,cAAS,GAAmE,EAAE,CAAC;QAC/E,sBAAiB,GA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D;;;;;;;;;;GAUG;AACH,MAAM,UAAU,UAAU,CACxB,SAAwB,EACxB,OAA+C,EAC/C,OAAiC;;IAAjC,wBAAA,EAAA,YAAiC;IAEjC,IAAM,YAAY,GAAG,IAAI,YAAY,CAAC,SAAS,CAAC,CAAC;IACjD,IAAI,OAAO,YAAY,gBAAgB,EAAE;QACvC,YAAY,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;KACxC;SAAM;QACL,YAAY,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;KAC1C;IACD,IAAI,OAAO,CAAC,MAAM,EAAE;QAClB,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;KACzC;IACD,IAAM,oBAAoB,GAAG,MAAA,OAAO,CAAC,oBAAoB,mCAAI,EAAE,CAAC;IAEhE,IAAI;QACF,YAAY;aACT,wBAAwB,YACvB,eAAe,EAAE,IAAI,EAAE,IACpB,oBAAoB,EACvB;aACD,mBAAmB,EAAE;aACrB,mBAAmB,EAAE;aACrB,KAAK,EAAE,CAAC;KACZ;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,KAAc,CAAC;KACvB;IAED,OAAO,cAAM,OAAA,YAAY,CAAC,IAAI,EAAE,EAAnB,CAAmB,CAAC;AACnC,CAAC","sourcesContent":["import {\n VideoState,\n VideoObserver,\n BrowserClient,\n EmbeddedVideoPlayer,\n VideoVendor,\n UUID,\n} from '@amplitude/analytics-core';\n\nexport class VideoCapture {\n private videoEl: HTMLVideoElement | null = null;\n private embeddedVideoPlayer: EmbeddedVideoPlayer | null = null;\n private vendor?: VideoVendor;\n private extraEventProperties: Record<string, string | number | boolean> = {};\n\n private listeners: ((previousState: VideoState, nextState: VideoState) => void)[] = [];\n private onRemoveListeners: (() => void)[] = [];\n\n constructor(private readonly amplitude: BrowserClient) {}\n\n /**\n * Specify a video element to capture events from\n *\n * @param videoEl - The HTML video element to capture events from.\n * @returns The VideoCapture instance.\n */\n withVideoElement(videoEl: HTMLVideoElement): VideoCapture {\n this.videoEl = videoEl;\n return this;\n }\n\n /**\n * Specify an embedded video player.js instance to capture events from\n * @param player - The embedded video player.js instance to capture events from.\n * @returns The VideoCapture instance.\n */\n withEmbeddedPlayer(player: EmbeddedVideoPlayer): VideoCapture {\n this.embeddedVideoPlayer = player;\n return this;\n }\n\n /**\n * Specify a vendor to capture extra vendor-specific event properties\n *\n * @param vendor - The vendor of the video player. Currently only \"mux\" is supported.\n * @returns The VideoCapture instance.\n */\n withVendor(vendor: VideoVendor): VideoCapture {\n this.vendor = vendor;\n return this;\n }\n\n /**\n * Specify extra event properties to include in all captured events\n *\n * @param properties - The extra event properties to include in the Amplitude event.\n * @returns The VideoCapture instance.\n */\n withExtraEventProperties(properties: Record<string, string | number | boolean>): VideoCapture {\n this.extraEventProperties = properties;\n return this;\n }\n\n /**\n * Track a \"Video Content Started\" event every time the video starts playing\n * @returns The VideoCapture instance.\n */\n captureVideoStarted(): VideoCapture {\n this.listeners.push((previousState, nextState) => {\n if (previousState.playbackState !== 'playing' && nextState.playbackState === 'playing') {\n // TODO: placeholder for Heartbeat Start Event\n this.amplitude.track('Video Content Started', {\n ...nextState.lastEvent,\n ...this.extraEventProperties,\n });\n }\n });\n return this;\n }\n\n /**\n * Track a \"Video Content Stopped\" event every time the video stops playing\n * @returns The VideoCapture instance.\n */\n captureVideoStopped(): VideoCapture {\n this.listeners.push((previousState, nextState) => {\n if (previousState.playbackState === 'playing' && nextState.playbackState !== 'playing') {\n // placeholder for Heartbeat Stop Event\n this.amplitude.track('Video Content Stopped', {\n ...nextState.lastEvent,\n watch_duration: nextState.watchTime,\n ...this.extraEventProperties,\n });\n }\n });\n return this;\n }\n\n // Placeholder: may need a generic state change listener to capture unusual events or to have\n // more control over the event tracking.\n // withStateChangeListener(listener: (previousState: VideoState, nextState: VideoState) => void): VideoCapture {\n\n /**\n * Start capturing analytics events for the video element\n * @returns The VideoCapture instance.\n * @throws An error if the video element is not specified.\n */\n start(): VideoCapture {\n const videoEl = this.videoEl ?? this.embeddedVideoPlayer;\n if (!videoEl) {\n throw new Error(\n 'Video element not specified. Use withVideoElement() or withEmbeddedPlayer() to specify the video element.',\n );\n }\n if (this.videoEl && this.embeddedVideoPlayer) {\n throw new Error(\n 'Both video element and embedded video player specified. Use only one of withVideoElement() or withEmbeddedPlayer() to specify the video element.',\n );\n }\n const videoObserver = new VideoObserver({\n videoEl,\n onStateChange: (previousState, nextState) => {\n this.listeners.forEach((listener) => listener(previousState, nextState));\n },\n vendor: this.vendor,\n isEmbedded: !!this.embeddedVideoPlayer,\n });\n\n this.onRemoveListeners.push(() => {\n videoObserver.destroy();\n });\n return this;\n }\n\n stop() {\n this.onRemoveListeners.forEach((listener) => listener());\n this.onRemoveListeners = [];\n }\n}\n\nexport type VideoCaptureOptions = {\n vendor?: VideoVendor;\n extraEventProperties?: Record<string, string | number | boolean>;\n};\n\ntype UntrackVideoResult = () => void;\n\nexport type TrackVideoResult = UntrackVideoResult | Error;\n\n/**\n * Track video analytics events for an HTML video element or embedded video player.js instance.\n *\n * Captures Video Started and Video Stopped events.\n *\n * @experimental This function is experimental and may not be stable.\n * @param amplitude - The Amplitude client instance.\n * @param videoEl - The HTML video element or embedded video player.js instance to capture events from.\n * @param options - The options for the video capture.\n * @returns A function to stop the video capture.\n */\nexport function trackVideo(\n amplitude: BrowserClient,\n videoEl: HTMLVideoElement | EmbeddedVideoPlayer,\n options: VideoCaptureOptions = {},\n): TrackVideoResult {\n const videoCapture = new VideoCapture(amplitude);\n if (videoEl instanceof HTMLVideoElement) {\n videoCapture.withVideoElement(videoEl);\n } else {\n videoCapture.withEmbeddedPlayer(videoEl);\n }\n if (options.vendor) {\n videoCapture.withVendor(options.vendor);\n }\n const extraEventProperties = options.extraEventProperties ?? {};\n\n try {\n videoCapture\n .withExtraEventProperties({\n view_session_id: UUID(),\n ...extraEventProperties,\n })\n .captureVideoStarted()\n .captureVideoStopped()\n .start();\n } catch (error) {\n return error as Error;\n }\n\n return () => videoCapture.stop();\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,MAAM,EAAE;QAClB,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;KACzC;IACD,IAAM,oBAAoB,GAAG,MAAA,OAAO,CAAC,oBAAoB,mCAAI,EAAE,CAAC;IAEhE,IAAI;QACF,YAAY;aACT,wBAAwB,YACvB,iBAAiB,EAAE,IAAI,EAAE,IACtB,oBAAoB,EACvB;aACD,mBAAmB,EAAE;aACrB,mBAAmB,EAAE;aACrB,KAAK,EAAE,CAAC;KACZ;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,KAAc,CAAC;KACvB;IAED,OAAO,cAAM,OAAA,YAAY,CAAC,IAAI,EAAE,EAAnB,CAAmB,CAAC;AACnC,CAAC","sourcesContent":["import {\n VideoState,\n VideoObserver,\n BrowserClient,\n EmbeddedVideoPlayer,\n VideoVendor,\n UUID,\n BaseEvent,\n getHeartbeatInstance,\n} from '@amplitude/analytics-core';\nimport { DEFAULT_CONTENT_STARTED_EVENT, DEFAULT_CONTENT_STOPPED_EVENT } from '../constants';\n\n/** Playback states where a view session is still in progress (e.g. buffering). */\nconst ACTIVE_PLAYBACK_STATES = new Set<VideoState['playbackState']>(['playing', 'waiting']);\n\n/**\n * Observer fields that never reach event properties from `lastEvent`: `position` is taken from\n * observer state instead, and `percent_completed`/`stop_reason` describe the player event rather\n * than the play session, which tracks its own values.\n */\nconst OMITTED_VIDEO_EVENT_PROPERTIES = new Set(['position', 'percent_completed', 'stop_reason']);\n\n/**\n * Copy remaining player-event fields (vendor metadata such as `mux_playback_id`, ids, titles)\n * onto the Amplitude event, dropping empty values so absent metadata is omitted.\n */\nfunction parseVideoEventProperties(lastEvent: VideoState['lastEvent']): Record<string, string | number | boolean> {\n const properties: Record<string, string | number | boolean> = {};\n for (const [key, value] of Object.entries(lastEvent ?? {})) {\n if (OMITTED_VIDEO_EVENT_PROPERTIES.has(key) || value === null || value === undefined) {\n continue;\n }\n properties[key] = value as string | number | boolean;\n }\n return properties;\n}\n\nexport class VideoCapture {\n private videoEl: HTMLMediaElement | null = null;\n private heartbeat: ReturnType<typeof getHeartbeatInstance>;\n private embeddedVideoPlayer: EmbeddedVideoPlayer | null = null;\n private vendor?: VideoVendor;\n private extraEventProperties: Record<string, string | number | boolean> = {};\n private stopEvent: BaseEvent | null = null;\n private listeners: ((previousState: VideoState, nextState: VideoState) => void)[] = [];\n private onRemoveListeners: (() => void)[] = [];\n private playId: string | null = null;\n private playStartTime: number | null = null;\n\n constructor(private readonly amplitude: BrowserClient) {\n this.heartbeat = getHeartbeatInstance(this.amplitude);\n }\n\n /**\n * Specify a video or audio element to capture events from\n *\n * @param videoEl - The HTML video or audio element to capture events from.\n * @returns The VideoCapture instance.\n */\n withVideoElement(videoEl: HTMLMediaElement): VideoCapture {\n this.videoEl = videoEl;\n return this;\n }\n\n /**\n * Specify an embedded video player.js instance to capture events from\n * @param player - The embedded video player.js instance to capture events from.\n * @returns The VideoCapture instance.\n */\n withEmbeddedPlayer(player: EmbeddedVideoPlayer): VideoCapture {\n this.embeddedVideoPlayer = player;\n return this;\n }\n\n /**\n * Specify a vendor to capture extra vendor-specific event properties\n *\n * @param vendor - The vendor of the video player. Currently only \"mux\" is supported.\n * @returns The VideoCapture instance.\n */\n withVendor(vendor: VideoVendor): VideoCapture {\n this.vendor = vendor;\n return this;\n }\n\n /**\n * Specify extra event properties to include in all captured events\n *\n * @param properties - The extra event properties to include in the Amplitude event.\n * @returns The VideoCapture instance.\n */\n withExtraEventProperties(properties: Record<string, string | number | boolean>): VideoCapture {\n this.extraEventProperties = properties;\n return this;\n }\n\n /**\n * Track a \"[Amplitude] Content Started\" event every time the video starts playing\n * @returns The VideoCapture instance.\n */\n captureVideoStarted(): VideoCapture {\n this.listeners.push((previousState, nextState) => {\n if (!ACTIVE_PLAYBACK_STATES.has(previousState.playbackState) && nextState.playbackState === 'playing') {\n this.playId = UUID();\n /* istanbul ignore next */\n this.playStartTime = nextState.lastEvent?.start_time ?? 0;\n const now = new Date().getTime();\n const startEvent: BaseEvent = {\n insert_id: UUID(),\n event_type: DEFAULT_CONTENT_STARTED_EVENT,\n time: now,\n event_properties: {\n ...this.parseStartEventProperties(nextState),\n ...this.extraEventProperties,\n play_id: this.playId,\n },\n };\n this.stopEvent = {\n ...startEvent,\n insert_id: UUID(),\n event_type: DEFAULT_CONTENT_STOPPED_EVENT,\n time: now + 1,\n event_properties: {\n ...this.parseStopEventProperties(nextState),\n ...this.extraEventProperties,\n stop_reason: 'timeout',\n play_id: this.playId,\n },\n };\n this.heartbeat.trackNoDelay(startEvent).catch(this.stop.bind(this));\n this.heartbeat.track(this.stopEvent).catch(this.stop.bind(this));\n }\n });\n return this;\n }\n\n /**\n * Track a \"[Amplitude] Content Stopped\" event every time the video stops playing\n * @returns The VideoCapture instance.\n */\n captureVideoStopped(): VideoCapture {\n this.listeners.push((previousState, nextState) => {\n // update the delayed event properties to have\n // the most up-to-date values\n if (this.stopEvent) {\n this.stopEvent.event_properties = {\n ...this.stopEvent.event_properties,\n ...this.parseStopEventProperties(nextState),\n ...this.extraEventProperties,\n };\n this.stopEvent.time = new Date().getTime();\n void this.heartbeat.update(this.stopEvent);\n }\n if (\n ACTIVE_PLAYBACK_STATES.has(previousState.playbackState) &&\n !ACTIVE_PLAYBACK_STATES.has(nextState.playbackState)\n ) {\n this.flushStopEvent(nextState.playbackState);\n }\n });\n return this;\n }\n\n /**\n * End the current play session by ingesting its queued delayed stop event immediately.\n *\n * The heartbeat is shared by every capture on the same Amplitude client, so the event is\n * flushed rather than the heartbeat stopped, which would discard other captures' events.\n * Flushing also drops the event from the heartbeat queue once ingested, so the interval\n * winds down on its own. No-op when no play session is in progress.\n */\n private flushStopEvent(stopReason: string) {\n const stopEvent = this.stopEvent;\n if (!stopEvent) {\n return;\n }\n // the next play queues a fresh delayed stop event\n this.stopEvent = null;\n this.playStartTime = null;\n stopEvent.event_properties = {\n ...stopEvent.event_properties,\n stop_reason: stopReason,\n };\n this.heartbeat.trackNoDelay(stopEvent).catch(this.stop.bind(this));\n }\n\n // Placeholder: may need a generic state change listener to capture unusual events or to have\n // more control over the event tracking.\n // withStateChangeListener(listener: (previousState: VideoState, nextState: VideoState) => void): VideoCapture {\n\n /**\n * Start capturing analytics events for the video element\n * @returns The VideoCapture instance.\n * @throws An error if the video element is not specified.\n */\n start(): VideoCapture {\n const videoEl = this.videoEl ?? this.embeddedVideoPlayer;\n if (!videoEl) {\n throw new Error(\n 'Video element not specified. Use withVideoElement() or withEmbeddedPlayer() to specify the video element.',\n );\n }\n if (this.videoEl && this.embeddedVideoPlayer) {\n throw new Error(\n 'Both video element and embedded video player specified. Use only one of withVideoElement() or withEmbeddedPlayer() to specify the video element.',\n );\n }\n const videoObserver = new VideoObserver({\n videoEl,\n onStateChange: (previousState, nextState) => {\n this.listeners.forEach((listener) => listener(previousState, nextState));\n },\n vendor: this.vendor,\n isEmbedded: !!this.embeddedVideoPlayer,\n });\n\n this.onRemoveListeners.push(() => {\n videoObserver.destroy();\n });\n return this;\n }\n\n /**\n * Stop capturing analytics events for the video element.\n *\n * Observers are detached first so no playback state change can race with the final\n * event, then any in-progress play session is closed out.\n */\n stop() {\n this.onRemoveListeners.forEach((listener) => listener());\n this.onRemoveListeners = [];\n this.flushStopEvent('untracked');\n }\n\n parseStartEventProperties(nextState: VideoState): Record<string, string | number | boolean> {\n return {\n ...parseVideoEventProperties(nextState.lastEvent),\n duration: nextState.lastEvent?.duration ?? 0,\n start_time: nextState.lastEvent?.start_time ?? 0,\n position: nextState.position ?? 0,\n delivery_mode: this.getDeliveryMode(),\n };\n }\n\n private getDeliveryMode(): 'video' | 'audio' {\n return this.videoEl instanceof HTMLAudioElement ? 'audio' : 'video';\n }\n\n parseStopEventProperties(nextState: VideoState): Record<string, string | number | boolean> {\n return {\n ...this.parseStartEventProperties(nextState),\n // lastEvent.start_time is the playhead at the time of the event, which for a stop event is\n // where playback ended, so the position captured when the play session began is preferred.\n start_time: this.playStartTime ?? nextState.lastEvent?.start_time ?? 0,\n stream_duration: nextState.watchTime ?? 0,\n percent_completed: calculatePercentCompleted(nextState.position ?? 0, nextState.lastEvent?.duration ?? 0),\n ...(nextState.errorMessage ? { error_message: nextState.errorMessage } : {}),\n };\n }\n}\n\nfunction calculatePercentCompleted(currentTime: number, duration: number) {\n if (!Number.isFinite(currentTime) || !Number.isFinite(duration) || duration <= 0) {\n return 0;\n }\n return Math.min(100, Math.max(0, (currentTime / duration) * 100));\n}\n\nexport type VideoCaptureOptions = {\n vendor?: VideoVendor;\n extraEventProperties?: Record<string, string | number | boolean>;\n};\n\ntype UntrackVideoResult = () => void;\n\nexport type TrackVideoResult = UntrackVideoResult | Error;\n\n/**\n * Track video analytics events for an HTML video or audio element or embedded video player.js instance.\n *\n * Captures [Amplitude] Content Started and [Amplitude] Content Stopped events.\n *\n * @experimental This function is experimental and may not be stable.\n * @param amplitude - The Amplitude client instance.\n * @param videoEl - The HTML video or audio element or embedded video player.js instance to capture events from.\n * @param options - The options for the video capture.\n * @returns A function to stop the video capture.\n */\nexport function trackVideo(\n amplitude: BrowserClient,\n videoEl: HTMLMediaElement | EmbeddedVideoPlayer,\n options: VideoCaptureOptions = {},\n): TrackVideoResult {\n const videoCapture = new VideoCapture(amplitude);\n if (videoEl instanceof HTMLMediaElement) {\n videoCapture.withVideoElement(videoEl);\n } else {\n videoCapture.withEmbeddedPlayer(videoEl);\n }\n if (options.vendor) {\n videoCapture.withVendor(options.vendor);\n }\n const extraEventProperties = options.extraEventProperties ?? {};\n\n try {\n videoCapture\n .withExtraEventProperties({\n stream_session_id: UUID(),\n ...extraEventProperties,\n })\n .captureVideoStarted()\n .captureVideoStopped()\n .start();\n } catch (error) {\n return error as Error;\n }\n\n return () => videoCapture.stop();\n}\n"]}
@@ -1 +1 @@
1
- !function(){"use strict";!function(e,t){var n=e.amplitude||{_q:[],_iq:{}};if(n.invoked)e.console&&console.error&&console.error("Amplitude snippet has been loaded.");else{var r=function(e,t){e.prototype[t]=function(){return this._q.push({name:t,args:Array.prototype.slice.call(arguments,0)}),this}},i=function(e,t,n){return function(r){e._q.push({name:t,args:Array.prototype.slice.call(n,0),resolve:r})}},o=function(e,t,n){e[t]=function(){if(n)return{promise:new Promise(i(e,t,Array.prototype.slice.call(arguments)))}}},s=function(e){for(var t=0;t<v.length;t++)o(e,v[t],!1);for(var n=0;n<y.length;n++)o(e,y[n],!0)};n.invoked=!0;var u=t.getElementsByTagName("script")[0],a=t.createElement("script");a.src="https://cdn.amplitude.com/libs/plugin-autocapture-browser-0.9.0-min.js.gz",a.async=!1,u.parentNode.insertBefore(a,u);var c=t.createElement("script");c.type="text/javascript",c.integrity="sha384-5CFSmGmmCyudYhiRUA3sg3JK9ZSa8Ps0EnnzH1p2Q/oM7/YNKazcXDkLsCyzuo3Y",c.crossOrigin="anonymous",c.async=!1,c.src="https://cdn.amplitude.com/libs/analytics-browser-2.46.0-min.js.gz",c.onload=function(){e.amplitude.runQueuedFunctions||console.log("[Amplitude] Error: could not load SDK"),e.amplitude.init("YOUR_API_KEY","YOUR_USER_ID",{instanceName:"amplitude-bookmarklet",serverZone:"YOUR_SERVER_ZONE",ingestionMetadata:{sourceName:"browser-typescript-bookmarklet",sourceVersion:"1.0.0"},optOut:!1}),amplitudeAutocapturePlugin&&amplitudeAutocapturePlugin.autocapturePlugin&&"function"==typeof amplitudeAutocapturePlugin.autocapturePlugin&&e.amplitude.add(amplitudeAutocapturePlugin.autocapturePlugin()),alert("Amplitude is now tracking events!")},u.parentNode.insertBefore(c,u);for(var p=function(){return this._q=[],this},l=["add","append","clearAll","prepend","set","setOnce","unset","preInsert","postInsert","remove","getUserProperties"],d=0;d<l.length;d++)r(p,l[d]);n.Identify=p;for(var m=function(){return this._q=[],this},g=["getEventProperties","setProductId","setQuantity","setPrice","setRevenue","setRevenueType","setReceipt","setReceiptSig","setCurrency","setEventProperties"],f=0;f<g.length;f++)r(m,g[f]);n.Revenue=m;var v=["getDeviceId","setDeviceId","getSessionId","setSessionId","getUserId","setUserId","setOptOut","setTransport","reset","extendSession"],y=["init","add","remove","track","logEvent","identify","groupIdentify","setGroup","revenue","flush"];s(n),n.createInstance=function(e){return n._iq[e]={_q:[]},s(n._iq[e]),n._iq[e]},e.amplitude=n}}(window,document)}();
1
+ !function(){"use strict";!function(e,t){var n=e.amplitude||{_q:[],_iq:{}};if(n.invoked)e.console&&console.error&&console.error("Amplitude snippet has been loaded.");else{var r=function(e,t){e.prototype[t]=function(){return this._q.push({name:t,args:Array.prototype.slice.call(arguments,0)}),this}},i=function(e,t,n){return function(r){e._q.push({name:t,args:Array.prototype.slice.call(n,0),resolve:r})}},o=function(e,t,n){e[t]=function(){if(n)return{promise:new Promise(i(e,t,Array.prototype.slice.call(arguments)))}}},s=function(e){for(var t=0;t<f.length;t++)o(e,f[t],!1);for(var n=0;n<y.length;n++)o(e,y[n],!0)};n.invoked=!0;var u=t.getElementsByTagName("script")[0],a=t.createElement("script");a.src="https://cdn.amplitude.com/libs/plugin-autocapture-browser-0.9.0-min.js.gz",a.async=!1,u.parentNode.insertBefore(a,u);var c=t.createElement("script");c.type="text/javascript",c.integrity="sha384-gt3Pvso3avjAL5mGN9NcOGKwcy+bj20O840b2Lc/uhLu77g9UK2KXDLnlsUezUcK",c.crossOrigin="anonymous",c.async=!1,c.src="https://cdn.amplitude.com/libs/analytics-browser-2.47.0-video-analytics-5.0-min.js.gz",c.onload=function(){e.amplitude.runQueuedFunctions||console.log("[Amplitude] Error: could not load SDK"),e.amplitude.init("YOUR_API_KEY","YOUR_USER_ID",{instanceName:"amplitude-bookmarklet",serverZone:"YOUR_SERVER_ZONE",ingestionMetadata:{sourceName:"browser-typescript-bookmarklet",sourceVersion:"1.0.0"},optOut:!1}),amplitudeAutocapturePlugin&&amplitudeAutocapturePlugin.autocapturePlugin&&"function"==typeof amplitudeAutocapturePlugin.autocapturePlugin&&e.amplitude.add(amplitudeAutocapturePlugin.autocapturePlugin()),alert("Amplitude is now tracking events!")},u.parentNode.insertBefore(c,u);for(var p=function(){return this._q=[],this},l=["add","append","clearAll","prepend","set","setOnce","unset","preInsert","postInsert","remove","getUserProperties"],d=0;d<l.length;d++)r(p,l[d]);n.Identify=p;for(var m=function(){return this._q=[],this},g=["getEventProperties","setProductId","setQuantity","setPrice","setRevenue","setRevenueType","setReceipt","setReceiptSig","setCurrency","setEventProperties"],v=0;v<g.length;v++)r(m,g[v]);n.Revenue=m;var f=["getDeviceId","setDeviceId","getSessionId","setSessionId","getUserId","setUserId","setOptOut","setTransport","reset","extendSession"],y=["init","add","remove","track","logEvent","identify","groupIdentify","setGroup","revenue","flush"];s(n),n.createInstance=function(e){return n._iq[e]={_q:[]},s(n._iq[e]),n._iq[e]},e.amplitude=n}}(window,document)}();
@@ -1 +1 @@
1
- javascript:!function()%7B%22use%20strict%22%3B!function(e%2Ct)%7Bvar%20n%3De.amplitude%7C%7C%7B_q%3A%5B%5D%2C_iq%3A%7B%7D%7D%3Bif(n.invoked)e.console%26%26console.error%26%26console.error(%22Amplitude%20snippet%20has%20been%20loaded.%22)%3Belse%7Bvar%20r%3Dfunction(e%2Ct)%7Be.prototype%5Bt%5D%3Dfunction()%7Breturn%20this._q.push(%7Bname%3At%2Cargs%3AArray.prototype.slice.call(arguments%2C0)%7D)%2Cthis%7D%7D%2Ci%3Dfunction(e%2Ct%2Cn)%7Breturn%20function(r)%7Be._q.push(%7Bname%3At%2Cargs%3AArray.prototype.slice.call(n%2C0)%2Cresolve%3Ar%7D)%7D%7D%2Co%3Dfunction(e%2Ct%2Cn)%7Be%5Bt%5D%3Dfunction()%7Bif(n)return%7Bpromise%3Anew%20Promise(i(e%2Ct%2CArray.prototype.slice.call(arguments)))%7D%7D%7D%2Cs%3Dfunction(e)%7Bfor(var%20t%3D0%3Bt%3Cv.length%3Bt%2B%2B)o(e%2Cv%5Bt%5D%2C!1)%3Bfor(var%20n%3D0%3Bn%3Cy.length%3Bn%2B%2B)o(e%2Cy%5Bn%5D%2C!0)%7D%3Bn.invoked%3D!0%3Bvar%20u%3Dt.getElementsByTagName(%22script%22)%5B0%5D%2Ca%3Dt.createElement(%22script%22)%3Ba.src%3D%22https%3A%2F%2Fcdn.amplitude.com%2Flibs%2Fplugin-autocapture-browser-0.9.0-min.js.gz%22%2Ca.async%3D!1%2Cu.parentNode.insertBefore(a%2Cu)%3Bvar%20c%3Dt.createElement(%22script%22)%3Bc.type%3D%22text%2Fjavascript%22%2Cc.integrity%3D%22sha384-5CFSmGmmCyudYhiRUA3sg3JK9ZSa8Ps0EnnzH1p2Q%2FoM7%2FYNKazcXDkLsCyzuo3Y%22%2Cc.crossOrigin%3D%22anonymous%22%2Cc.async%3D!1%2Cc.src%3D%22https%3A%2F%2Fcdn.amplitude.com%2Flibs%2Fanalytics-browser-2.46.0-min.js.gz%22%2Cc.onload%3Dfunction()%7Be.amplitude.runQueuedFunctions%7C%7Cconsole.log(%22%5BAmplitude%5D%20Error%3A%20could%20not%20load%20SDK%22)%2Ce.amplitude.init(%22YOUR_API_KEY%22%2C%22YOUR_USER_ID%22%2C%7BinstanceName%3A%22amplitude-bookmarklet%22%2CserverZone%3A%22YOUR_SERVER_ZONE%22%2CingestionMetadata%3A%7BsourceName%3A%22browser-typescript-bookmarklet%22%2CsourceVersion%3A%221.0.0%22%7D%2CoptOut%3A!1%7D)%2CamplitudeAutocapturePlugin%26%26amplitudeAutocapturePlugin.autocapturePlugin%26%26%22function%22%3D%3Dtypeof%20amplitudeAutocapturePlugin.autocapturePlugin%26%26e.amplitude.add(amplitudeAutocapturePlugin.autocapturePlugin())%2Calert(%22Amplitude%20is%20now%20tracking%20events!%22)%7D%2Cu.parentNode.insertBefore(c%2Cu)%3Bfor(var%20p%3Dfunction()%7Breturn%20this._q%3D%5B%5D%2Cthis%7D%2Cl%3D%5B%22add%22%2C%22append%22%2C%22clearAll%22%2C%22prepend%22%2C%22set%22%2C%22setOnce%22%2C%22unset%22%2C%22preInsert%22%2C%22postInsert%22%2C%22remove%22%2C%22getUserProperties%22%5D%2Cd%3D0%3Bd%3Cl.length%3Bd%2B%2B)r(p%2Cl%5Bd%5D)%3Bn.Identify%3Dp%3Bfor(var%20m%3Dfunction()%7Breturn%20this._q%3D%5B%5D%2Cthis%7D%2Cg%3D%5B%22getEventProperties%22%2C%22setProductId%22%2C%22setQuantity%22%2C%22setPrice%22%2C%22setRevenue%22%2C%22setRevenueType%22%2C%22setReceipt%22%2C%22setReceiptSig%22%2C%22setCurrency%22%2C%22setEventProperties%22%5D%2Cf%3D0%3Bf%3Cg.length%3Bf%2B%2B)r(m%2Cg%5Bf%5D)%3Bn.Revenue%3Dm%3Bvar%20v%3D%5B%22getDeviceId%22%2C%22setDeviceId%22%2C%22getSessionId%22%2C%22setSessionId%22%2C%22getUserId%22%2C%22setUserId%22%2C%22setOptOut%22%2C%22setTransport%22%2C%22reset%22%2C%22extendSession%22%5D%2Cy%3D%5B%22init%22%2C%22add%22%2C%22remove%22%2C%22track%22%2C%22logEvent%22%2C%22identify%22%2C%22groupIdentify%22%2C%22setGroup%22%2C%22revenue%22%2C%22flush%22%5D%3Bs(n)%2Cn.createInstance%3Dfunction(e)%7Breturn%20n._iq%5Be%5D%3D%7B_q%3A%5B%5D%7D%2Cs(n._iq%5Be%5D)%2Cn._iq%5Be%5D%7D%2Ce.amplitude%3Dn%7D%7D(window%2Cdocument)%7D()%3B%0A
1
+ javascript:!function()%7B%22use%20strict%22%3B!function(e%2Ct)%7Bvar%20n%3De.amplitude%7C%7C%7B_q%3A%5B%5D%2C_iq%3A%7B%7D%7D%3Bif(n.invoked)e.console%26%26console.error%26%26console.error(%22Amplitude%20snippet%20has%20been%20loaded.%22)%3Belse%7Bvar%20r%3Dfunction(e%2Ct)%7Be.prototype%5Bt%5D%3Dfunction()%7Breturn%20this._q.push(%7Bname%3At%2Cargs%3AArray.prototype.slice.call(arguments%2C0)%7D)%2Cthis%7D%7D%2Ci%3Dfunction(e%2Ct%2Cn)%7Breturn%20function(r)%7Be._q.push(%7Bname%3At%2Cargs%3AArray.prototype.slice.call(n%2C0)%2Cresolve%3Ar%7D)%7D%7D%2Co%3Dfunction(e%2Ct%2Cn)%7Be%5Bt%5D%3Dfunction()%7Bif(n)return%7Bpromise%3Anew%20Promise(i(e%2Ct%2CArray.prototype.slice.call(arguments)))%7D%7D%7D%2Cs%3Dfunction(e)%7Bfor(var%20t%3D0%3Bt%3Cf.length%3Bt%2B%2B)o(e%2Cf%5Bt%5D%2C!1)%3Bfor(var%20n%3D0%3Bn%3Cy.length%3Bn%2B%2B)o(e%2Cy%5Bn%5D%2C!0)%7D%3Bn.invoked%3D!0%3Bvar%20u%3Dt.getElementsByTagName(%22script%22)%5B0%5D%2Ca%3Dt.createElement(%22script%22)%3Ba.src%3D%22https%3A%2F%2Fcdn.amplitude.com%2Flibs%2Fplugin-autocapture-browser-0.9.0-min.js.gz%22%2Ca.async%3D!1%2Cu.parentNode.insertBefore(a%2Cu)%3Bvar%20c%3Dt.createElement(%22script%22)%3Bc.type%3D%22text%2Fjavascript%22%2Cc.integrity%3D%22sha384-gt3Pvso3avjAL5mGN9NcOGKwcy%2Bbj20O840b2Lc%2FuhLu77g9UK2KXDLnlsUezUcK%22%2Cc.crossOrigin%3D%22anonymous%22%2Cc.async%3D!1%2Cc.src%3D%22https%3A%2F%2Fcdn.amplitude.com%2Flibs%2Fanalytics-browser-2.47.0-video-analytics-5.0-min.js.gz%22%2Cc.onload%3Dfunction()%7Be.amplitude.runQueuedFunctions%7C%7Cconsole.log(%22%5BAmplitude%5D%20Error%3A%20could%20not%20load%20SDK%22)%2Ce.amplitude.init(%22YOUR_API_KEY%22%2C%22YOUR_USER_ID%22%2C%7BinstanceName%3A%22amplitude-bookmarklet%22%2CserverZone%3A%22YOUR_SERVER_ZONE%22%2CingestionMetadata%3A%7BsourceName%3A%22browser-typescript-bookmarklet%22%2CsourceVersion%3A%221.0.0%22%7D%2CoptOut%3A!1%7D)%2CamplitudeAutocapturePlugin%26%26amplitudeAutocapturePlugin.autocapturePlugin%26%26%22function%22%3D%3Dtypeof%20amplitudeAutocapturePlugin.autocapturePlugin%26%26e.amplitude.add(amplitudeAutocapturePlugin.autocapturePlugin())%2Calert(%22Amplitude%20is%20now%20tracking%20events!%22)%7D%2Cu.parentNode.insertBefore(c%2Cu)%3Bfor(var%20p%3Dfunction()%7Breturn%20this._q%3D%5B%5D%2Cthis%7D%2Cl%3D%5B%22add%22%2C%22append%22%2C%22clearAll%22%2C%22prepend%22%2C%22set%22%2C%22setOnce%22%2C%22unset%22%2C%22preInsert%22%2C%22postInsert%22%2C%22remove%22%2C%22getUserProperties%22%5D%2Cd%3D0%3Bd%3Cl.length%3Bd%2B%2B)r(p%2Cl%5Bd%5D)%3Bn.Identify%3Dp%3Bfor(var%20m%3Dfunction()%7Breturn%20this._q%3D%5B%5D%2Cthis%7D%2Cg%3D%5B%22getEventProperties%22%2C%22setProductId%22%2C%22setQuantity%22%2C%22setPrice%22%2C%22setRevenue%22%2C%22setRevenueType%22%2C%22setReceipt%22%2C%22setReceiptSig%22%2C%22setCurrency%22%2C%22setEventProperties%22%5D%2Cv%3D0%3Bv%3Cg.length%3Bv%2B%2B)r(m%2Cg%5Bv%5D)%3Bn.Revenue%3Dm%3Bvar%20f%3D%5B%22getDeviceId%22%2C%22setDeviceId%22%2C%22getSessionId%22%2C%22setSessionId%22%2C%22getUserId%22%2C%22setUserId%22%2C%22setOptOut%22%2C%22setTransport%22%2C%22reset%22%2C%22extendSession%22%5D%2Cy%3D%5B%22init%22%2C%22add%22%2C%22remove%22%2C%22track%22%2C%22logEvent%22%2C%22identify%22%2C%22groupIdentify%22%2C%22setGroup%22%2C%22revenue%22%2C%22flush%22%5D%3Bs(n)%2Cn.createInstance%3Dfunction(e)%7Breturn%20n._iq%5Be%5D%3D%7B_q%3A%5B%5D%7D%2Cs(n._iq%5Be%5D)%2Cn._iq%5Be%5D%7D%2Ce.amplitude%3Dn%7D%7D(window%2Cdocument)%7D()%3B%0A