Merge pull request #17129 from mozilla/fxa-9564

fix(metrics): always use the metrics flow data in `Metrics` model when redirecting in third party auth
This commit is contained in:
Vijay Budhram 2024-06-17 11:45:44 -04:00 коммит произвёл GitHub
Родитель 3f183283a0 152be5bed3
Коммит 566c8ef9a1
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
3 изменённых файлов: 30 добавлений и 2 удалений

Просмотреть файл

@ -73,6 +73,14 @@ export default {
// We stash originating location in the Google state oauth param
// because we will need it to use it to log the user into FxA
const currentParams = new URLSearchParams(this.window.location.search);
if (this.metrics) {
const metrics = this.metrics.getFlowEventMetadata();
currentParams.append('flowId', metrics.flowId);
currentParams.append('flowBeginTime', metrics.flowBeginTime);
currentParams.append('deviceId', metrics.deviceId);
}
currentParams.delete('deeplink');
const state = encodeURIComponent(
@ -121,6 +129,14 @@ export default {
this.logFlowEvent('apple.oauth-start');
const currentParams = new URLSearchParams(this.window.location.search);
if (this.metrics) {
const metrics = this.metrics.getFlowEventMetadata();
currentParams.append('flowId', metrics.flowId);
currentParams.append('flowBeginTime', metrics.flowBeginTime);
currentParams.append('deviceId', metrics.deviceId);
}
currentParams.delete('deeplink');
const state = encodeURIComponent(

Просмотреть файл

@ -78,6 +78,11 @@ describe('views/mixins/third-party-auth-mixin', function () {
user,
});
sinon.spy(notifier, 'trigger');
sinon.stub(metrics, 'getFlowEventMetadata').callsFake(() => ({
flowId: '123',
flowBeginTime: '456',
deviceId: '789',
}));
await view.render();
});
@ -146,6 +151,8 @@ describe('views/mixins/third-party-auth-mixin', function () {
assert.isTrue(view.logFlowEvent.calledWith('google.oauth-start'));
assert.isTrue(metrics.getFlowEventMetadata.calledOnce);
assert.isTrue(mockForm.setAttribute.calledWith('method', 'GET'));
assert.isTrue(
mockForm.setAttribute.calledWith(
@ -167,7 +174,7 @@ describe('views/mixins/third-party-auth-mixin', function () {
mockInput,
'state',
encodeURIComponent(
`${windowMock.location.origin}${windowMock.location.pathname}?`
`${windowMock.location.origin}${windowMock.location.pathname}?flowId=123&flowBeginTime=456&deviceId=789`
)
);
assertInputEl(mockInput, 'access_type', 'offline');
@ -189,6 +196,8 @@ describe('views/mixins/third-party-auth-mixin', function () {
assert.isTrue(view.logFlowEvent.calledWith('apple.oauth-start'));
assert.isTrue(metrics.getFlowEventMetadata.calledOnce);
assert.isTrue(mockForm.setAttribute.calledWith('method', 'GET'));
assert.isTrue(
mockForm.setAttribute.calledWith(
@ -210,7 +219,7 @@ describe('views/mixins/third-party-auth-mixin', function () {
mockInput,
'state',
encodeURIComponent(
`${windowMock.location.origin}${windowMock.location.pathname}?`
`${windowMock.location.origin}${windowMock.location.pathname}?flowId=123&flowBeginTime=456&deviceId=789`
)
);
assertInputEl(mockInput, 'access_type', 'offline');

Просмотреть файл

@ -10,6 +10,7 @@ import { ReactComponent as AppleLogo } from './apple-logo.svg';
import { useConfig } from '../../models';
import { ReactElement } from 'react-markdown/lib/react-markdown';
import { useMetrics } from '../../lib/metrics';
export type ThirdPartyAuthProps = {
onContinueWithGoogle?: FormEventHandler<HTMLFormElement>;
@ -125,9 +126,11 @@ const ThirdPartySignInForm = ({
buttonText: ReactElement;
onSubmit?: FormEventHandler<HTMLFormElement>;
}) => {
const { logViewEventOnce } = useMetrics();
const stateRef = useRef<HTMLInputElement>(null);
function onClick() {
logViewEventOnce(`flow.${party}`, 'oauth-start');
stateRef.current!.value = getState();
}