@amplitude/analytics-browser 2.46.0-video-analytics-4.0 → 2.46.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 +2 -9
  3. package/lib/cjs/config.d.ts.map +1 -1
  4. package/lib/cjs/config.js +3 -28
  5. package/lib/cjs/config.js.map +1 -1
  6. package/lib/cjs/constants.d.ts +0 -2
  7. package/lib/cjs/constants.d.ts.map +1 -1
  8. package/lib/cjs/constants.js +1 -3
  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 +10 -32
  15. package/lib/cjs/video-capture/video-capture.d.ts.map +1 -1
  16. package/lib/cjs/video-capture/video-capture.js +14 -117
  17. package/lib/cjs/video-capture/video-capture.js.map +1 -1
  18. package/lib/esm/config.d.ts +2 -9
  19. package/lib/esm/config.d.ts.map +1 -1
  20. package/lib/esm/config.js +2 -26
  21. package/lib/esm/config.js.map +1 -1
  22. package/lib/esm/constants.d.ts +0 -2
  23. package/lib/esm/constants.d.ts.map +1 -1
  24. package/lib/esm/constants.js +0 -2
  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 +10 -32
  31. package/lib/esm/video-capture/video-capture.d.ts.map +1 -1
  32. package/lib/esm/video-capture/video-capture.js +16 -119
  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 +2 -9
  48. package/lib/scripts/config.d.ts.map +1 -1
  49. package/lib/scripts/constants.d.ts +0 -2
  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 +10 -32
  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 var VERSION = '2.46.0-video-analytics-4.0';
1
+ export var VERSION = '2.46.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,4BAA4B,CAAC","sourcesContent":["export const VERSION = '2.46.0-video-analytics-4.0';\n"]}
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,24 +1,20 @@
1
- import { VideoState, BrowserClient, EmbeddedVideoPlayer, VideoVendor } from '@amplitude/analytics-core';
1
+ import { 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;
6
5
  private embeddedVideoPlayer;
7
6
  private vendor?;
8
7
  private extraEventProperties;
9
- private stopEvent;
10
8
  private listeners;
11
9
  private onRemoveListeners;
12
- private playId;
13
- private playStartTime;
14
10
  constructor(amplitude: BrowserClient);
15
11
  /**
16
- * Specify a video or audio element to capture events from
12
+ * Specify a video element to capture events from
17
13
  *
18
- * @param videoEl - The HTML video or audio element to capture events from.
14
+ * @param videoEl - The HTML video element to capture events from.
19
15
  * @returns The VideoCapture instance.
20
16
  */
21
- withVideoElement(videoEl: HTMLMediaElement): VideoCapture;
17
+ withVideoElement(videoEl: HTMLVideoElement): VideoCapture;
22
18
  /**
23
19
  * Specify an embedded video player.js instance to capture events from
24
20
  * @param player - The embedded video player.js instance to capture events from.
@@ -40,40 +36,22 @@ export declare class VideoCapture {
40
36
  */
41
37
  withExtraEventProperties(properties: Record<string, string | number | boolean>): VideoCapture;
42
38
  /**
43
- * Track a "[Amplitude] Content Started" event every time the video starts playing
39
+ * Track a "Video Content Started" event every time the video starts playing
44
40
  * @returns The VideoCapture instance.
45
41
  */
46
42
  captureVideoStarted(): VideoCapture;
47
43
  /**
48
- * Track a "[Amplitude] Content Stopped" event every time the video stops playing
44
+ * Track a "Video Content Stopped" event every time the video stops playing
49
45
  * @returns The VideoCapture instance.
50
46
  */
51
47
  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;
61
48
  /**
62
49
  * Start capturing analytics events for the video element
63
50
  * @returns The VideoCapture instance.
64
51
  * @throws An error if the video element is not specified.
65
52
  */
66
53
  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
- */
73
54
  stop(): void;
74
- parseStartEventProperties(nextState: VideoState): Record<string, string | number | boolean>;
75
- private getDeliveryMode;
76
- parseStopEventProperties(nextState: VideoState): Record<string, string | number | boolean>;
77
55
  }
