Skip to content

Commit

Permalink
Round percent progress in ad events
Browse files Browse the repository at this point in the history
  • Loading branch information
matus-tomlein committed May 15, 2023
1 parent 79df441 commit b74c7b3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
12 changes: 8 additions & 4 deletions plugins/browser-plugin-media/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@ export function trackMediaAdSkip(
CommonMediaEventProperties,
trackers: Array<string> = Object.keys(_trackers)
) {
const { percentProgress } = args;
let { percentProgress } = args;
if (percentProgress !== undefined) { percentProgress = Math.floor(percentProgress); }
track(
{
mediaEvent: {
Expand Down Expand Up @@ -502,7 +503,8 @@ export function trackMediaAdClick(
CommonMediaEventProperties,
trackers: Array<string> = Object.keys(_trackers)
) {
const { percentProgress } = args;
let { percentProgress } = args;
if (percentProgress !== undefined) { percentProgress = Math.floor(percentProgress); }
track(
{
mediaEvent: {
Expand All @@ -529,7 +531,8 @@ export function trackMediaAdPause(
CommonMediaEventProperties,
trackers: Array<string> = Object.keys(_trackers)
) {
const { percentProgress } = args;
let { percentProgress } = args;
if (percentProgress !== undefined) { percentProgress = Math.floor(percentProgress); }
track(
{
mediaEvent: {
Expand Down Expand Up @@ -557,7 +560,8 @@ export function trackMediaAdResume(
CommonMediaEventProperties,
trackers: Array<string> = Object.keys(_trackers)
) {
const { percentProgress } = args;
let { percentProgress } = args;
if (percentProgress !== undefined) { percentProgress = Math.floor(percentProgress); }
track(
{
mediaEvent: {
Expand Down
11 changes: 7 additions & 4 deletions plugins/browser-plugin-media/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ export type MediaTrackingConfiguration = {
/** Attributes for the media player context entity */
player?: MediaPlayerUpdate;
/** Attributes for the media player session context entity or false to disable it. Enabled by default. */
session?: { startedAt?: Date } | false;
session?: {
/** Local date-time timestamp of when the session started. Automatically set to current time if not given. */
startedAt?: Date
} | false;
/** Configuration for sending ping events. Enabled by default. */
pings?:
| {
Expand Down Expand Up @@ -115,12 +118,12 @@ export type MediaTrackVolumeChangeArguments = {
};

export type MediaTrackFullscreenChangeArguments = {
/** Whether the video element is fullscreen. */
/** Whether the video element is fullscreen after the change. */
fullscreen: boolean;
};

export type MediaTrackPictureInPictureChangeArguments = {
/** Whether the video element is showing picture-in-picture. */
/** Whether the video element is showing picture-in-picture after the change. */
pictureInPicture: boolean;
};

Expand Down Expand Up @@ -257,7 +260,7 @@ export interface MediaPlayerUpdate {

/** Partial type/schema for a context entity for media player events that tracks a session of a single media player usage */
export interface MediaSession extends Record<string, unknown> {
/** An identifier for the media session */
/** An identifier for the media session that is kept while the media content is played in the media player. Does not reset automatically. */
mediaSessionId: string;
/** Date-time timestamp of when the session started */
startedAt?: Date;
Expand Down
8 changes: 4 additions & 4 deletions plugins/browser-plugin-media/test/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ describe('Media Tracking API', () => {
it('tracks an ad skip event', () => {
startMediaTracking({ id, session: false });

trackMediaAdSkip({ id, percentProgress: 33 })
trackMediaAdSkip({ id, percentProgress: 33.33 })

expect(eventQueue).toMatchObject([
{
Expand All @@ -242,7 +242,7 @@ describe('Media Tracking API', () => {
it('tracks an ad click event', () => {
startMediaTracking({ id, session: false });

trackMediaAdClick({ id, percentProgress: 33 })
trackMediaAdClick({ id, percentProgress: 33.33 })

expect(eventQueue).toMatchObject([
{
Expand All @@ -257,7 +257,7 @@ describe('Media Tracking API', () => {
it('tracks an ad pause event', () => {
startMediaTracking({ id, session: false });

trackMediaAdPause({ id, percentProgress: 33 })
trackMediaAdPause({ id, percentProgress: 33.33 })

expect(eventQueue).toMatchObject([
{
Expand All @@ -272,7 +272,7 @@ describe('Media Tracking API', () => {
it('tracks an ad resume event', () => {
startMediaTracking({ id, session: false });

trackMediaAdResume({ id, percentProgress: 33 })
trackMediaAdResume({ id, percentProgress: 33.33 })

expect(eventQueue).toMatchObject([
{
Expand Down

0 comments on commit b74c7b3

Please sign in to comment.