From 4aff6ee1aea491342574e5afead2bd95007922dd Mon Sep 17 00:00:00 2001 From: Nina Ciocanu Date: Fri, 17 May 2024 17:38:44 +0300 Subject: [PATCH 1/2] instantiate instance on session start --- .../LegacyMediaAnalytics/createGetInstance.js | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/components/LegacyMediaAnalytics/createGetInstance.js b/src/components/LegacyMediaAnalytics/createGetInstance.js index c08e4195e..6517f2de0 100644 --- a/src/components/LegacyMediaAnalytics/createGetInstance.js +++ b/src/components/LegacyMediaAnalytics/createGetInstance.js @@ -13,6 +13,7 @@ import { EVENT, MEDIA_EVENTS_INTERNAL } from "./constants/constants"; import { includes, isEmptyObject, + isNil, isNonEmptyArray, isNumber } from "../../utils"; @@ -22,10 +23,13 @@ import { } from "./constants/mediaKeysToXdmConverter"; export default ({ logger, trackMediaSession, trackMediaEvent, uuid }) => { - let trackerState = { - qoe: null, - lastPlayhead: 0, - playerId: uuid() + let trackerState = null; + const instantiateTracker = () => { + trackerState = { + qoe: null, + lastPlayhead: 0, + playerId: uuid() + }; }; const getEventType = ({ eventType }) => { if ( @@ -98,7 +102,7 @@ export default ({ logger, trackMediaSession, trackMediaEvent, uuid }) => { return { trackSessionStart: (mediaObject, contextData = {}) => { - if (isEmptyObject(mediaObject)) { + if (isNil(mediaObject) || isEmptyObject(mediaObject)) { logger.warn("Invalid media object"); return {}; } @@ -106,11 +110,7 @@ export default ({ logger, trackMediaSession, trackMediaEvent, uuid }) => { logger.warn( "The Media Session was completed. Restarting a new session." ); - trackerState = { - qoe: null, - lastPlayhead: 0, - playerId: uuid() - }; + instantiateTracker(); } const xdm = createXdmObject({ eventType: MEDIA_EVENTS_INTERNAL.SessionStart, From 0a827ba38089d3f79de96b9d09375ad253e66a58 Mon Sep 17 00:00:00 2001 From: Nina Ciocanu Date: Fri, 17 May 2024 17:41:31 +0300 Subject: [PATCH 2/2] instantiate instance on session start test update --- .../LegacyMediaAnalytics/createGetInstance.spec.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/unit/specs/components/LegacyMediaAnalytics/createGetInstance.spec.js b/test/unit/specs/components/LegacyMediaAnalytics/createGetInstance.spec.js index 05a76fa4b..f4c752f1a 100644 --- a/test/unit/specs/components/LegacyMediaAnalytics/createGetInstance.spec.js +++ b/test/unit/specs/components/LegacyMediaAnalytics/createGetInstance.spec.js @@ -41,6 +41,7 @@ describe("createGetInstance", () => { trackMediaEvent, uuid }); + result.trackSessionStart({ sessionDetails: {} }); result.trackPlay(); expect(trackMediaEvent).toHaveBeenCalledWith({ @@ -55,6 +56,7 @@ describe("createGetInstance", () => { trackMediaEvent, uuid }); + result.trackSessionStart({ sessionDetails: {} }); result.trackPause(); expect(trackMediaEvent).toHaveBeenCalledWith({ @@ -118,6 +120,7 @@ describe("createGetInstance", () => { trackMediaEvent, uuid }); + result.trackSessionStart({ sessionDetails: {} }); result.trackError("error"); expect(trackMediaEvent).toHaveBeenCalledWith({ @@ -139,6 +142,7 @@ describe("createGetInstance", () => { trackMediaEvent, uuid }); + result.trackSessionStart({ sessionDetails: {} }); result.trackComplete(); expect(trackMediaEvent).toHaveBeenCalledWith({ @@ -156,6 +160,7 @@ describe("createGetInstance", () => { trackMediaEvent, uuid }); + result.trackSessionStart({ sessionDetails: {} }); result.trackSessionEnd(); expect(trackMediaEvent).toHaveBeenCalledWith({ @@ -176,6 +181,7 @@ describe("createGetInstance", () => { const state = { name: "muted" }; + result.trackSessionStart({ sessionDetails: {} }); result.trackEvent("stateStart", state); expect(trackMediaEvent).toHaveBeenCalledWith({ @@ -198,6 +204,7 @@ describe("createGetInstance", () => { const state = { name: "muted" }; + result.trackSessionStart({ sessionDetails: {} }); result.trackEvent("stateEnd", state); expect(trackMediaEvent).toHaveBeenCalledWith({ @@ -230,7 +237,7 @@ describe("createGetInstance", () => { "a.media.ad.advertiser": "Sample Advertiser 2", "a.media.ad.campaign": "csmpaign2" }; - + result.trackSessionStart({ sessionDetails: {} }); result.trackEvent("adStart", { advertisingDetails }, adContextData); expect(trackMediaEvent).toHaveBeenCalledWith({