@amplitude/analytics-browser 2.46.0-video-analytics-4.0 → 2.47.0-video-analytics-5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/cjs/config.d.ts +1 -1
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/cjs/version.js.map +1 -1
- package/lib/cjs/video-capture/video-capture.js +6 -6
- package/lib/cjs/video-capture/video-capture.js.map +1 -1
- package/lib/esm/config.d.ts +1 -1
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/esm/version.js.map +1 -1
- package/lib/esm/video-capture/video-capture.js +6 -6
- package/lib/esm/video-capture/video-capture.js.map +1 -1
- 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/config.d.ts +1 -1
- package/lib/scripts/version.d.ts +1 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ This SDK is also available through CDN. Copy the script loader below and paste b
|
|
|
53
53
|
<!-- README_SNIPPET_BLOCK -->
|
|
54
54
|
```html
|
|
55
55
|
<script type="text/javascript">
|
|
56
|
-
!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}},s=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(s(e,t,Array.prototype.slice.call(arguments)))};!function(e,t,r){e._q.push({name:t,args:Array.prototype.slice.call(r,0)})}(e,t,Array.prototype.slice.call(arguments))}},i=function(e){for(var t=0;t<y.length;t++)o(e,y[t],!1);for(var r=0;r<
|
|
56
|
+
!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}},s=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(s(e,t,Array.prototype.slice.call(arguments)))};!function(e,t,r){e._q.push({name:t,args:Array.prototype.slice.call(r,0)})}(e,t,Array.prototype.slice.call(arguments))}},i=function(e){for(var t=0;t<y.length;t++)o(e,y[t],!1);for(var r=0;r<g.length;r++)o(e,g[r],!0)};r.invoked=!0;var c=t.createElement("script");c.type="text/javascript",c.integrity="sha384-gt3Pvso3avjAL5mGN9NcOGKwcy+bj20O840b2Lc/uhLu77g9UK2KXDLnlsUezUcK",c.crossOrigin="anonymous",c.async=!0,c.src="https://cdn.amplitude.com/libs/analytics-browser-2.47.0-video-analytics-5.0-min.js.gz",c.onload=function(){e.amplitude.runQueuedFunctions||console.log("[Amplitude] Error: could not load SDK")};var a=t.getElementsByTagName("script")[0];a.parentNode.insertBefore(c,a);for(var u=function(){return this._q=[],this},l=["add","append","clearAll","prepend","set","setOnce","unset","preInsert","postInsert","remove","getUserProperties"],p=0;p<l.length;p++)n(u,l[p]);r.Identify=u;for(var d=function(){return this._q=[],this},v=["getEventProperties","setProductId","setQuantity","setPrice","setRevenue","setRevenueType","setReceipt","setReceiptSig","setCurrency","setEventProperties"],f=0;f<v.length;f++)n(d,v[f]);r.Revenue=d;var y=["getDeviceId","setDeviceId","getSessionId","setSessionId","getUserId","setUserId","setOptOut","setTransport","reset","extendSession"],g=["init","add","remove","track","logEvent","identify","groupIdentify","setGroup","revenue","flush"];i(r),r.createInstance=function(e){return r._iq[e]={_q:[]},i(r._iq[e]),r._iq[e]},e.amplitude=r}}(window,document)}();
|
|
57
57
|
|
|
58
58
|
amplitude.init("<YOUR_API_KEY>");
|
|
59
59
|
</script>
|
package/lib/cjs/config.d.ts
CHANGED
|
@@ -46,7 +46,7 @@ export declare class BrowserConfig extends Config implements IBrowserConfig {
|
|
|
46
46
|
enableRequestBodyCompression: boolean;
|
|
47
47
|
customEnrichment?: boolean | CustomEnrichmentOptions | undefined;
|
|
48
48
|
delayedEventsServerUrl?: string | undefined;
|
|
49
|
-
readonly version = "2.
|
|
49
|
+
readonly version = "2.47.0-video-analytics-5.0";
|
|
50
50
|
protected _cookieStorage: Storage<UserSession>;
|
|
51
51
|
protected _deviceId?: string;
|
|
52
52
|
protected _lastEventId?: number;
|
package/lib/cjs/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "2.
|
|
1
|
+
export declare const VERSION = "2.47.0-video-analytics-5.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/lib/cjs/version.js
CHANGED
package/lib/cjs/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,4BAA4B,CAAC","sourcesContent":["export const VERSION = '2.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,4BAA4B,CAAC","sourcesContent":["export const VERSION = '2.47.0-video-analytics-5.0';\n"]}
|
|
@@ -7,11 +7,11 @@ var constants_1 = require("../constants");
|
|
|
7
7
|
/** Playback states where a view session is still in progress (e.g. buffering). */
|
|
8
8
|
var ACTIVE_PLAYBACK_STATES = new Set(['playing', 'waiting']);
|
|
9
9
|
/**
|
|
10
|
-
* Observer fields that never reach event properties
|
|
11
|
-
* and `percent_completed`/`stop_reason` describe the player event rather
|
|
12
|
-
* which tracks its own values.
|
|
10
|
+
* Observer fields that never reach event properties from `lastEvent`: `position` is taken from
|
|
11
|
+
* observer state instead, and `percent_completed`/`stop_reason` describe the player event rather
|
|
12
|
+
* than the play session, which tracks its own values.
|
|
13
13
|
*/
|
|
14
|
-
var OMITTED_VIDEO_EVENT_PROPERTIES = new Set(['
|
|
14
|
+
var OMITTED_VIDEO_EVENT_PROPERTIES = new Set(['position', 'percent_completed', 'stop_reason']);
|
|
15
15
|
/**
|
|
16
16
|
* Copy remaining player-event fields (vendor metadata such as `mux_playback_id`, ids, titles)
|
|
17
17
|
* onto the Amplitude event, dropping empty values so absent metadata is omitted.
|
|
@@ -209,7 +209,7 @@ var VideoCapture = /** @class */ (function () {
|
|
|
209
209
|
return tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, this.parseStartEventProperties(nextState)), {
|
|
210
210
|
// lastEvent.start_time is the playhead at the time of the event, which for a stop event is
|
|
211
211
|
// where playback ended, so the position captured when the play session began is preferred.
|
|
212
|
-
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,
|
|
212
|
+
start_time: (_c = (_a = this.playStartTime) !== null && _a !== void 0 ? _a : (_b = nextState.lastEvent) === null || _b === void 0 ? void 0 : _b.start_time) !== null && _c !== void 0 ? _c : 0, stream_duration: (_d = nextState.watchTime) !== null && _d !== void 0 ? _d : 0, percent_completed: calculatePercentCompleted((_e = nextState.position) !== null && _e !== void 0 ? _e : 0, (_g = (_f = nextState.lastEvent) === null || _f === void 0 ? void 0 : _f.duration) !== null && _g !== void 0 ? _g : 0) }), (nextState.errorMessage ? { error_message: nextState.errorMessage } : {}));
|
|
213
213
|
};
|
|
214
214
|
return VideoCapture;
|
|
215
215
|
}());
|
|
@@ -247,7 +247,7 @@ function trackVideo(amplitude, videoEl, options) {
|
|
|
247
247
|
var extraEventProperties = (_a = options.extraEventProperties) !== null && _a !== void 0 ? _a : {};
|
|
248
248
|
try {
|
|
249
249
|
videoCapture
|
|
250
|
-
.withExtraEventProperties(tslib_1.__assign({
|
|
250
|
+
.withExtraEventProperties(tslib_1.__assign({ stream_session_id: (0, analytics_core_1.UUID)() }, extraEventProperties))
|
|
251
251
|
.captureVideoStarted()
|
|
252
252
|
.captureVideoStopped()
|
|
253
253
|
.start();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"video-capture.js","sourceRoot":"","sources":["../../../src/video-capture/video-capture.ts"],"names":[],"mappings":";;;;AAAA,4DASmC;AACnC,0CAA4F;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,iBAAA,MAAM,CAAC,OAAO,CAAC,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,EAAE,CAAC,CAAA,gBAAA,4BAAE;YAAjD,IAAA,KAAA,2BAAY,EAAX,GAAG,QAAA,EAAE,KAAK,QAAA;YACpB,IAAI,8BAA8B,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,KAAK,KAAK,IAAI,IAAI,KAA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AE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,WAAW,GAAG,QAAQ,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;AACpE,CAAC;AAWD;;;;;;;;;;GAUG;AACH,SAAgB,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,oBACvB,eAAe,EAAE,IAAA,qBAAI,GAAE,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;AA9BD,gCA8BC","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,4DASmC;AACnC,0CAA4F;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,UAAU,EAAE,mBAAmB,EAAE,aAAa,CAAC,CAAC,CAAC;AAEjG;;;GAGG;AACH,SAAS,yBAAyB,CAAC,SAAkC;;IACnE,IAAM,UAAU,GAA8C,EAAE,CAAC;;QACjE,KAA2B,IAAA,KAAA,iBAAA,MAAM,CAAC,OAAO,CAAC,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,EAAE,CAAC,CAAA,gBAAA,4BAAE;YAAjD,IAAA,KAAA,2BAAY,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,wB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,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,oBACvB,iBAAiB,EAAE,IAAA,qBAAI,GAAE,IACtB,oBAAoB,EACvB;aACD,mBAAmB,EAAE;aACrB,mBAAmB,EAAE;aACrB,KAAK,EAAE,CAAC;KACZ;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,KAAc,CAAC;KACvB;IAED,OAAO,cAAM,OAAA,YAAY,CAAC,IAAI,EAAE,EAAnB,CAAmB,CAAC;AACnC,CAAC;AA9BD,gCA8BC","sourcesContent":["import {\n VideoState,\n VideoObserver,\n BrowserClient,\n EmbeddedVideoPlayer,\n VideoVendor,\n UUID,\n BaseEvent,\n getHeartbeatInstance,\n} from '@amplitude/analytics-core';\nimport { DEFAULT_CONTENT_STARTED_EVENT, DEFAULT_CONTENT_STOPPED_EVENT } from '../constants';\n\n/** Playback states where a view session is still in progress (e.g. buffering). */\nconst ACTIVE_PLAYBACK_STATES = new Set<VideoState['playbackState']>(['playing', 'waiting']);\n\n/**\n * Observer fields that never reach event properties from `lastEvent`: `position` is taken from\n * observer state instead, and `percent_completed`/`stop_reason` describe the player event rather\n * than the play session, which tracks its own values.\n */\nconst OMITTED_VIDEO_EVENT_PROPERTIES = new Set(['position', 'percent_completed', 'stop_reason']);\n\n/**\n * Copy remaining player-event fields (vendor metadata such as `mux_playback_id`, ids, titles)\n * onto the Amplitude event, dropping empty values so absent metadata is omitted.\n */\nfunction parseVideoEventProperties(lastEvent: VideoState['lastEvent']): Record<string, string | number | boolean> {\n const properties: Record<string, string | number | boolean> = {};\n for (const [key, value] of Object.entries(lastEvent ?? {})) {\n if (OMITTED_VIDEO_EVENT_PROPERTIES.has(key) || value === null || value === undefined) {\n continue;\n }\n properties[key] = value as string | number | boolean;\n }\n return properties;\n}\n\nexport class VideoCapture {\n private videoEl: HTMLMediaElement | null = null;\n private heartbeat: ReturnType<typeof getHeartbeatInstance>;\n private embeddedVideoPlayer: EmbeddedVideoPlayer | null = null;\n private vendor?: VideoVendor;\n private extraEventProperties: Record<string, string | number | boolean> = {};\n private stopEvent: BaseEvent | null = null;\n private listeners: ((previousState: VideoState, nextState: VideoState) => void)[] = [];\n private onRemoveListeners: (() => void)[] = [];\n private playId: string | null = null;\n private playStartTime: number | null = null;\n\n constructor(private readonly amplitude: BrowserClient) {\n this.heartbeat = getHeartbeatInstance(this.amplitude);\n }\n\n /**\n * Specify a video or audio element to capture events from\n *\n * @param videoEl - The HTML video or audio element to capture events from.\n * @returns The VideoCapture instance.\n */\n withVideoElement(videoEl: HTMLMediaElement): VideoCapture {\n this.videoEl = videoEl;\n return this;\n }\n\n /**\n * Specify an embedded video player.js instance to capture events from\n * @param player - The embedded video player.js instance to capture events from.\n * @returns The VideoCapture instance.\n */\n withEmbeddedPlayer(player: EmbeddedVideoPlayer): VideoCapture {\n this.embeddedVideoPlayer = player;\n return this;\n }\n\n /**\n * Specify a vendor to capture extra vendor-specific event properties\n *\n * @param vendor - The vendor of the video player. Currently only \"mux\" is supported.\n * @returns The VideoCapture instance.\n */\n withVendor(vendor: VideoVendor): VideoCapture {\n this.vendor = vendor;\n return this;\n }\n\n /**\n * Specify extra event properties to include in all captured events\n *\n * @param properties - The extra event properties to include in the Amplitude event.\n * @returns The VideoCapture instance.\n */\n withExtraEventProperties(properties: Record<string, string | number | boolean>): VideoCapture {\n this.extraEventProperties = properties;\n return this;\n }\n\n /**\n * Track a \"[Amplitude] Content Started\" event every time the video starts playing\n * @returns The VideoCapture instance.\n */\n captureVideoStarted(): VideoCapture {\n this.listeners.push((previousState, nextState) => {\n if (!ACTIVE_PLAYBACK_STATES.has(previousState.playbackState) && nextState.playbackState === 'playing') {\n this.playId = UUID();\n /* istanbul ignore next */\n this.playStartTime = nextState.lastEvent?.start_time ?? 0;\n const now = new Date().getTime();\n const startEvent: BaseEvent = {\n insert_id: UUID(),\n event_type: DEFAULT_CONTENT_STARTED_EVENT,\n time: now,\n event_properties: {\n ...this.parseStartEventProperties(nextState),\n ...this.extraEventProperties,\n play_id: this.playId,\n },\n };\n this.stopEvent = {\n ...startEvent,\n insert_id: UUID(),\n event_type: DEFAULT_CONTENT_STOPPED_EVENT,\n time: now + 1,\n event_properties: {\n ...this.parseStopEventProperties(nextState),\n ...this.extraEventProperties,\n stop_reason: 'timeout',\n play_id: this.playId,\n },\n };\n this.heartbeat.trackNoDelay(startEvent).catch(this.stop.bind(this));\n this.heartbeat.track(this.stopEvent).catch(this.stop.bind(this));\n }\n });\n return this;\n }\n\n /**\n * Track a \"[Amplitude] Content Stopped\" event every time the video stops playing\n * @returns The VideoCapture instance.\n */\n captureVideoStopped(): VideoCapture {\n this.listeners.push((previousState, nextState) => {\n // update the delayed event properties to have\n // the most up-to-date values\n if (this.stopEvent) {\n this.stopEvent.event_properties = {\n ...this.stopEvent.event_properties,\n ...this.parseStopEventProperties(nextState),\n ...this.extraEventProperties,\n };\n this.stopEvent.time = new Date().getTime();\n void this.heartbeat.update(this.stopEvent);\n }\n if (\n ACTIVE_PLAYBACK_STATES.has(previousState.playbackState) &&\n !ACTIVE_PLAYBACK_STATES.has(nextState.playbackState)\n ) {\n this.flushStopEvent(nextState.playbackState);\n }\n });\n return this;\n }\n\n /**\n * End the current play session by ingesting its queued delayed stop event immediately.\n *\n * The heartbeat is shared by every capture on the same Amplitude client, so the event is\n * flushed rather than the heartbeat stopped, which would discard other captures' events.\n * Flushing also drops the event from the heartbeat queue once ingested, so the interval\n * winds down on its own. No-op when no play session is in progress.\n */\n private flushStopEvent(stopReason: string) {\n const stopEvent = this.stopEvent;\n if (!stopEvent) {\n return;\n }\n // the next play queues a fresh delayed stop event\n this.stopEvent = null;\n this.playStartTime = null;\n stopEvent.event_properties = {\n ...stopEvent.event_properties,\n stop_reason: stopReason,\n };\n this.heartbeat.trackNoDelay(stopEvent).catch(this.stop.bind(this));\n }\n\n // Placeholder: may need a generic state change listener to capture unusual events or to have\n // more control over the event tracking.\n // withStateChangeListener(listener: (previousState: VideoState, nextState: VideoState) => void): VideoCapture {\n\n /**\n * Start capturing analytics events for the video element\n * @returns The VideoCapture instance.\n * @throws An error if the video element is not specified.\n */\n start(): VideoCapture {\n const videoEl = this.videoEl ?? this.embeddedVideoPlayer;\n if (!videoEl) {\n throw new Error(\n 'Video element not specified. Use withVideoElement() or withEmbeddedPlayer() to specify the video element.',\n );\n }\n if (this.videoEl && this.embeddedVideoPlayer) {\n throw new Error(\n 'Both video element and embedded video player specified. Use only one of withVideoElement() or withEmbeddedPlayer() to specify the video element.',\n );\n }\n const videoObserver = new VideoObserver({\n videoEl,\n onStateChange: (previousState, nextState) => {\n this.listeners.forEach((listener) => listener(previousState, nextState));\n },\n vendor: this.vendor,\n isEmbedded: !!this.embeddedVideoPlayer,\n });\n\n this.onRemoveListeners.push(() => {\n videoObserver.destroy();\n });\n return this;\n }\n\n /**\n * Stop capturing analytics events for the video element.\n *\n * Observers are detached first so no playback state change can race with the final\n * event, then any in-progress play session is closed out.\n */\n stop() {\n this.onRemoveListeners.forEach((listener) => listener());\n this.onRemoveListeners = [];\n this.flushStopEvent('untracked');\n }\n\n parseStartEventProperties(nextState: VideoState): Record<string, string | number | boolean> {\n return {\n ...parseVideoEventProperties(nextState.lastEvent),\n duration: nextState.lastEvent?.duration ?? 0,\n start_time: nextState.lastEvent?.start_time ?? 0,\n position: nextState.position ?? 0,\n delivery_mode: this.getDeliveryMode(),\n };\n }\n\n private getDeliveryMode(): 'video' | 'audio' {\n return this.videoEl instanceof HTMLAudioElement ? 'audio' : 'video';\n }\n\n parseStopEventProperties(nextState: VideoState): Record<string, string | number | boolean> {\n return {\n ...this.parseStartEventProperties(nextState),\n // lastEvent.start_time is the playhead at the time of the event, which for a stop event is\n // where playback ended, so the position captured when the play session began is preferred.\n start_time: this.playStartTime ?? nextState.lastEvent?.start_time ?? 0,\n stream_duration: nextState.watchTime ?? 0,\n percent_completed: calculatePercentCompleted(nextState.position ?? 0, nextState.lastEvent?.duration ?? 0),\n ...(nextState.errorMessage ? { error_message: nextState.errorMessage } : {}),\n };\n }\n}\n\nfunction calculatePercentCompleted(currentTime: number, duration: number) {\n if (!Number.isFinite(currentTime) || !Number.isFinite(duration) || duration <= 0) {\n return 0;\n }\n return Math.min(100, Math.max(0, (currentTime / duration) * 100));\n}\n\nexport type VideoCaptureOptions = {\n vendor?: VideoVendor;\n extraEventProperties?: Record<string, string | number | boolean>;\n};\n\ntype UntrackVideoResult = () => void;\n\nexport type TrackVideoResult = UntrackVideoResult | Error;\n\n/**\n * Track video analytics events for an HTML video or audio element or embedded video player.js instance.\n *\n * Captures [Amplitude] Content Started and [Amplitude] Content Stopped events.\n *\n * @experimental This function is experimental and may not be stable.\n * @param amplitude - The Amplitude client instance.\n * @param videoEl - The HTML video or audio element or embedded video player.js instance to capture events from.\n * @param options - The options for the video capture.\n * @returns A function to stop the video capture.\n */\nexport function trackVideo(\n amplitude: BrowserClient,\n videoEl: HTMLMediaElement | EmbeddedVideoPlayer,\n options: VideoCaptureOptions = {},\n): TrackVideoResult {\n const videoCapture = new VideoCapture(amplitude);\n if (videoEl instanceof HTMLMediaElement) {\n videoCapture.withVideoElement(videoEl);\n } else {\n videoCapture.withEmbeddedPlayer(videoEl);\n }\n if (options.vendor) {\n videoCapture.withVendor(options.vendor);\n }\n const extraEventProperties = options.extraEventProperties ?? {};\n\n try {\n videoCapture\n .withExtraEventProperties({\n stream_session_id: UUID(),\n ...extraEventProperties,\n })\n .captureVideoStarted()\n .captureVideoStopped()\n .start();\n } catch (error) {\n return error as Error;\n }\n\n return () => videoCapture.stop();\n}\n"]}
|
package/lib/esm/config.d.ts
CHANGED
|
@@ -46,7 +46,7 @@ export declare class BrowserConfig extends Config implements IBrowserConfig {
|
|
|
46
46
|
enableRequestBodyCompression: boolean;
|
|
47
47
|
customEnrichment?: boolean | CustomEnrichmentOptions | undefined;
|
|
48
48
|
delayedEventsServerUrl?: string | undefined;
|
|
49
|
-
readonly version = "2.
|
|
49
|
+
readonly version = "2.47.0-video-analytics-5.0";
|
|
50
50
|
protected _cookieStorage: Storage<UserSession>;
|
|
51
51
|
protected _deviceId?: string;
|
|
52
52
|
protected _lastEventId?: number;
|
package/lib/esm/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "2.
|
|
1
|
+
export declare const VERSION = "2.47.0-video-analytics-5.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/lib/esm/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export var VERSION = '2.
|
|
1
|
+
export var VERSION = '2.47.0-video-analytics-5.0';
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
package/lib/esm/version.js.map
CHANGED
|
@@ -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.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,OAAO,GAAG,4BAA4B,CAAC","sourcesContent":["export const VERSION = '2.47.0-video-analytics-5.0';\n"]}
|
|
@@ -4,11 +4,11 @@ import { DEFAULT_CONTENT_STARTED_EVENT, DEFAULT_CONTENT_STOPPED_EVENT } from '..
|
|
|
4
4
|
/** Playback states where a view session is still in progress (e.g. buffering). */
|
|
5
5
|
var ACTIVE_PLAYBACK_STATES = new Set(['playing', 'waiting']);
|
|
6
6
|
/**
|
|
7
|
-
* Observer fields that never reach event properties
|
|
8
|
-
* and `percent_completed`/`stop_reason` describe the player event rather
|
|
9
|
-
* which tracks its own values.
|
|
7
|
+
* Observer fields that never reach event properties from `lastEvent`: `position` is taken from
|
|
8
|
+
* observer state instead, and `percent_completed`/`stop_reason` describe the player event rather
|
|
9
|
+
* than the play session, which tracks its own values.
|
|
10
10
|
*/
|
|
11
|
-
var OMITTED_VIDEO_EVENT_PROPERTIES = new Set(['
|
|
11
|
+
var OMITTED_VIDEO_EVENT_PROPERTIES = new Set(['position', 'percent_completed', 'stop_reason']);
|
|
12
12
|
/**
|
|
13
13
|
* Copy remaining player-event fields (vendor metadata such as `mux_playback_id`, ids, titles)
|
|
14
14
|
* onto the Amplitude event, dropping empty values so absent metadata is omitted.
|
|
@@ -206,7 +206,7 @@ var VideoCapture = /** @class */ (function () {
|
|
|
206
206
|
return __assign(__assign(__assign({}, this.parseStartEventProperties(nextState)), {
|
|
207
207
|
// lastEvent.start_time is the playhead at the time of the event, which for a stop event is
|
|
208
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,
|
|
209
|
+
start_time: (_c = (_a = this.playStartTime) !== null && _a !== void 0 ? _a : (_b = nextState.lastEvent) === null || _b === void 0 ? void 0 : _b.start_time) !== null && _c !== void 0 ? _c : 0, stream_duration: (_d = nextState.watchTime) !== null && _d !== void 0 ? _d : 0, percent_completed: calculatePercentCompleted((_e = nextState.position) !== null && _e !== void 0 ? _e : 0, (_g = (_f = nextState.lastEvent) === null || _f === void 0 ? void 0 : _f.duration) !== null && _g !== void 0 ? _g : 0) }), (nextState.errorMessage ? { error_message: nextState.errorMessage } : {}));
|
|
210
210
|
};
|
|
211
211
|
return VideoCapture;
|
|
212
212
|
}());
|
|
@@ -244,7 +244,7 @@ export function trackVideo(amplitude, videoEl, options) {
|
|
|
244
244
|
var extraEventProperties = (_a = options.extraEventProperties) !== null && _a !== void 0 ? _a : {};
|
|
245
245
|
try {
|
|
246
246
|
videoCapture
|
|
247
|
-
.withExtraEventProperties(__assign({
|
|
247
|
+
.withExtraEventProperties(__assign({ stream_session_id: UUID() }, extraEventProperties))
|
|
248
248
|
.captureVideoStarted()
|
|
249
249
|
.captureVideoStopped()
|
|
250
250
|
.start();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"video-capture.js","sourceRoot":"","sources":["../../../src/video-capture/video-capture.ts"],"names":[],"mappings":";AAAA,OAAO,EAEL,aAAa,EAIb,IAAI,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,CAA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C;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 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,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,UAAU,EAAE,mBAAmB,EAAE,aAAa,CAAC,CAAC,CAAC;AAEjG;;;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,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,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,iBAAiB,EAAE,IAAI,EAAE,IACtB,oBAAoB,EACvB;aACD,mBAAmB,EAAE;aACrB,mBAAmB,EAAE;aACrB,KAAK,EAAE,CAAC;KACZ;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,KAAc,CAAC;KACvB;IAED,OAAO,cAAM,OAAA,YAAY,CAAC,IAAI,EAAE,EAAnB,CAAmB,CAAC;AACnC,CAAC","sourcesContent":["import {\n VideoState,\n VideoObserver,\n BrowserClient,\n EmbeddedVideoPlayer,\n VideoVendor,\n UUID,\n BaseEvent,\n getHeartbeatInstance,\n} from '@amplitude/analytics-core';\nimport { DEFAULT_CONTENT_STARTED_EVENT, DEFAULT_CONTENT_STOPPED_EVENT } from '../constants';\n\n/** Playback states where a view session is still in progress (e.g. buffering). */\nconst ACTIVE_PLAYBACK_STATES = new Set<VideoState['playbackState']>(['playing', 'waiting']);\n\n/**\n * Observer fields that never reach event properties from `lastEvent`: `position` is taken from\n * observer state instead, and `percent_completed`/`stop_reason` describe the player event rather\n * than the play session, which tracks its own values.\n */\nconst OMITTED_VIDEO_EVENT_PROPERTIES = new Set(['position', 'percent_completed', 'stop_reason']);\n\n/**\n * Copy remaining player-event fields (vendor metadata such as `mux_playback_id`, ids, titles)\n * onto the Amplitude event, dropping empty values so absent metadata is omitted.\n */\nfunction parseVideoEventProperties(lastEvent: VideoState['lastEvent']): Record<string, string | number | boolean> {\n const properties: Record<string, string | number | boolean> = {};\n for (const [key, value] of Object.entries(lastEvent ?? {})) {\n if (OMITTED_VIDEO_EVENT_PROPERTIES.has(key) || value === null || value === undefined) {\n continue;\n }\n properties[key] = value as string | number | boolean;\n }\n return properties;\n}\n\nexport class VideoCapture {\n private videoEl: HTMLMediaElement | null = null;\n private heartbeat: ReturnType<typeof getHeartbeatInstance>;\n private embeddedVideoPlayer: EmbeddedVideoPlayer | null = null;\n private vendor?: VideoVendor;\n private extraEventProperties: Record<string, string | number | boolean> = {};\n private stopEvent: BaseEvent | null = null;\n private listeners: ((previousState: VideoState, nextState: VideoState) => void)[] = [];\n private onRemoveListeners: (() => void)[] = [];\n private playId: string | null = null;\n private playStartTime: number | null = null;\n\n constructor(private readonly amplitude: BrowserClient) {\n this.heartbeat = getHeartbeatInstance(this.amplitude);\n }\n\n /**\n * Specify a video or audio element to capture events from\n *\n * @param videoEl - The HTML video or audio element to capture events from.\n * @returns The VideoCapture instance.\n */\n withVideoElement(videoEl: HTMLMediaElement): VideoCapture {\n this.videoEl = videoEl;\n return this;\n }\n\n /**\n * Specify an embedded video player.js instance to capture events from\n * @param player - The embedded video player.js instance to capture events from.\n * @returns The VideoCapture instance.\n */\n withEmbeddedPlayer(player: EmbeddedVideoPlayer): VideoCapture {\n this.embeddedVideoPlayer = player;\n return this;\n }\n\n /**\n * Specify a vendor to capture extra vendor-specific event properties\n *\n * @param vendor - The vendor of the video player. Currently only \"mux\" is supported.\n * @returns The VideoCapture instance.\n */\n withVendor(vendor: VideoVendor): VideoCapture {\n this.vendor = vendor;\n return this;\n }\n\n /**\n * Specify extra event properties to include in all captured events\n *\n * @param properties - The extra event properties to include in the Amplitude event.\n * @returns The VideoCapture instance.\n */\n withExtraEventProperties(properties: Record<string, string | number | boolean>): VideoCapture {\n this.extraEventProperties = properties;\n return this;\n }\n\n /**\n * Track a \"[Amplitude] Content Started\" event every time the video starts playing\n * @returns The VideoCapture instance.\n */\n captureVideoStarted(): VideoCapture {\n this.listeners.push((previousState, nextState) => {\n if (!ACTIVE_PLAYBACK_STATES.has(previousState.playbackState) && nextState.playbackState === 'playing') {\n this.playId = UUID();\n /* istanbul ignore next */\n this.playStartTime = nextState.lastEvent?.start_time ?? 0;\n const now = new Date().getTime();\n const startEvent: BaseEvent = {\n insert_id: UUID(),\n event_type: DEFAULT_CONTENT_STARTED_EVENT,\n time: now,\n event_properties: {\n ...this.parseStartEventProperties(nextState),\n ...this.extraEventProperties,\n play_id: this.playId,\n },\n };\n this.stopEvent = {\n ...startEvent,\n insert_id: UUID(),\n event_type: DEFAULT_CONTENT_STOPPED_EVENT,\n time: now + 1,\n event_properties: {\n ...this.parseStopEventProperties(nextState),\n ...this.extraEventProperties,\n stop_reason: 'timeout',\n play_id: this.playId,\n },\n };\n this.heartbeat.trackNoDelay(startEvent).catch(this.stop.bind(this));\n this.heartbeat.track(this.stopEvent).catch(this.stop.bind(this));\n }\n });\n return this;\n }\n\n /**\n * Track a \"[Amplitude] Content Stopped\" event every time the video stops playing\n * @returns The VideoCapture instance.\n */\n captureVideoStopped(): VideoCapture {\n this.listeners.push((previousState, nextState) => {\n // update the delayed event properties to have\n // the most up-to-date values\n if (this.stopEvent) {\n this.stopEvent.event_properties = {\n ...this.stopEvent.event_properties,\n ...this.parseStopEventProperties(nextState),\n ...this.extraEventProperties,\n };\n this.stopEvent.time = new Date().getTime();\n void this.heartbeat.update(this.stopEvent);\n }\n if (\n ACTIVE_PLAYBACK_STATES.has(previousState.playbackState) &&\n !ACTIVE_PLAYBACK_STATES.has(nextState.playbackState)\n ) {\n this.flushStopEvent(nextState.playbackState);\n }\n });\n return this;\n }\n\n /**\n * End the current play session by ingesting its queued delayed stop event immediately.\n *\n * The heartbeat is shared by every capture on the same Amplitude client, so the event is\n * flushed rather than the heartbeat stopped, which would discard other captures' events.\n * Flushing also drops the event from the heartbeat queue once ingested, so the interval\n * winds down on its own. No-op when no play session is in progress.\n */\n private flushStopEvent(stopReason: string) {\n const stopEvent = this.stopEvent;\n if (!stopEvent) {\n return;\n }\n // the next play queues a fresh delayed stop event\n this.stopEvent = null;\n this.playStartTime = null;\n stopEvent.event_properties = {\n ...stopEvent.event_properties,\n stop_reason: stopReason,\n };\n this.heartbeat.trackNoDelay(stopEvent).catch(this.stop.bind(this));\n }\n\n // Placeholder: may need a generic state change listener to capture unusual events or to have\n // more control over the event tracking.\n // withStateChangeListener(listener: (previousState: VideoState, nextState: VideoState) => void): VideoCapture {\n\n /**\n * Start capturing analytics events for the video element\n * @returns The VideoCapture instance.\n * @throws An error if the video element is not specified.\n */\n start(): VideoCapture {\n const videoEl = this.videoEl ?? this.embeddedVideoPlayer;\n if (!videoEl) {\n throw new Error(\n 'Video element not specified. Use withVideoElement() or withEmbeddedPlayer() to specify the video element.',\n );\n }\n if (this.videoEl && this.embeddedVideoPlayer) {\n throw new Error(\n 'Both video element and embedded video player specified. Use only one of withVideoElement() or withEmbeddedPlayer() to specify the video element.',\n );\n }\n const videoObserver = new VideoObserver({\n videoEl,\n onStateChange: (previousState, nextState) => {\n this.listeners.forEach((listener) => listener(previousState, nextState));\n },\n vendor: this.vendor,\n isEmbedded: !!this.embeddedVideoPlayer,\n });\n\n this.onRemoveListeners.push(() => {\n videoObserver.destroy();\n });\n return this;\n }\n\n /**\n * Stop capturing analytics events for the video element.\n *\n * Observers are detached first so no playback state change can race with the final\n * event, then any in-progress play session is closed out.\n */\n stop() {\n this.onRemoveListeners.forEach((listener) => listener());\n this.onRemoveListeners = [];\n this.flushStopEvent('untracked');\n }\n\n parseStartEventProperties(nextState: VideoState): Record<string, string | number | boolean> {\n return {\n ...parseVideoEventProperties(nextState.lastEvent),\n duration: nextState.lastEvent?.duration ?? 0,\n start_time: nextState.lastEvent?.start_time ?? 0,\n position: nextState.position ?? 0,\n delivery_mode: this.getDeliveryMode(),\n };\n }\n\n private getDeliveryMode(): 'video' | 'audio' {\n return this.videoEl instanceof HTMLAudioElement ? 'audio' : 'video';\n }\n\n parseStopEventProperties(nextState: VideoState): Record<string, string | number | boolean> {\n return {\n ...this.parseStartEventProperties(nextState),\n // lastEvent.start_time is the playhead at the time of the event, which for a stop event is\n // where playback ended, so the position captured when the play session began is preferred.\n start_time: this.playStartTime ?? nextState.lastEvent?.start_time ?? 0,\n stream_duration: nextState.watchTime ?? 0,\n percent_completed: calculatePercentCompleted(nextState.position ?? 0, nextState.lastEvent?.duration ?? 0),\n ...(nextState.errorMessage ? { error_message: nextState.errorMessage } : {}),\n };\n }\n}\n\nfunction calculatePercentCompleted(currentTime: number, duration: number) {\n if (!Number.isFinite(currentTime) || !Number.isFinite(duration) || duration <= 0) {\n return 0;\n }\n return Math.min(100, Math.max(0, (currentTime / duration) * 100));\n}\n\nexport type VideoCaptureOptions = {\n vendor?: VideoVendor;\n extraEventProperties?: Record<string, string | number | boolean>;\n};\n\ntype UntrackVideoResult = () => void;\n\nexport type TrackVideoResult = UntrackVideoResult | Error;\n\n/**\n * Track video analytics events for an HTML video or audio element or embedded video player.js instance.\n *\n * Captures [Amplitude] Content Started and [Amplitude] Content Stopped events.\n *\n * @experimental This function is experimental and may not be stable.\n * @param amplitude - The Amplitude client instance.\n * @param videoEl - The HTML video or audio element or embedded video player.js instance to capture events from.\n * @param options - The options for the video capture.\n * @returns A function to stop the video capture.\n */\nexport function trackVideo(\n amplitude: BrowserClient,\n videoEl: HTMLMediaElement | EmbeddedVideoPlayer,\n options: VideoCaptureOptions = {},\n): TrackVideoResult {\n const videoCapture = new VideoCapture(amplitude);\n if (videoEl instanceof HTMLMediaElement) {\n videoCapture.withVideoElement(videoEl);\n } else {\n videoCapture.withEmbeddedPlayer(videoEl);\n }\n if (options.vendor) {\n videoCapture.withVendor(options.vendor);\n }\n const extraEventProperties = options.extraEventProperties ?? {};\n\n try {\n videoCapture\n .withExtraEventProperties({\n stream_session_id: UUID(),\n ...extraEventProperties,\n })\n .captureVideoStarted()\n .captureVideoStopped()\n .start();\n } catch (error) {\n return error as Error;\n }\n\n return () => videoCapture.stop();\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){"use strict";!function(e,t){var n=e.amplitude||{_q:[],_iq:{}};if(n.invoked)e.console&&console.error&&console.error("Amplitude snippet has been loaded.");else{var r=function(e,t){e.prototype[t]=function(){return this._q.push({name:t,args:Array.prototype.slice.call(arguments,0)}),this}},i=function(e,t,n){return function(r){e._q.push({name:t,args:Array.prototype.slice.call(n,0),resolve:r})}},o=function(e,t,n){e[t]=function(){if(n)return{promise:new Promise(i(e,t,Array.prototype.slice.call(arguments)))}}},s=function(e){for(var t=0;t<
|
|
1
|
+
!function(){"use strict";!function(e,t){var n=e.amplitude||{_q:[],_iq:{}};if(n.invoked)e.console&&console.error&&console.error("Amplitude snippet has been loaded.");else{var r=function(e,t){e.prototype[t]=function(){return this._q.push({name:t,args:Array.prototype.slice.call(arguments,0)}),this}},i=function(e,t,n){return function(r){e._q.push({name:t,args:Array.prototype.slice.call(n,0),resolve:r})}},o=function(e,t,n){e[t]=function(){if(n)return{promise:new Promise(i(e,t,Array.prototype.slice.call(arguments)))}}},s=function(e){for(var t=0;t<f.length;t++)o(e,f[t],!1);for(var n=0;n<y.length;n++)o(e,y[n],!0)};n.invoked=!0;var u=t.getElementsByTagName("script")[0],a=t.createElement("script");a.src="https://cdn.amplitude.com/libs/plugin-autocapture-browser-0.9.0-min.js.gz",a.async=!1,u.parentNode.insertBefore(a,u);var c=t.createElement("script");c.type="text/javascript",c.integrity="sha384-gt3Pvso3avjAL5mGN9NcOGKwcy+bj20O840b2Lc/uhLu77g9UK2KXDLnlsUezUcK",c.crossOrigin="anonymous",c.async=!1,c.src="https://cdn.amplitude.com/libs/analytics-browser-2.47.0-video-analytics-5.0-min.js.gz",c.onload=function(){e.amplitude.runQueuedFunctions||console.log("[Amplitude] Error: could not load SDK"),e.amplitude.init("YOUR_API_KEY","YOUR_USER_ID",{instanceName:"amplitude-bookmarklet",serverZone:"YOUR_SERVER_ZONE",ingestionMetadata:{sourceName:"browser-typescript-bookmarklet",sourceVersion:"1.0.0"},optOut:!1}),amplitudeAutocapturePlugin&&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++)r(p,l[d]);n.Identify=p;for(var m=function(){return this._q=[],this},g=["getEventProperties","setProductId","setQuantity","setPrice","setRevenue","setRevenueType","setReceipt","setReceiptSig","setCurrency","setEventProperties"],v=0;v<g.length;v++)r(m,g[v]);n.Revenue=m;var f=["getDeviceId","setDeviceId","getSessionId","setSessionId","getUserId","setUserId","setOptOut","setTransport","reset","extendSession"],y=["init","add","remove","track","logEvent","identify","groupIdentify","setGroup","revenue","flush"];s(n),n.createInstance=function(e){return n._iq[e]={_q:[]},s(n._iq[e]),n._iq[e]},e.amplitude=n}}(window,document)}();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
javascript:!function()%7B%22use%20strict%22%3B!function(e%2Ct)%7Bvar%20n%3De.amplitude%7C%7C%7B_q%3A%5B%5D%2C_iq%3A%7B%7D%7D%3Bif(n.invoked)e.console%26%26console.error%26%26console.error(%22Amplitude%20snippet%20has%20been%20loaded.%22)%3Belse%7Bvar%20r%3Dfunction(e%2Ct)%7Be.prototype%5Bt%5D%3Dfunction()%7Breturn%20this._q.push(%7Bname%3At%2Cargs%3AArray.prototype.slice.call(arguments%2C0)%7D)%2Cthis%7D%7D%2Ci%3Dfunction(e%2Ct%2Cn)%7Breturn%20function(r)%7Be._q.push(%7Bname%3At%2Cargs%3AArray.prototype.slice.call(n%2C0)%2Cresolve%3Ar%7D)%7D%7D%2Co%3Dfunction(e%2Ct%2Cn)%7Be%5Bt%5D%3Dfunction()%7Bif(n)return%7Bpromise%3Anew%20Promise(i(e%2Ct%2CArray.prototype.slice.call(arguments)))%7D%7D%7D%2Cs%3Dfunction(e)%7Bfor(var%20t%3D0%3Bt%
|
|
1
|
+
javascript:!function()%7B%22use%20strict%22%3B!function(e%2Ct)%7Bvar%20n%3De.amplitude%7C%7C%7B_q%3A%5B%5D%2C_iq%3A%7B%7D%7D%3Bif(n.invoked)e.console%26%26console.error%26%26console.error(%22Amplitude%20snippet%20has%20been%20loaded.%22)%3Belse%7Bvar%20r%3Dfunction(e%2Ct)%7Be.prototype%5Bt%5D%3Dfunction()%7Breturn%20this._q.push(%7Bname%3At%2Cargs%3AArray.prototype.slice.call(arguments%2C0)%7D)%2Cthis%7D%7D%2Ci%3Dfunction(e%2Ct%2Cn)%7Breturn%20function(r)%7Be._q.push(%7Bname%3At%2Cargs%3AArray.prototype.slice.call(n%2C0)%2Cresolve%3Ar%7D)%7D%7D%2Co%3Dfunction(e%2Ct%2Cn)%7Be%5Bt%5D%3Dfunction()%7Bif(n)return%7Bpromise%3Anew%20Promise(i(e%2Ct%2CArray.prototype.slice.call(arguments)))%7D%7D%7D%2Cs%3Dfunction(e)%7Bfor(var%20t%3D0%3Bt%3Cf.length%3Bt%2B%2B)o(e%2Cf%5Bt%5D%2C!1)%3Bfor(var%20n%3D0%3Bn%3Cy.length%3Bn%2B%2B)o(e%2Cy%5Bn%5D%2C!0)%7D%3Bn.invoked%3D!0%3Bvar%20u%3Dt.getElementsByTagName(%22script%22)%5B0%5D%2Ca%3Dt.createElement(%22script%22)%3Ba.src%3D%22https%3A%2F%2Fcdn.amplitude.com%2Flibs%2Fplugin-autocapture-browser-0.9.0-min.js.gz%22%2Ca.async%3D!1%2Cu.parentNode.insertBefore(a%2Cu)%3Bvar%20c%3Dt.createElement(%22script%22)%3Bc.type%3D%22text%2Fjavascript%22%2Cc.integrity%3D%22sha384-gt3Pvso3avjAL5mGN9NcOGKwcy%2Bbj20O840b2Lc%2FuhLu77g9UK2KXDLnlsUezUcK%22%2Cc.crossOrigin%3D%22anonymous%22%2Cc.async%3D!1%2Cc.src%3D%22https%3A%2F%2Fcdn.amplitude.com%2Flibs%2Fanalytics-browser-2.47.0-video-analytics-5.0-min.js.gz%22%2Cc.onload%3Dfunction()%7Be.amplitude.runQueuedFunctions%7C%7Cconsole.log(%22%5BAmplitude%5D%20Error%3A%20could%20not%20load%20SDK%22)%2Ce.amplitude.init(%22YOUR_API_KEY%22%2C%22YOUR_USER_ID%22%2C%7BinstanceName%3A%22amplitude-bookmarklet%22%2CserverZone%3A%22YOUR_SERVER_ZONE%22%2CingestionMetadata%3A%7BsourceName%3A%22browser-typescript-bookmarklet%22%2CsourceVersion%3A%221.0.0%22%7D%2CoptOut%3A!1%7D)%2CamplitudeAutocapturePlugin%26%26amplitudeAutocapturePlugin.autocapturePlugin%26%26%22function%22%3D%3Dtypeof%20amplitudeAutocapturePlugin.autocapturePlugin%26%26e.amplitude.add(amplitudeAutocapturePlugin.autocapturePlugin())%2Calert(%22Amplitude%20is%20now%20tracking%20events!%22)%7D%2Cu.parentNode.insertBefore(c%2Cu)%3Bfor(var%20p%3Dfunction()%7Breturn%20this._q%3D%5B%5D%2Cthis%7D%2Cl%3D%5B%22add%22%2C%22append%22%2C%22clearAll%22%2C%22prepend%22%2C%22set%22%2C%22setOnce%22%2C%22unset%22%2C%22preInsert%22%2C%22postInsert%22%2C%22remove%22%2C%22getUserProperties%22%5D%2Cd%3D0%3Bd%3Cl.length%3Bd%2B%2B)r(p%2Cl%5Bd%5D)%3Bn.Identify%3Dp%3Bfor(var%20m%3Dfunction()%7Breturn%20this._q%3D%5B%5D%2Cthis%7D%2Cg%3D%5B%22getEventProperties%22%2C%22setProductId%22%2C%22setQuantity%22%2C%22setPrice%22%2C%22setRevenue%22%2C%22setRevenueType%22%2C%22setReceipt%22%2C%22setReceiptSig%22%2C%22setCurrency%22%2C%22setEventProperties%22%5D%2Cv%3D0%3Bv%3Cg.length%3Bv%2B%2B)r(m%2Cg%5Bv%5D)%3Bn.Revenue%3Dm%3Bvar%20f%3D%5B%22getDeviceId%22%2C%22setDeviceId%22%2C%22getSessionId%22%2C%22setSessionId%22%2C%22getUserId%22%2C%22setUserId%22%2C%22setOptOut%22%2C%22setTransport%22%2C%22reset%22%2C%22extendSession%22%5D%2Cy%3D%5B%22init%22%2C%22add%22%2C%22remove%22%2C%22track%22%2C%22logEvent%22%2C%22identify%22%2C%22groupIdentify%22%2C%22setGroup%22%2C%22revenue%22%2C%22flush%22%5D%3Bs(n)%2Cn.createInstance%3Dfunction(e)%7Breturn%20n._iq%5Be%5D%3D%7B_q%3A%5B%5D%7D%2Cs(n._iq%5Be%5D)%2Cn._iq%5Be%5D%7D%2Ce.amplitude%3Dn%7D%7D(window%2Cdocument)%7D()%3B%0A
|