@amplitude/analytics-browser 2.46.0-video-analytics-2.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 (59) hide show
  1. package/README.md +1 -1
  2. package/lib/cjs/browser-client.js +1 -1
  3. package/lib/cjs/browser-client.js.map +1 -1
  4. package/lib/cjs/config.d.ts +2 -10
  5. package/lib/cjs/config.d.ts.map +1 -1
  6. package/lib/cjs/config.js +4 -30
  7. package/lib/cjs/config.js.map +1 -1
  8. package/lib/cjs/constants.d.ts +0 -2
  9. package/lib/cjs/constants.d.ts.map +1 -1
  10. package/lib/cjs/constants.js +1 -3
  11. package/lib/cjs/constants.js.map +1 -1
  12. package/lib/cjs/version.d.ts +1 -1
  13. package/lib/cjs/version.d.ts.map +1 -1
  14. package/lib/cjs/version.js +1 -1
  15. package/lib/cjs/version.js.map +1 -1
  16. package/lib/cjs/video-capture/video-capture.d.ts +10 -32
  17. package/lib/cjs/video-capture/video-capture.d.ts.map +1 -1
  18. package/lib/cjs/video-capture/video-capture.js +14 -91
  19. package/lib/cjs/video-capture/video-capture.js.map +1 -1
  20. package/lib/esm/browser-client.js +1 -1
  21. package/lib/esm/browser-client.js.map +1 -1
  22. package/lib/esm/config.d.ts +2 -10
  23. package/lib/esm/config.d.ts.map +1 -1
  24. package/lib/esm/config.js +3 -28
  25. package/lib/esm/config.js.map +1 -1
  26. package/lib/esm/constants.d.ts +0 -2
  27. package/lib/esm/constants.d.ts.map +1 -1
  28. package/lib/esm/constants.js +0 -2
  29. package/lib/esm/constants.js.map +1 -1
  30. package/lib/esm/version.d.ts +1 -1
  31. package/lib/esm/version.d.ts.map +1 -1
  32. package/lib/esm/version.js +1 -1
  33. package/lib/esm/version.js.map +1 -1
  34. package/lib/esm/video-capture/video-capture.d.ts +10 -32
  35. package/lib/esm/video-capture/video-capture.d.ts.map +1 -1
  36. package/lib/esm/video-capture/video-capture.js +15 -92
  37. package/lib/esm/video-capture/video-capture.js.map +1 -1
  38. package/lib/scripts/amplitude-bookmarklet-snippet-min.js +1 -1
  39. package/lib/scripts/amplitude-bookmarklet.html +1 -1
  40. package/lib/scripts/amplitude-gtm-min.js +1 -1
  41. package/lib/scripts/amplitude-gtm-min.js.gz +0 -0
  42. package/lib/scripts/amplitude-gtm-min.js.map +1 -1
  43. package/lib/scripts/amplitude-gtm-snippet-min.js +1 -1
  44. package/lib/scripts/amplitude-min.js +1 -1
  45. package/lib/scripts/amplitude-min.js.gz +0 -0
  46. package/lib/scripts/amplitude-min.js.map +1 -1
  47. package/lib/scripts/amplitude-min.umd.js +1 -1
  48. package/lib/scripts/amplitude-min.umd.js.gz +0 -0
  49. package/lib/scripts/amplitude-snippet-instructions.html +1 -1
  50. package/lib/scripts/amplitude-snippet-min.js +1 -1
  51. package/lib/scripts/config.d.ts +2 -10
  52. package/lib/scripts/config.d.ts.map +1 -1
  53. package/lib/scripts/constants.d.ts +0 -2
  54. package/lib/scripts/constants.d.ts.map +1 -1
  55. package/lib/scripts/version.d.ts +1 -1
  56. package/lib/scripts/version.d.ts.map +1 -1
  57. package/lib/scripts/video-capture/video-capture.d.ts +10 -32
  58. package/lib/scripts/video-capture/video-capture.d.ts.map +1 -1
  59. package/package.json +9 -9
