-
Notifications
You must be signed in to change notification settings - Fork 233
Migrate html5 plugin to new media plugin #1344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Greg Leonard (greg-el)
merged 1 commit into
release/4.0.0
from
migrate-html5-plugin-to-new-media-plugin
Oct 8, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
...wser-plugin-media-tracking/migrate-html5-plugin-to-new-media-plugin_2024-09-24-12-28.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "changes": [ | ||
| { | ||
| "packageName": "@snowplow/browser-plugin-media-tracking", | ||
| "comment": "Migrate HTML Media Tracking to Snowplow Media Plugin", | ||
| "type": "none" | ||
| } | ||
| ], | ||
| "packageName": "@snowplow/browser-plugin-media-tracking" | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| // DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush. | ||
| { | ||
| "pnpmShrinkwrapHash": "c364f96ddb4f2ccb56f10dceb499162dffc440f8", | ||
| "pnpmShrinkwrapHash": "64adeaeaaaae09f264464fa44834bfe036401311", | ||
| "preferredVersionsHash": "bf21a9e8fbc5a3846fb05b4fa0859e0917b2202f" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import { Logger } from '@snowplow/tracker-core'; | ||
| import { BrowserPlugin, BrowserTracker } from '@snowplow/browser-tracker-core'; | ||
| import { waitForElement } from './findElem'; | ||
| import { Config, isElementConfig, isStringConfig } from './config'; | ||
| import { setUpListeners } from './player'; | ||
| import { setConfigDefaults } from './helperFunctions'; | ||
|
|
||
| // These imports are used for documentation purposes only. | ||
| // Typescript complains that they are unused. | ||
| // @ts-ignore: TS6133 | ||
| import { DynamicContext } from '@snowplow/tracker-core'; | ||
| // @ts-ignore: TS6133 | ||
| import { HTML5MediaEventTypes } from './config'; | ||
| // @ts-ignore: TS6133 | ||
| import { FilterOutRepeatedEvents } from '@snowplow/browser-plugin-media/src/types'; | ||
|
|
||
| import { endMediaTracking } from '@snowplow/browser-plugin-media'; | ||
|
|
||
| let LOG: Logger; | ||
| const _trackers: Record<string, BrowserTracker> = {}; | ||
|
|
||
| export function MediaTrackingPlugin(): BrowserPlugin { | ||
| return { | ||
| activateBrowserPlugin: (tracker: BrowserTracker) => { | ||
| _trackers[tracker.id] = tracker; | ||
| }, | ||
| logger: (logger) => { | ||
| LOG = logger; | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Enables media tracking on an HTML `<video>` or `<audio>` element. | ||
| * | ||
| * @param {Config} config - Configuration options for media tracking. | ||
| * | ||
| * **Required:** | ||
| * - `config.id` (`string`): The session ID. Must be unique for each media element. Used to identify the media session and end tracking. | ||
| * - `config.video` (string | HTMLMediaElement): The ID of the media element or the element itself. | ||
| * | ||
| * **Optional:** | ||
| * - `config.label` (`string`): A human-readable label for the media element. | ||
| * - `config.captureEvents` {@link HTML5MediaEventTypes}: A list of media events to track. All events are tracked by default. | ||
| * - `config.boundaries` (`number[]`): Percentage thresholds (0-100) at which to trigger progress events. Disabled by default. | ||
| * - `config.context` {@link DynamicContext}: Contexts to attach to each tracking event. | ||
| * | ||
| * **Ping Configuration (Optional):** | ||
| * - `config.pings.pingInterval` (`number`): The interval (in seconds) for sending ping events. Default is 30(s). | ||
| * - `config.pings.maxPausedPings` (`number`): The maximum number of ping events sent while playback is paused. Default is 1. | ||
| * | ||
| * **Other Options (Optional):** | ||
| * - `config.updatePageActivityWhilePlaying` (`boolean`): Whether to update page activity while media is playing. Enabled by default. | ||
| * - `config.filterOutRepeatedEvents` {@link FilterOutRepeatedEvents}: Whether to suppress consecutive identical events. Default is false. | ||
| */ | ||
| export function startHtml5MediaTracking(config: Config) { | ||
| if (!config.video) { | ||
| LOG.error( | ||
| "Missing 'video' property in the enableMediaTracking configuration. ", | ||
| "Ensure the 'config.video' property is correctly set. Current config: ", | ||
| config | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| config = setConfigDefaults(config); | ||
|
|
||
| if (isStringConfig(config)) { | ||
| waitForElement(config, setUpListeners); | ||
| } else if (isElementConfig(config)) { | ||
| setUpListeners(config); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Ends media tracking with the given ID if previously started. Clears local state for the media tracking and sends any events waiting to be sent. | ||
| * | ||
| * @param {string} id - The session ID. | ||
| */ | ||
| export function endHtml5MediaTracking(id: string) { | ||
| endMediaTracking({ id }); | ||
| } | ||
94 changes: 0 additions & 94 deletions
94
plugins/browser-plugin-media-tracking/src/buildMediaEvent.ts
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { MediaEventType } from '@snowplow/browser-plugin-media'; | ||
| import { CommonMediaEventProperties, MediaTrackingConfiguration } from '@snowplow/browser-plugin-media/src/types'; | ||
|
|
||
| export type HTML5MediaEventTypes = Extract< | ||
| MediaEventType, | ||
| | MediaEventType.Ready | ||
| | MediaEventType.Play | ||
| | MediaEventType.Pause | ||
| | MediaEventType.End | ||
| | MediaEventType.SeekEnd | ||
| | MediaEventType.PlaybackRateChange | ||
| | MediaEventType.VolumeChange | ||
| | MediaEventType.FullscreenChange | ||
| | MediaEventType.PictureInPictureChange | ||
| | MediaEventType.BufferStart | ||
| | MediaEventType.BufferEnd | ||
| | MediaEventType.Error | ||
| | MediaEventType.Ping | ||
| | MediaEventType.PercentProgress | ||
| >; | ||
|
|
||
| export type Config = { | ||
| video: string | HTMLMediaElement; | ||
| label?: string; | ||
| } & CommonMediaEventProperties & | ||
| Omit<MediaTrackingConfiguration, 'player'>; | ||
|
|
||
| export interface StringConfig extends Config { | ||
| video: string; | ||
| } | ||
|
|
||
| export function isStringConfig(config: Config): config is StringConfig { | ||
| return typeof config.video === 'string'; | ||
| } | ||
|
|
||
| export interface ElementConfig extends Config { | ||
| video: HTMLMediaElement; | ||
| } | ||
|
|
||
| export function isElementConfig(config: Config): config is ElementConfig { | ||
| return config.video instanceof HTMLMediaElement; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.