@amplitude/analytics-browser 2.38.2-SR-3115-rc2.0 → 2.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/cjs/attribution/helpers.d.ts +3 -1
- package/lib/cjs/attribution/helpers.d.ts.map +1 -1
- package/lib/cjs/attribution/helpers.js.map +1 -1
- package/lib/cjs/attribution/tracking-methods.d.ts +12 -0
- package/lib/cjs/attribution/tracking-methods.d.ts.map +1 -0
- package/lib/cjs/attribution/tracking-methods.js +31 -0
- package/lib/cjs/attribution/tracking-methods.js.map +1 -0
- package/lib/cjs/browser-client.d.ts.map +1 -1
- package/lib/cjs/browser-client.js +36 -25
- package/lib/cjs/browser-client.js.map +1 -1
- package/lib/cjs/config/joined-config.d.ts.map +1 -1
- package/lib/cjs/config/joined-config.js +5 -1
- package/lib/cjs/config/joined-config.js.map +1 -1
- package/lib/cjs/config.d.ts +1 -1
- package/lib/cjs/config.d.ts.map +1 -1
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +3 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.d.ts.map +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/cjs/version.js.map +1 -1
- package/lib/cjs/video-capture/video-capture.d.ts +72 -0
- package/lib/cjs/video-capture/video-capture.d.ts.map +1 -0
- package/lib/cjs/video-capture/video-capture.js +152 -0
- package/lib/cjs/video-capture/video-capture.js.map +1 -0
- package/lib/esm/attribution/helpers.d.ts +3 -1
- package/lib/esm/attribution/helpers.d.ts.map +1 -1
- package/lib/esm/attribution/helpers.js.map +1 -1
- package/lib/esm/attribution/tracking-methods.d.ts +12 -0
- package/lib/esm/attribution/tracking-methods.d.ts.map +1 -0
- package/lib/esm/attribution/tracking-methods.js +24 -0
- package/lib/esm/attribution/tracking-methods.js.map +1 -0
- package/lib/esm/browser-client.d.ts.map +1 -1
- package/lib/esm/browser-client.js +36 -25
- package/lib/esm/browser-client.js.map +1 -1
- package/lib/esm/config/joined-config.d.ts.map +1 -1
- package/lib/esm/config/joined-config.js +5 -1
- package/lib/esm/config/joined-config.js.map +1 -1
- package/lib/esm/config.d.ts +1 -1
- package/lib/esm/config.d.ts.map +1 -1
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.d.ts.map +1 -1
- package/lib/esm/index.js +1 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.d.ts.map +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/esm/version.js.map +1 -1
- package/lib/esm/video-capture/video-capture.d.ts +72 -0
- package/lib/esm/video-capture/video-capture.d.ts.map +1 -0
- package/lib/esm/video-capture/video-capture.js +148 -0
- package/lib/esm/video-capture/video-capture.js.map +1 -0
- package/lib/scripts/amplitude-bookmarklet-snippet-min.js +1 -1
- package/lib/scripts/amplitude-bookmarklet.html +1 -1
- package/lib/scripts/amplitude-gtm-min.js +1 -1
- package/lib/scripts/amplitude-gtm-min.js.gz +0 -0
- package/lib/scripts/amplitude-gtm-min.js.map +1 -1
- package/lib/scripts/amplitude-gtm-snippet-min.js +1 -1
- package/lib/scripts/amplitude-min.js +1 -1
- package/lib/scripts/amplitude-min.js.gz +0 -0
- package/lib/scripts/amplitude-min.js.map +1 -1
- package/lib/scripts/amplitude-min.umd.js +1 -1
- package/lib/scripts/amplitude-min.umd.js.gz +0 -0
- package/lib/scripts/amplitude-snippet-instructions.html +1 -1
- package/lib/scripts/amplitude-snippet-min.js +1 -1
- package/lib/scripts/attribution/helpers.d.ts +3 -1
- package/lib/scripts/attribution/helpers.d.ts.map +1 -1
- package/lib/scripts/attribution/tracking-methods.d.ts +12 -0
- package/lib/scripts/attribution/tracking-methods.d.ts.map +1 -0
- package/lib/scripts/browser-client.d.ts.map +1 -1
- package/lib/scripts/config/joined-config.d.ts.map +1 -1
- package/lib/scripts/config.d.ts +1 -1
- package/lib/scripts/config.d.ts.map +1 -1
- package/lib/scripts/index.d.ts +1 -0
- package/lib/scripts/index.d.ts.map +1 -1
- package/lib/scripts/version.d.ts +1 -1
- package/lib/scripts/version.d.ts.map +1 -1
- package/lib/scripts/video-capture/video-capture.d.ts +72 -0
- package/lib/scripts/video-capture/video-capture.d.ts.map +1 -0
- package/package.json +9 -8
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { BrowserClient, EmbeddedVideoPlayer, VideoVendor } from '@amplitude/analytics-core';
|
|
2
|
+
export declare class VideoCapture {
|
|
3
|
+
private readonly amplitude;
|
|
4
|
+
private videoEl;
|
|
5
|
+
private embeddedVideoPlayer;
|
|
6
|
+
private vendor?;
|
|
7
|
+
private extraEventProperties;
|
|
8
|
+
private listeners;
|
|
9
|
+
private onRemoveListeners;
|
|
10
|
+
constructor(amplitude: BrowserClient);
|
|
11
|
+
/**
|
|
12
|
+
* Specify a video element to capture events from
|
|
13
|
+
*
|
|
14
|
+
* @param videoEl - The HTML video element to capture events from.
|
|
15
|
+
* @returns The VideoCapture instance.
|
|
16
|
+
*/
|
|
17
|
+
withVideoElement(videoEl: HTMLVideoElement): VideoCapture;
|
|
18
|
+
/**
|
|
19
|
+
* Specify an embedded video player.js instance to capture events from
|
|
20
|
+
* @param player - The embedded video player.js instance to capture events from.
|
|
21
|
+
* @returns The VideoCapture instance.
|
|
22
|
+
*/
|
|
23
|
+
withEmbeddedPlayer(player: EmbeddedVideoPlayer): VideoCapture;
|
|
24
|
+
/**
|
|
25
|
+
* Specify a vendor to capture extra vendor-specific event properties
|
|
26
|
+
*
|
|
27
|
+
* @param vendor - The vendor of the video player. Currently only "mux" is supported.
|
|
28
|
+
* @returns The VideoCapture instance.
|
|
29
|
+
*/
|
|
30
|
+
withVendor(vendor: VideoVendor): VideoCapture;
|
|
31
|
+
/**
|
|
32
|
+
* Specify extra event properties to include in all captured events
|
|
33
|
+
*
|
|
34
|
+
* @param properties - The extra event properties to include in the Amplitude event.
|
|
35
|
+
* @returns The VideoCapture instance.
|
|
36
|
+
*/
|
|
37
|
+
withExtraEventProperties(properties: Record<string, string | number | boolean>): VideoCapture;
|
|
38
|
+
/**
|
|
39
|
+
* Track a "Video Content Started" event every time the video starts playing
|
|
40
|
+
* @returns The VideoCapture instance.
|
|
41
|
+
*/
|
|
42
|
+
captureVideoStarted(): VideoCapture;
|
|
43
|
+
/**
|
|
44
|
+
* Track a "Video Content Stopped" event every time the video stops playing
|
|
45
|
+
* @returns The VideoCapture instance.
|
|
46
|
+
*/
|
|
47
|
+
captureVideoStopped(): VideoCapture;
|
|
48
|
+
/**
|
|
49
|
+
* Start capturing analytics events for the video element
|
|
50
|
+
* @returns The VideoCapture instance.
|
|
51
|
+
* @throws An error if the video element is not specified.
|
|
52
|
+
*/
|
|
53
|
+
start(): VideoCapture;
|
|
54
|
+
stop(): void;
|
|
55
|
+
}
|
|
56
|
+
export type VideoCaptureOptions = {
|
|
57
|
+
vendor?: VideoVendor;
|
|
58
|
+
extraEventProperties?: Record<string, string | number | boolean>;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Track video analytics events for an HTML video element or embedded video player.js instance.
|
|
62
|
+
*
|
|
63
|
+
* Captures Video Started and Video Stopped events.
|
|
64
|
+
*
|
|
65
|
+
* @experimental This function is experimental and may not be stable.
|
|
66
|
+
* @param amplitude - The Amplitude client instance.
|
|
67
|
+
* @param videoEl - The HTML video element or embedded video player.js instance to capture events from.
|
|
68
|
+
* @param options - The options for the video capture.
|
|
69
|
+
* @returns A function to stop the video capture.
|
|
70
|
+
*/
|
|
71
|
+
export declare function trackVideo(amplitude: BrowserClient, videoEl: HTMLVideoElement | EmbeddedVideoPlayer, options?: VideoCaptureOptions): () => void;
|
|
72
|
+
//# sourceMappingURL=video-capture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"video-capture.d.ts","sourceRoot":"","sources":["../../../src/video-capture/video-capture.ts"],"names":[],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
|
+
import { VideoObserver } from '@amplitude/analytics-core';
|
|
3
|
+
var VideoCapture = /** @class */ (function () {
|
|
4
|
+
function VideoCapture(amplitude) {
|
|
5
|
+
this.amplitude = amplitude;
|
|
6
|
+
this.videoEl = null;
|
|
7
|
+
this.embeddedVideoPlayer = null;
|
|
8
|
+
this.extraEventProperties = {};
|
|
9
|
+
this.listeners = [];
|
|
10
|
+
this.onRemoveListeners = [];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Specify a video element to capture events from
|
|
14
|
+
*
|
|
15
|
+
* @param videoEl - The HTML video element to capture events from.
|
|
16
|
+
* @returns The VideoCapture instance.
|
|
17
|
+
*/
|
|
18
|
+
VideoCapture.prototype.withVideoElement = function (videoEl) {
|
|
19
|
+
this.videoEl = videoEl;
|
|
20
|
+
return this;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Specify an embedded video player.js instance to capture events from
|
|
24
|
+
* @param player - The embedded video player.js instance to capture events from.
|
|
25
|
+
* @returns The VideoCapture instance.
|
|
26
|
+
*/
|
|
27
|
+
VideoCapture.prototype.withEmbeddedPlayer = function (player) {
|
|
28
|
+
this.embeddedVideoPlayer = player;
|
|
29
|
+
return this;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Specify a vendor to capture extra vendor-specific event properties
|
|
33
|
+
*
|
|
34
|
+
* @param vendor - The vendor of the video player. Currently only "mux" is supported.
|
|
35
|
+
* @returns The VideoCapture instance.
|
|
36
|
+
*/
|
|
37
|
+
VideoCapture.prototype.withVendor = function (vendor) {
|
|
38
|
+
this.vendor = vendor;
|
|
39
|
+
return this;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Specify extra event properties to include in all captured events
|
|
43
|
+
*
|
|
44
|
+
* @param properties - The extra event properties to include in the Amplitude event.
|
|
45
|
+
* @returns The VideoCapture instance.
|
|
46
|
+
*/
|
|
47
|
+
VideoCapture.prototype.withExtraEventProperties = function (properties) {
|
|
48
|
+
this.extraEventProperties = properties;
|
|
49
|
+
return this;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Track a "Video Content Started" event every time the video starts playing
|
|
53
|
+
* @returns The VideoCapture instance.
|
|
54
|
+
*/
|
|
55
|
+
VideoCapture.prototype.captureVideoStarted = function () {
|
|
56
|
+
var _this = this;
|
|
57
|
+
this.listeners.push(function (previousState, nextState) {
|
|
58
|
+
if (previousState.playbackState !== 'playing' && nextState.playbackState === 'playing') {
|
|
59
|
+
// placeholder for Heartbeat Start Event
|
|
60
|
+
_this.amplitude.track('Video Content Started', __assign(__assign({}, nextState.lastEvent), _this.extraEventProperties));
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return this;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Track a "Video Content Stopped" event every time the video stops playing
|
|
67
|
+
* @returns The VideoCapture instance.
|
|
68
|
+
*/
|
|
69
|
+
VideoCapture.prototype.captureVideoStopped = function () {
|
|
70
|
+
var _this = this;
|
|
71
|
+
this.listeners.push(function (previousState, nextState) {
|
|
72
|
+
if (previousState.playbackState === 'playing' && nextState.playbackState !== 'playing') {
|
|
73
|
+
// placeholder for Heartbeat Stop Event
|
|
74
|
+
_this.amplitude.track('Video Content Stopped', __assign(__assign(__assign({}, nextState.lastEvent), { watch_duration: nextState.watchTime }), _this.extraEventProperties));
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
return this;
|
|
78
|
+
};
|
|
79
|
+
// Placeholder: may need a generic state change listener to capture unusual events or to have
|
|
80
|
+
// more control over the event tracking.
|
|
81
|
+
// withStateChangeListener(listener: (previousState: VideoState, nextState: VideoState) => void): VideoCapture {
|
|
82
|
+
/**
|
|
83
|
+
* Start capturing analytics events for the video element
|
|
84
|
+
* @returns The VideoCapture instance.
|
|
85
|
+
* @throws An error if the video element is not specified.
|
|
86
|
+
*/
|
|
87
|
+
VideoCapture.prototype.start = function () {
|
|
88
|
+
var _this = this;
|
|
89
|
+
var _a;
|
|
90
|
+
var videoEl = (_a = this.videoEl) !== null && _a !== void 0 ? _a : this.embeddedVideoPlayer;
|
|
91
|
+
if (!videoEl) {
|
|
92
|
+
throw new Error('Video element not specified. Use withVideoElement() or withEmbeddedPlayer() to specify the video element.');
|
|
93
|
+
}
|
|
94
|
+
if (this.videoEl && this.embeddedVideoPlayer) {
|
|
95
|
+
throw new Error('Both video element and embedded video player specified. Use only one of withVideoElement() or withEmbeddedPlayer() to specify the video element.');
|
|
96
|
+
}
|
|
97
|
+
var videoObserver = new VideoObserver({
|
|
98
|
+
videoEl: videoEl,
|
|
99
|
+
onStateChange: function (previousState, nextState) {
|
|
100
|
+
_this.listeners.forEach(function (listener) { return listener(previousState, nextState); });
|
|
101
|
+
},
|
|
102
|
+
vendor: this.vendor,
|
|
103
|
+
isEmbedded: !!this.embeddedVideoPlayer,
|
|
104
|
+
});
|
|
105
|
+
this.onRemoveListeners.push(function () {
|
|
106
|
+
videoObserver.destroy();
|
|
107
|
+
});
|
|
108
|
+
return this;
|
|
109
|
+
};
|
|
110
|
+
VideoCapture.prototype.stop = function () {
|
|
111
|
+
this.onRemoveListeners.forEach(function (listener) { return listener(); });
|
|
112
|
+
this.onRemoveListeners = [];
|
|
113
|
+
};
|
|
114
|
+
return VideoCapture;
|
|
115
|
+
}());
|
|
116
|
+
export { VideoCapture };
|
|
117
|
+
/**
|
|
118
|
+
* Track video analytics events for an HTML video element or embedded video player.js instance.
|
|
119
|
+
*
|
|
120
|
+
* Captures Video Started and Video Stopped events.
|
|
121
|
+
*
|
|
122
|
+
* @experimental This function is experimental and may not be stable.
|
|
123
|
+
* @param amplitude - The Amplitude client instance.
|
|
124
|
+
* @param videoEl - The HTML video element or embedded video player.js instance to capture events from.
|
|
125
|
+
* @param options - The options for the video capture.
|
|
126
|
+
* @returns A function to stop the video capture.
|
|
127
|
+
*/
|
|
128
|
+
export function trackVideo(amplitude, videoEl, options) {
|
|
129
|
+
var _a;
|
|
130
|
+
if (options === void 0) { options = {}; }
|
|
131
|
+
var videoCapture = new VideoCapture(amplitude);
|
|
132
|
+
if (videoEl instanceof HTMLVideoElement) {
|
|
133
|
+
videoCapture.withVideoElement(videoEl);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
videoCapture.withEmbeddedPlayer(videoEl);
|
|
137
|
+
}
|
|
138
|
+
if (options.vendor) {
|
|
139
|
+
videoCapture.withVendor(options.vendor);
|
|
140
|
+
}
|
|
141
|
+
videoCapture
|
|
142
|
+
.withExtraEventProperties((_a = options.extraEventProperties) !== null && _a !== void 0 ? _a : {})
|
|
143
|
+
.captureVideoStarted()
|
|
144
|
+
.captureVideoStopped()
|
|
145
|
+
.start();
|
|
146
|
+
return function () { return videoCapture.stop(); };
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=video-capture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"video-capture.js","sourceRoot":"","sources":["../../../src/video-capture/video-capture.ts"],"names":[],"mappings":";AAAA,OAAO,EAAc,aAAa,EAAmD,MAAM,2BAA2B,CAAC;AAEvH;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,CAA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,MAAM,EAAE;QAClB,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;KACzC;IACD,YAAY;SACT,wBAAwB,CAAC,MAAA,OAAO,CAAC,oBAAoB,mCAAI,EAAE,CAAC;SAC5D,mBAAmB,EAAE;SACrB,mBAAmB,EAAE;SACrB,KAAK,EAAE,CAAC;IAEX,OAAO,cAAM,OAAA,YAAY,CAAC,IAAI,EAAE,EAAnB,CAAmB,CAAC;AACnC,CAAC","sourcesContent":["import { VideoState, VideoObserver, BrowserClient, EmbeddedVideoPlayer, VideoVendor } 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 // 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\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): () => void {\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 videoCapture\n .withExtraEventProperties(options.extraEventProperties ?? {})\n .captureVideoStarted()\n .captureVideoStopped()\n .start();\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<
|
|
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<v.length;t++)o(e,v[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-4O8lKNFNgd/jP8qyPyPo+hGxkbqZ9dQ/DUufAi9GWr0ZryDdHu+46n/uC5ZmwffP",c.crossOrigin="anonymous",c.async=!1,c.src="https://cdn.amplitude.com/libs/analytics-browser-2.40.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&&litudeAutocapturePlugin.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"],f=0;f<g.length;f++)n(m,g[f]);r.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(r),r.createInstance=function(e){return r._iq[e]={_q:[]},s(r._iq[e]),r._iq[e]},e.amplitude=r}}(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%
|
|
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%3Cv.length%3Bt%2B%2B)o(e%2Cv%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-4O8lKNFNgd%2FjP8qyPyPo%2BhGxkbqZ9dQ%2FDUufAi9GWr0ZryDdHu%2B46n%2FuC5ZmwffP%22%2Cc.crossOrigin%3D%22anonymous%22%2Cc.async%3D!1%2Cc.src%3D%22https%3A%2F%2Fcdn.amplitude.com%2Flibs%2Fanalytics-browser-2.40.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%2Cf%3D0%3Bf%3Cg.length%3Bf%2B%2B)n(m%2Cg%5Bf%5D)%3Br.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(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
|