@@ -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-2.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;AAMnC,qBAAa,YAAY;IAYX,OAAO,CAAC,QAAQ,CAAC,SAAS;IAXtC,OAAO,CAAC,OAAO,C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AAmB,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,25 +1,18 @@
1
1
  import { __assign } 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']);
2
+ import { VideoObserver, UUID, } from '@amplitude/analytics-core';
6
3
  var VideoCapture = /** @class */ (function () {
7
4
  function VideoCapture(amplitude) {
8
5
  this.amplitude = amplitude;
9
6
  this.videoEl = null;
10
7
  this.embeddedVideoPlayer = null;
11
8
  this.extraEventProperties = {};
12
- this.stopEvent = null;
13
9
  this.listeners = [];
14
10
  this.onRemoveListeners = [];
15
- this.playId = null;
16
- this.playStartTime = null;
17
- this.heartbeat = getHeartbeatInstance(this.amplitude);
18
11
  }
19
12
  /**
20
- * Specify a video or audio element to capture events from
13
+ * Specify a video element to capture events from
21
14
  *
22
- * @param videoEl - The HTML video or audio element to capture events from.
15
+ * @param videoEl - The HTML video element to capture events from.
23
16
  * @returns The VideoCapture instance.
24
17
  */
25
18
  VideoCapture.prototype.withVideoElement = function (videoEl) {
@@ -56,71 +49,33 @@ var VideoCapture = /** @class */ (function () {
56
49
  return this;
57
50
  };
58
51
  /**
59
- * 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
60
53
  * @returns The VideoCapture instance.
61
54
  */
62
55
  VideoCapture.prototype.captureVideoStarted = function () {
63
56
  var _this = this;
64
57
  this.listeners.push(function (previousState, nextState) {
65
- var _a, _b;
66
- if (!ACTIVE_PLAYBACK_STATES.has(previousState.playbackState) && nextState.playbackState === 'playing') {
67
- _this.playId = UUID();
68
- /* istanbul ignore next */
69
- _this.playStartTime = (_b = (_a = nextState.lastEvent) === null || _a === void 0 ? void 0 : _a.start_time) !== null && _b !== void 0 ? _b : 0;
70
- var now = new Date().getTime();
71
- var startEvent = {
72
- insert_id: UUID(),
73
- event_type: DEFAULT_CONTENT_STARTED_EVENT,
74
- time: now,
75
- event_properties: __assign(__assign(__assign(__assign({}, nextState.lastEvent), _this.parseStartEventProperties(nextState)), _this.extraEventProperties), { play_id: _this.playId }),
76
- };
77
- _this.stopEvent = __assign(__assign({}, startEvent), { insert_id: UUID(), event_type: DEFAULT_CONTENT_STOPPED_EVENT, time: now + 1, event_properties: __assign(__assign(__assign(__assign({}, nextState.lastEvent), _this.parseStopEventProperties(nextState)), _this.extraEventProperties), { stop_reason: 'timeout', play_id: _this.playId }) });
78
- _this.heartbeat.trackNoDelay(startEvent).catch(_this.stop.bind(_this));
79
- _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));
80
61
  }
81
62
  });
82
63
  return this;
83
64
  };
84
65
  /**
85
- * 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
86
67
  * @returns The VideoCapture instance.
87
68
  */
88
69
  VideoCapture.prototype.captureVideoStopped = function () {
89
70
  var _this = this;
90
71
  this.listeners.push(function (previousState, nextState) {
91
- // update the delayed event properties to have
92
- // the most up-to-date values
93
- if (_this.stopEvent) {
94
- _this.stopEvent.event_properties = __assign(__assign(__assign({}, _this.stopEvent.event_properties), _this.parseStopEventProperties(nextState)), _this.extraEventProperties);
95
- _this.stopEvent.time = new Date().getTime();
96
- void _this.heartbeat.update(_this.stopEvent);
97
- }
98
- if (ACTIVE_PLAYBACK_STATES.has(previousState.playbackState) &&
99
- !ACTIVE_PLAYBACK_STATES.has(nextState.playbackState)) {
100
- _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));
101
75
  }
102
76
  });
103
77
  return this;
104
78
  };
