Skip to content

Commit 7bb675e

Browse files
authored
feat(cookie-consent): add screen to context object of segment (#2012)
Signed-off-by: Alexandre Philibeaux <[email protected]>
1 parent c9dd424 commit 7bb675e

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@scaleway/cookie-consent': patch
3+
---
4+
5+
Add a screen object from window into the context of segment

packages/cookie-consent/src/CookieConsentProvider/SegmentConsentMiddleware.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ export const SegmentConsentMiddleware = ({
4747
// https://segment.com/docs/privacy/consent-management/consent-in-segment-connections/#consent-object
4848
categoryPreferences: categoriesConsent,
4949
}
50+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
51+
if (window) {
52+
const screen = {
53+
width: window.screen.width,
54+
height: window.screen.height,
55+
availHeight: window.screen.availHeight,
56+
availWidth: window.screen.availWidth,
57+
}
58+
// eslint-disable-next-line , no-param-reassign
59+
payload.obj.context['screen'] = screen
60+
}
5061

5162
// eslint-disable-next-line , no-param-reassign
5263
payload.obj.context['consent'] = consent
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// useSegmentIntegrations tests have been splitted in multiple files because of https://github.com/facebook/vi/issues/8987
2+
import SegmentProvider from '@scaleway/use-segment'
3+
import { render } from '@testing-library/react'
4+
import { describe, it } from 'vitest'
5+
import { CookieConsentProvider, SegmentConsentMiddleware } from '..'
6+
7+
const segmentSettings = {
8+
writeKey: 'writeKey',
9+
cdnURL: 'cdnURL',
10+
timeout: 300,
11+
}
12+
13+
describe('CookieConsent - SegmentConsentMiddleware', () => {
14+
it('should render correctly', () => {
15+
render(
16+
<CookieConsentProvider
17+
isConsentRequired
18+
essentialIntegrations={['Stripe', 'Sentry']}
19+
config={{
20+
segment: segmentSettings,
21+
}}
22+
>
23+
<SegmentProvider settings={segmentSettings} events={{}}>
24+
<SegmentConsentMiddleware amplitudeIntegrationName="Amplitude (Actions)" />
25+
</SegmentProvider>
26+
</CookieConsentProvider>,
27+
)
28+
})
29+
})

0 commit comments

Comments
 (0)