78
56
  export type VideoCaptureOptions = {
79
57
  vendor?: VideoVendor;
@@ -82,16 +60,16 @@ export type VideoCaptureOptions = {
82
60
  type UntrackVideoResult = () => void;
83
61
  export type TrackVideoResult = UntrackVideoResult | Error;
84
62
  /**
85
- * Track video analytics events for an HTML video or audio element or embedded video player.js instance.
63
+ * Track video analytics events for an HTML video element or embedded video player.js instance.
86
64
  *
87
- * Captures [Amplitude] Content Started and [Amplitude] Content Stopped events.
65
+ * Captures Video Started and Video Stopped events.
88
66
  *
89
67
  * @experimental This function is experimental and may not be stable.
90
68
  * @param amplitude - The Amplitude client instance.
91
- * @param videoEl - The HTML video or audio element or embedded video player.js instance to capture events from.
69
+ * @param videoEl - The HTML video element or embedded video player.js instance to capture events from.
92
70
  * @param options - The options for the video capture.
93
71
  * @returns A function to stop the video capture.
94
72
  */
95
- export declare function trackVideo(amplitude: BrowserClient, videoEl: HTMLMediaElement | EmbeddedVideoPlayer, options?: VideoCaptureOptions): TrackVideoResult;
73
+ export declare function trackVideo(amplitude: BrowserClient, videoEl: HTMLVideoElement | EmbeddedVideoPlayer, options?: VideoCaptureOptions): TrackVideoResult;
96
74
  export {};
97
75
  //# 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,EACL,UAAU,EAEV,aAAa,EACb,mBAAmB,EACnB,WAAW,EAIZ,MAAM,2BAA2B,CAAC;AA4BnC,qBAAa,YAAY;IAYX,OAAO,CAAC,QAAQ,CAAC,SAAS;IAXtC,OAAO,CAAC,OAAO,CAAiC;IAChD,OA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ChC,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,56 +1,18 @@
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: `last_position` is an observer internal,
8
- * and `percent_completed`/`stop_reason` describe the player event rather than the play session,
9
- * which tracks its own values.
10
- */
11
- var OMITTED_VIDEO_EVENT_PROPERTIES = new Set(['last_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
- }
1
+ import { __assign } from "tslib";
2
+ import { VideoObserver, UUID, } from '@amplitude/analytics-core';
37
3
  var VideoCapture = /** @class */ (function () {
38
4
  function VideoCapture(amplitude) {
39
5
  this.amplitude = amplitude;
40
6
  this.videoEl = null;
41
7
  this.embeddedVideoPlayer = null;
42
8
  this.extraEventProperties = {};
43
- this.stopEvent = null;
44
9
  this.listeners = [];
45
10
  this.onRemoveListeners = [];
46
- this.playId = null;
47
- this.playStartTime = null;
48
- this.heartbeat = getHeartbeatInstance(this.amplitude);
49
11
  }
50
12
  /**
51
- * Specify a video or audio element to capture events from
13
+ * Specify a video element to capture events from
52
14
  *
53
- * @param videoEl - The HTML video or audio element to capture events from.
15
+ * @param videoEl - The HTML video element to capture events from.
54
16
  * @returns The VideoCapture instance.
55
17
  */
56
18
  VideoCapture.prototype.withVideoElement = function (videoEl) {
@@ -87,71 +49,33 @@ var VideoCapture = /** @class */ (function () {
87
49
  return this;
88
50
  };
89
51
  /**
90
- * Track a "[Amplitude] Content Started" event every time the video starts playing
52
+ * Track a "Video Content Started" event every time the video starts playing
91
53
  * @returns The VideoCapture instance.
92
54
  */
93
55
  VideoCapture.prototype.captureVideoStarted = function () {
94
56
  var _this = this;
95
57
  this.listeners.push(function (previousState, nextState) {
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));
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));
111
61
  }
112
62
  });
113
63
  return this;
114
64
  };
115
65
  /**
116
- * Track a "[Amplitude] Content Stopped" event every time the video stops playing
66
+ * Track a "Video Content Stopped" event every time the video stops playing
117
67
  * @returns The VideoCapture instance.
118
68
  */
119
69
  VideoCapture.prototype.captureVideoStopped = function () {
120
70
  var _this = this;
121
71
  this.listeners.push(function (previousState, nextState) {
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);
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));
132
75
  }
133
76
  });
134
77
  return this;
135
78
  };
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
- };
155
79
  // Placeholder: may need a generic state change listener to capture unusual events or to have
156
80
  // more control over the event tracking.
157
81
  // withStateChangeListener(listener: (previousState: VideoState, nextState: VideoState) => void): VideoCapture {
@@ -183,48 +107,21 @@ var VideoCapture = /** @class */ (function () {
183
107
  });
184
108
  return this;