105
- /**
106
- * End the current play session by ingesting its queued delayed stop event immediately.
107
- *
108
- * The heartbeat is shared by every capture on the same Amplitude client, so the event is
109
- * flushed rather than the heartbeat stopped, which would discard other captures' events.
110
- * Flushing also drops the event from the heartbeat queue once ingested, so the interval
111
- * winds down on its own. No-op when no play session is in progress.
112
- */
113
- VideoCapture.prototype.flushStopEvent = function (stopReason) {
114
- var stopEvent = this.stopEvent;
115
- if (!stopEvent) {
116
- return;
117
- }
118
- // the next play queues a fresh delayed stop event
119
- this.stopEvent = null;
120
- this.playStartTime = null;
121
- stopEvent.event_properties = __assign(__assign({}, stopEvent.event_properties), { stop_reason: stopReason });
122
- this.heartbeat.trackNoDelay(stopEvent).catch(this.stop.bind(this));
123
- };
124
79
  // Placeholder: may need a generic state change listener to capture unusual events or to have
125
80
  // more control over the event tracking.
126
81
  // withStateChangeListener(listener: (previousState: VideoState, nextState: VideoState) => void): VideoCapture {
@@ -152,53 +107,21 @@ var VideoCapture = /** @class */ (function () {
152
107
  });
153
108
  return this;
154
109
  };
155
- /**
156
- * Stop capturing analytics events for the video element.
157
- *
158
- * Observers are detached first so no playback state change can race with the final
159
- * event, then any in-progress play session is closed out.
160
- */
161
110
  VideoCapture.prototype.stop = function () {
162
111
  this.onRemoveListeners.forEach(function (listener) { return listener(); });
163
112
  this.onRemoveListeners = [];
164
- this.flushStopEvent('untracked');
165
- };
166
- VideoCapture.prototype.parseStartEventProperties = function (nextState) {
167
- var _a, _b, _c, _d, _e;
168
- return {
169
- duration: (_b = (_a = nextState.lastEvent) === null || _a === void 0 ? void 0 : _a.duration) !== null && _b !== void 0 ? _b : 0,
170
- start_time: (_d = (_c = nextState.lastEvent) === null || _c === void 0 ? void 0 : _c.start_time) !== null && _d !== void 0 ? _d : 0,
171
- position: (_e = nextState.position) !== null && _e !== void 0 ? _e : 0,
172
- delivery_mode: this.getDeliveryMode(),
173
- };
174
- };
175
- VideoCapture.prototype.getDeliveryMode = function () {
176
- return this.videoEl instanceof HTMLAudioElement ? 'audio' : 'video';
177
- };
178
- VideoCapture.prototype.parseStopEventProperties = function (nextState) {
179
- var _a, _b, _c, _d, _e, _f, _g;
180
- return __assign(__assign({}, this.parseStartEventProperties(nextState)), {
181
- // lastEvent.start_time is the playhead at the time of the event, which for a stop event is
182
- // where playback ended, so the position captured when the play session began is preferred.
183
- 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) });
184
113
  };
185
114
  return VideoCapture;
186
115
  }());
187
116
  export { VideoCapture };
188
- function calculatePercentCompleted(currentTime, duration) {
189
- if (!Number.isFinite(currentTime) || !Number.isFinite(duration) || duration <= 0) {
190
- return 0;
191
- }
192
- return Math.min(100, Math.max(0, (currentTime / duration) * 100));
193
- }
194
117
  /**
195
- * 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.
196
119
  *
197
- * Captures [Amplitude] Content Started and [Amplitude] Content Stopped events.
120
+ * Captures Video Started and Video Stopped events.
198
121
  *
199
122
  * @experimental This function is experimental and may not be stable.
200
123
  * @param amplitude - The Amplitude client instance.
201
- * @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.
202
125
  * @param options - The options for the video capture.
203
126
  * @returns A function to stop the video capture.
204
127
  */
