-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
TAN-665 Posthog user recordings
- Loading branch information
Showing
11 changed files
with
255 additions
and
63 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
82 changes: 82 additions & 0 deletions
82
front/app/containers/App/UserSessionRecordingModal/index.tsx
This file contains 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 React, { useState, useEffect } from 'react'; | ||
|
||
import { | ||
Icon, | ||
colors, | ||
Text, | ||
Button, | ||
Title, | ||
Box, | ||
} from '@citizenlab/cl2-component-library'; | ||
import { useIntl } from 'utils/cl-intl'; | ||
import messages from './messages'; | ||
import Modal from 'components/UI/Modal'; | ||
|
||
import { get, set } from 'js-cookie'; | ||
import eventEmitter from 'utils/eventEmitter'; | ||
import useFeatureFlag from 'hooks/useFeatureFlag'; | ||
|
||
const UserSessionRecordingModal = () => { | ||
const [modalOpened, setModalOpened] = useState(false); | ||
const { formatMessage } = useIntl(); | ||
const userSessionRecodingFeatureFlag = useFeatureFlag({ | ||
name: 'user_session_recording', | ||
}); | ||
|
||
useEffect(() => { | ||
const shouldShowModal = () => { | ||
const hasSeenModal = get('user_session_recording_modal'); | ||
const show = | ||
userSessionRecodingFeatureFlag && | ||
hasSeenModal !== 'true' && | ||
Math.random() < 0.01; // 1% chance of showing the modal | ||
return show; | ||
}; | ||
|
||
if (shouldShowModal()) { | ||
setModalOpened(true); | ||
} | ||
}, [userSessionRecodingFeatureFlag]); | ||
|
||
const onAccept = () => { | ||
setModalOpened(false); | ||
eventEmitter.emit('user_session_recording_accepted', true); | ||
set('user_session_recording_modal', 'true'); | ||
}; | ||
|
||
const onClose = () => { | ||
setModalOpened(false); | ||
set('user_session_recording_modal', 'true'); | ||
}; | ||
|
||
return ( | ||
<Modal opened={modalOpened} close={onClose}> | ||
<Box p="24px"> | ||
<Box display="flex" gap="16px" alignItems="center"> | ||
<Icon | ||
name="alert-circle" | ||
fill={colors.green500} | ||
width="40px" | ||
height="40px" | ||
/> | ||
<Title>{formatMessage(messages.modalTitle)}</Title> | ||
</Box> | ||
|
||
<Text fontSize="l">{formatMessage(messages.modalDescription1)}</Text> | ||
<Text fontSize="l">{formatMessage(messages.modalDescription2)}</Text> | ||
<Text fontSize="l">{formatMessage(messages.modalDescription3)}</Text> | ||
|
||
<Box display="flex" justifyContent="flex-end" gap="16px" mt="48px"> | ||
<Button buttonStyle="secondary" onClick={onClose}> | ||
{formatMessage(messages.reject)} | ||
</Button> | ||
<Button buttonStyle="primary" onClick={onAccept}> | ||
{formatMessage(messages.accept)} | ||
</Button> | ||
</Box> | ||
</Box> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default UserSessionRecordingModal; |
30 changes: 30 additions & 0 deletions
30
front/app/containers/App/UserSessionRecordingModal/messages.ts
This file contains 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,30 @@ | ||
import { defineMessages } from 'react-intl'; | ||
|
||
export default defineMessages({ | ||
modalTitle: { | ||
id: 'app.sessionRecording.modalTitle', | ||
defaultMessage: 'Help us improve this website', | ||
}, | ||
modalDescription1: { | ||
id: 'app.sessionRecording.modalDescription1', | ||
defaultMessage: | ||
'In order to better understand our users, we randomly ask a small percentage of visitors to track their browsing session in detail.', | ||
}, | ||
modalDescription2: { | ||
id: 'app.sessionRecording.modalDescription2', | ||
defaultMessage: | ||
'The sole purpose of the recorded data is to improve the website. None of your data will be shared with a 3rd party. Any sensitive information you enter will be filtered.', | ||
}, | ||
modalDescription3: { | ||
id: 'app.sessionRecording.modalDescription3', | ||
defaultMessage: 'Do you accept?', | ||
}, | ||
accept: { | ||
id: 'app.sessionRecording.accept', | ||
defaultMessage: 'Yes, I accept', | ||
}, | ||
reject: { | ||
id: 'app.sessionRecording.reject', | ||
defaultMessage: 'No, I reject', | ||
}, | ||
}); |
This file contains 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 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 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.