185
109
  };
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
- */
192
110
  VideoCapture.prototype.stop = function () {
193
111
  this.onRemoveListeners.forEach(function (listener) { return listener(); });
194
112
  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, watch_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 } : {}));
210
113
  };
211
114
  return VideoCapture;
212
115
  }());
213
116
  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
- }
220
117
  /**
221
- * Track video analytics events for an HTML video or audio element or embedded video player.js instance.
118
+ * Track video analytics events for an HTML video element or embedded video player.js instance.
222
119
  *
223
- * Captures [Amplitude] Content Started and [Amplitude] Content Stopped events.
120
+ * Captures Video Started and Video Stopped events.
224
121
  *
225
122
  * @experimental This function is experimental and may not be stable.
226
123
  * @param amplitude - The Amplitude client instance.
227
- * @param videoEl - The HTML video or audio element or embedded video player.js instance to capture events from.
124
+ * @param videoEl - The HTML video element or embedded video player.js instance to capture events from.
228
125
  * @param options - The options for the video capture.
229
126
  * @returns A function to stop the video capture.
230
127
  */
@@ -232,7 +129,7 @@ export function trackVideo(amplitude, videoEl, options) {
232
129
  var _a;
233
130
  if (options === void 0) { options = {}; }
234
131
  var videoCapture = new VideoCapture(amplitude);
235
- if (videoEl instanceof HTMLMediaElement) {
132
+ if (videoEl instanceof HTMLVideoElement) {
236
133
  videoCapture.withVideoElement(videoEl);
237
134
  }
238
135
  else {
@@ -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,EAEJ,oBAAoB,GACrB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,6BAA6B,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAC;AAE5F,kFAAkF;AAClF,IAAM,sBAAsB,GAAG,IAAI,GAAG,CAA8B,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;AAE5F;;;;GAIG;AACH,IAAM,8BAA8B,GAAG,IAAI,GAAG,CAAC,CAAC,eAAe,EAAE,mBAAmB,EAAE,aAAa,CAAC,CAAC,CAAC;AAEtG;;;GAGG;AACH,SAAS,yBAAyB,CAAC,SAAkC;;IACnE,IAAM,UAAU,GAA8C,EAAE,CAAC;;QACjE,KAA2B,IAAA,KAAA,SAAA,MAAM,CAAC,OAAO,CAAC,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,EAAE,CAAC,CAAA,gBAAA,4BAAE;YAAjD,IAAA,KAAA,mBAAY,EAAX,GAAG,QAAA,EAAE,KAAK,QAAA;YACpB,IAAI,8BAA8B,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE;gBACpF,SAAS;aACV;YACD,UAAU,CAAC,GAAG,CAAC,GAAG,KAAkC,CAAC;SACtD;;;;;;;;;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;IAYE,sBAA6B,SAAwB;QAAxB,cAAS,GAAT,SAAS,CAAe;QAX7C,YAAO,GAA4B,IAAI,CAAC;QAExC,wBAAmB,GAA+B,IAAI,CAAC;QAEvD,yBAAoB,GAA8C,EAAE,CAAC;QACrE,cAAS,GAAqB,IA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AO,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 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: `last_position` is an observer internal,\n * and `percent_completed`/`stop_reason` describe the player event rather than the play session,\n * which tracks its own values.\n */\nconst OMITTED_VIDEO_EVENT_PROPERTIES = new Set(['last_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 watch_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 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();\n}\n"]}
1
+ {"version":3,"file":"video-capture.js","sourceRoot":"","sources":["../../../src/video-capture/video-capture.ts"],"names":[],"mappings":";AAAA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,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;IAED,2BAAI,GAAJ;QACE,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,UAAC,QAAQ,IAAK,OAAA,QAAQ,EAAE,EAAV,CAAU,CAAC,CAAC;QACzD,IAAI,CAAC,iBAAiB,GAAG,EAAE,CAAC;IAC9B,CAAC;IACH,mBAAC;AAAD,CAAC,AAjID,IAiIC;;AAWD;;;;;;;;;;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();\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-Iv/3hfl4wm5kzRLNGFYnn9ujyjH+Iw51ByCb+GRzsHlIH1tJ1x1LDjMaKxwZTmz5",c.crossOrigin="anonymous",c.async=!1,c.src="https://cdn.amplitude.com/libs/analytics-browser-2.46.0-video-analytics-4.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<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 +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-Iv%2F3hfl4wm5kzRLNGFYnn9ujyjH%2BIw51ByCb%2BGRzsHlIH1tJ1x1LDjMaKxwZTmz5%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-video-analytics-4.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%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