diff --git a/src/sdkToEventsApiConverter.ts b/src/sdkToEventsApiConverter.ts index 93553866..f4c51b31 100644 --- a/src/sdkToEventsApiConverter.ts +++ b/src/sdkToEventsApiConverter.ts @@ -77,8 +77,16 @@ export function convertEvents( device_info: { platform: EventsApi.DeviceInformationPlatformEnum.web, - screen_width: typeof window !== 'undefined' ? window.screen.width : 0, - screen_height: typeof window !== 'undefined' ? window.screen.height : 0, + screen_width: + typeof window !== 'undefined' && + typeof window.screen !== 'undefined' + ? window.screen.width + : 0, + screen_height: + typeof window !== 'undefined' && + typeof window.screen !== 'undefined' + ? window.screen.height + : 0, }, user_attributes: lastEvent.UserAttributes, user_identities: convertUserIdentities(lastEvent.UserIdentities), diff --git a/test/src/tests-runtimeToBatchEventsDTO.ts b/test/src/tests-runtimeToBatchEventsDTO.ts index 41bdd047..ad2f935f 100644 --- a/test/src/tests-runtimeToBatchEventsDTO.ts +++ b/test/src/tests-runtimeToBatchEventsDTO.ts @@ -466,4 +466,56 @@ describe('Old model to batch model conversion', () => { done(); }); + + it('Set width and height to 0 when window is defined but screen is not defined', done => { + const originalScreen = window.screen; + delete window.screen; + + const sdkEvent: SDKEvent = { + EventName: "Pause Event", + EventCategory: 8, + ExpandedEventCount: 0, + EventDataType: 4, + EventAttributes: { + content_duration: '120000', + content_id: "1234567", + content_title: "My sweet sweet media", + content_type: "Video", + media_session_id: "07be2e14-7e05-4053-bcb5-94950365822d", + playhead_position: '7023.335999999999', + stream_type: "OnDemand", + }, + ConsentState: null, + CurrencyCode: null, + CustomFlags: {}, + DataPlan: {}, + Debug: true, + DeviceId: "0edd580e-d887-44e4-89ae-cd65aa0ee933", + Location: null, + MPID: "-8433569646818451201", + OptOut: null, + SDKVersion: "2.11.15", + SourceMessageId: 'testSMID', + SessionId: "64102C03-592F-440D-8BCC-1D27AAA6B188", + SessionStartDate: 1603211322698, + Timestamp: 1603212299414, + UserAttributes: {}, + UserIdentities: [], + IsFirstRun: true, + } + + const batch = Converter.convertEvents( + '-8433569646818451201', + [sdkEvent], + window.mParticle.getInstance() + ); + + expect(batch).to.be.ok; + expect(batch.device_info.screen_height).to.equal(0); + expect(batch.device_info.screen_width).to.equal(0); + + // set screen back on + window.screen = originalScreen; + done(); + }); }); \ No newline at end of file