@@ -206,7 +129,7 @@ export function trackVideo(amplitude, videoEl, options) {
206
129
  var _a;
207
130
  if (options === void 0) { options = {}; }
208
131
  var videoCapture = new VideoCapture(amplitude);
209
- if (videoEl instanceof HTMLMediaElement) {
132
+ if (videoEl instanceof HTMLVideoElement) {
210
133
  videoCapture.withVideoElement(videoEl);
211
134
  }
212
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;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,IAAI,CAAC;QACnC,cAAS,GAAmE,EAAE,CAAC;QAC/E,sBAAiB,GAAmB,EAAE,CAAC;QACvC,WAAM,GAAkB,IAAI,CAAC;QAC7B,kBAAa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,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\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 ...nextState.lastEvent,\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 ...nextState.lastEvent,\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 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 };\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,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,GAAmB,EAAE,CAAC;IAES,CAAC;IAEzD;;;;;OAKG;IACH,uCAAgB,GAAhB,UAAiB,OAAyB;QACxC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACH,yCAAkB,GAAlB,UAAmB,MAA2B;QAC5C,IAAI,CAAC,mBAAmB,GAAG,MAAM,CAAC;QAClC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACH,iCAAU,GAAV,UAAW,MAAmB;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACH,+CAAwB,GAAxB,UAAyB,UAAqD;QAC5E,IAA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,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 r=e.amplitude||{_q:[],_iq:{}};if(r.invoked)e.console&&console.error&&console.error("Amplitude snippet has been loaded.");else{var n=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,r){return function(n){e._q.push({name:t,args:Array.prototype.slice.call(r,0),resolve:n})}},o=function(e,t,r){e[t]=function(){if(r)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 r=0;r<y.length;r++)o(e,y[r],!0)};r.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-ZSiwhdQGuqmtwOcmwBjS+FvNEXNzaQGdiwIo0iCkH7jAUCtMEPxpOqTxm0S7oO7Y",c.crossOrigin="anonymous",c.async=!1,c.src="https://cdn.amplitude.com/libs/analytics-browser-2.46.0-video-analytics-2.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++)n(p,l[d]);r.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++)n(m,g[v]);r.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(r),r.createInstance=function(e){return r._iq[e]={_q:[]},s(r._iq[e]),r._iq[e]},e.amplitude=r}}(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%20r%3De.amplitude%7C%7C%7B_q%3A%5B%5D%2C_iq%3A%7B%7D%7D%3Bif(r.invoked)e.console%26%26console.error%26%26console.error(%22Amplitude%20snippet%20has%20been%20loaded.%22)%3Belse%7Bvar%20n%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%2Cr)%7Breturn%20function(n)%7Be._q.push(%7Bname%3At%2Cargs%3AArray.prototype.slice.call(r%2C0)%2Cresolve%3An%7D)%7D%7D%2Co%3Dfunction(e%2Ct%2Cr)%7Be%5Bt%5D%3Dfunction()%7Bif(r)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%20r%3D0%3Br%3Cy.length%3Br%2B%2B)o(e%2Cy%5Br%5D%2C!0)%7D%3Br.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-ZSiwhdQGuqmtwOcmwBjS%2BFvNEXNzaQGdiwIo0iCkH7jAUCtMEPxpOqTxm0S7oO7Y%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-2.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)n(p%2Cl%5Bd%5D)%3Br.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)n(m%2Cg%5Bv%5D)%3Br.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(r)%2Cr.createInstance%3Dfunction(e)%7Breturn%20r._iq%5Be%5D%3D%7B_q%3A%5B%5D%7D%2Cs(r._iq%5Be%5D)%2Cr._iq%5Be%5D%7D%2Ce.amplitude%3Dr%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