mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-27 09:42:00 +00:00
Merge pull request #8016 from overleaf/msm-leavers-survey-metrics
[Settings] Metrics for institutional leavers survey GitOrigin-RevId: 776d556789e8c9d0ea4c524ce4daa6bf05435810
This commit is contained in:
parent
9a71372c36
commit
c8daef59dc
2 changed files with 65 additions and 3 deletions
|
@ -1,7 +1,13 @@
|
||||||
|
import { useEffect } from 'react'
|
||||||
import { Alert } from 'react-bootstrap'
|
import { Alert } from 'react-bootstrap'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import usePersistedState from '../../../shared/hooks/use-persisted-state'
|
import usePersistedState from '../../../shared/hooks/use-persisted-state'
|
||||||
import { useUserEmailsContext } from '../context/user-email-context'
|
import { useUserEmailsContext } from '../context/user-email-context'
|
||||||
|
import { sendMB } from '../../../infrastructure/event-tracking'
|
||||||
|
|
||||||
|
function sendMetrics(segmentation: 'view' | 'click' | 'close') {
|
||||||
|
sendMB('institutional-leavers-survey-notification', { type: segmentation })
|
||||||
|
}
|
||||||
|
|
||||||
export function LeaversSurveyAlert() {
|
export function LeaversSurveyAlert() {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
@ -20,13 +26,23 @@ export function LeaversSurveyAlert() {
|
||||||
function handleDismiss() {
|
function handleDismiss() {
|
||||||
setShowInstitutionalLeaversSurveyUntil(0)
|
setShowInstitutionalLeaversSurveyUntil(0)
|
||||||
setHide(true)
|
setHide(true)
|
||||||
|
sendMetrics('close')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Date.now() > showInstitutionalLeaversSurveyUntil) {
|
function handleLinkClick() {
|
||||||
return null
|
sendMetrics('click')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hide) {
|
const shouldDisplay =
|
||||||
|
!hide && Date.now() <= showInstitutionalLeaversSurveyUntil
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (shouldDisplay) {
|
||||||
|
sendMetrics('view')
|
||||||
|
}
|
||||||
|
}, [shouldDisplay])
|
||||||
|
|
||||||
|
if (!shouldDisplay) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +55,7 @@ export function LeaversSurveyAlert() {
|
||||||
href="https://docs.google.com/forms/d/e/1FAIpQLSfYdeeoY5p1d31r5iUx1jw0O-Gd66vcsBi_Ntu3lJRMjV2EJA/viewform"
|
href="https://docs.google.com/forms/d/e/1FAIpQLSfYdeeoY5p1d31r5iUx1jw0O-Gd66vcsBi_Ntu3lJRMjV2EJA/viewform"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
|
onClick={handleLinkClick}
|
||||||
>
|
>
|
||||||
{t('take_short_survey')}
|
{t('take_short_survey')}
|
||||||
</a>
|
</a>
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
import { expect } from 'chai'
|
import { expect } from 'chai'
|
||||||
|
import sinon from 'sinon'
|
||||||
import { fireEvent, screen, render } from '@testing-library/react'
|
import { fireEvent, screen, render } from '@testing-library/react'
|
||||||
import { UserEmailsProvider } from '../../../../../frontend/js/features/settings/context/user-email-context'
|
import { UserEmailsProvider } from '../../../../../frontend/js/features/settings/context/user-email-context'
|
||||||
import { LeaversSurveyAlert } from '../../../../../frontend/js/features/settings/components/leavers-survey-alert'
|
import { LeaversSurveyAlert } from '../../../../../frontend/js/features/settings/components/leavers-survey-alert'
|
||||||
|
import * as eventTracking from '../../../../../frontend/js/infrastructure/event-tracking'
|
||||||
import localStorage from '../../../../../frontend/js/infrastructure/local-storage'
|
import localStorage from '../../../../../frontend/js/infrastructure/local-storage'
|
||||||
|
|
||||||
function renderWithProvider() {
|
function renderWithProvider() {
|
||||||
|
@ -52,4 +54,47 @@ describe('<LeaversSurveyAlert/>', function () {
|
||||||
expect(localStorage.getItem('showInstitutionalLeaversSurveyUntil')).to.be
|
expect(localStorage.getItem('showInstitutionalLeaversSurveyUntil')).to.be
|
||||||
.null
|
.null
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('event tracking', function () {
|
||||||
|
let sendMBSpy
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
sendMBSpy = sinon.spy(eventTracking, 'sendMB')
|
||||||
|
const tomorrow = Date.now() + 1000 * 60 * 60 * 24
|
||||||
|
localStorage.setItem('showInstitutionalLeaversSurveyUntil', tomorrow)
|
||||||
|
localStorage.setItem('hideInstitutionalLeaversSurvey', false)
|
||||||
|
renderWithProvider()
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(function () {
|
||||||
|
sendMBSpy.restore()
|
||||||
|
localStorage.clear()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should sent a `view` event on load', function () {
|
||||||
|
expect(sendMBSpy).to.be.calledOnce
|
||||||
|
expect(sendMBSpy).calledWith(
|
||||||
|
'institutional-leavers-survey-notification',
|
||||||
|
{ type: 'view' }
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should sent a `click` event when the link is clicked', function () {
|
||||||
|
fireEvent.click(screen.getByRole('link'))
|
||||||
|
expect(sendMBSpy).to.be.calledTwice
|
||||||
|
expect(sendMBSpy).calledWith(
|
||||||
|
'institutional-leavers-survey-notification',
|
||||||
|
{ type: 'click' }
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should sent a `close` event when it is closed', function () {
|
||||||
|
fireEvent.click(screen.getByRole('button'))
|
||||||
|
expect(sendMBSpy).to.be.calledTwice
|
||||||
|
expect(sendMBSpy).calledWith(
|
||||||
|
'institutional-leavers-survey-notification',
|
||||||
|
{ type: 'close' }
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue