Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mes 9344 vehicle checks ga4 #1518

Merged
merged 5 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { provideMockActions } from '@ngrx/effects/testing';
import * as testsActions from '@store/tests/tests.actions';
import { TestCategory } from '@dvsa/mes-test-schema/category-definitions/common/test-category';
import { AnalyticRecorded } from '@providers/analytics/analytics.actions';
import { AnalyticsEventCategories, AnalyticsScreenNames } from '@providers/analytics/analytics.model';
import {
AnalyticsEventCategories,
AnalyticsScreenNames,
GoogleAnalyticsEvents, GoogleAnalyticsEventsTitles, GoogleAnalyticsEventsValues,
} from '@providers/analytics/analytics.model';
import * as SafetyAndBalanceQuestionsActions
from '@store/tests/test-data/cat-a-mod2/safety-and-balance/safety-and-balance.cat-a-mod2.actions';
import {
Expand Down Expand Up @@ -55,6 +59,7 @@ describe('VehicleChecksModalCatAMod2AnalyticsEffects', () => {
effects.vehicleChecksModalViewDidEnter$.subscribe((result) => {
expect(result.type === AnalyticRecorded.type).toBe(true);
expect(analyticsProviderMock.setCurrentPage).toHaveBeenCalledWith(screenName);
expect(analyticsProviderMock.setGACurrentPage).toHaveBeenCalledWith(screenName);
done();
});
});
Expand All @@ -75,6 +80,11 @@ describe('VehicleChecksModalCatAMod2AnalyticsEffects', () => {
`safety question ${questionNumber + 1} changed`,
safetyQuestion.code,
);
expect(analyticsProviderMock.logGAEvent).toHaveBeenCalledWith(
(GoogleAnalyticsEvents.SAFETY_QUESTION + '2'),
GoogleAnalyticsEventsTitles.QUESTION_NUMBER,
safetyQuestion.code,
);
done();
});
});
Expand All @@ -93,6 +103,11 @@ describe('VehicleChecksModalCatAMod2AnalyticsEffects', () => {
`safety question ${questionNumber + 1} outcome changed`,
'correct',
);
expect(analyticsProviderMock.logGAEvent).toHaveBeenCalledWith(
(GoogleAnalyticsEvents.SAFETY_QUESTION + '2'),
GoogleAnalyticsEventsTitles.RESULT,
GoogleAnalyticsEventsValues.CORRECT,
);
done();
});
});
Expand All @@ -113,12 +128,17 @@ describe('VehicleChecksModalCatAMod2AnalyticsEffects', () => {
`balance question ${questionNumber + 1} changed`,
balanceQuestion.code,
);
expect(analyticsProviderMock.logGAEvent).toHaveBeenCalledWith(
(GoogleAnalyticsEvents.BALANCE_QUESTION + '2'),
GoogleAnalyticsEventsTitles.QUESTION_NUMBER,
balanceQuestion.code,
);
done();
});
});
});

describe('balanceQuestionOutComeChanged$', () => {
describe('balanceQuestionOutcomeChanged$', () => {
const questionOutcome: QuestionOutcome = 'DF';
const questionNumber: number = 1;
it('should log an analytics event with balance question outcome info', (done) => {
Expand All @@ -131,6 +151,11 @@ describe('VehicleChecksModalCatAMod2AnalyticsEffects', () => {
`balance question ${questionNumber + 1} outcome changed`,
'driving fault',
);
expect(analyticsProviderMock.logGAEvent).toHaveBeenCalledWith(
(GoogleAnalyticsEvents.BALANCE_QUESTION + '2'),
GoogleAnalyticsEventsTitles.RESULT,
GoogleAnalyticsEventsValues.DRIVING_FAULT,
);
done();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Actions, createEffect, ofType } from '@ngrx/effects';
import { concatMap, switchMap, withLatestFrom } from 'rxjs/operators';
import {
AnalyticsEventCategories,
AnalyticsScreenNames,
AnalyticsScreenNames, GoogleAnalyticsEvents, GoogleAnalyticsEventsTitles, GoogleAnalyticsEventsValues,
} from '@providers/analytics/analytics.model';
import { AnalyticRecorded } from '@providers/analytics/analytics.actions';
import { AnalyticsProvider } from '@providers/analytics/analytics';
Expand Down Expand Up @@ -43,9 +43,14 @@ export class VehicleChecksModalCatAMod2AnalyticsEffects {
),
)),
switchMap(([, tests]: [ReturnType<typeof VehicleChecksViewDidEnter>, TestsModel]) => {
// TODO - MES-9495 - remove old analytics
this.analytics.setCurrentPage(
formatAnalyticsText(AnalyticsScreenNames.VEHICLE_CHECKS, tests),
);
// GA4 Analytics
this.analytics.setGACurrentPage(
formatAnalyticsText(AnalyticsScreenNames.VEHICLE_CHECKS, tests),
);
return of(AnalyticRecorded());
}),
));
Expand All @@ -60,12 +65,19 @@ export class VehicleChecksModalCatAMod2AnalyticsEffects {
),
)),
switchMap(([action, tests]: [ReturnType<typeof SafetyQuestionSelected>, TestsModel]) => {
// TODO - MES-9495 - remove old analytics
const eventText = `safety question ${action.index + 1} changed`;
this.analytics.logEvent(
formatAnalyticsText(AnalyticsEventCategories.VEHICLE_CHECKS, tests),
eventText,
action.safetyQuestion.code,
);
// GA4 Analytics
this.analytics.logGAEvent(
(GoogleAnalyticsEvents.SAFETY_QUESTION + (action.index + 1)),
GoogleAnalyticsEventsTitles.QUESTION_NUMBER,
action.safetyQuestion.code,
);
return of(AnalyticRecorded());
}),
));
Expand All @@ -80,13 +92,21 @@ export class VehicleChecksModalCatAMod2AnalyticsEffects {
),
)),
switchMap(([action, tests]: [ReturnType<typeof SafetyQuestionOutcomeChanged>, TestsModel]) => {
// TODO - MES-9495 - remove old analytics
const eventText = `safety question ${action.index + 1} outcome changed`;
const outComeText = action.safetyQuestionOutcome === 'P' ? 'correct' : 'driving fault';
this.analytics.logEvent(
formatAnalyticsText(AnalyticsEventCategories.VEHICLE_CHECKS, tests),
eventText,
outComeText,
);
// GA4 Analytics
this.analytics.logGAEvent(
(GoogleAnalyticsEvents.SAFETY_QUESTION + (action.index + 1)),
GoogleAnalyticsEventsTitles.RESULT,
action.safetyQuestionOutcome === 'P' ?
GoogleAnalyticsEventsValues.CORRECT : GoogleAnalyticsEventsValues.DRIVING_FAULT,
);
return of(AnalyticRecorded());
}),
));
Expand All @@ -101,12 +121,19 @@ export class VehicleChecksModalCatAMod2AnalyticsEffects {
),
)),
switchMap(([action, tests]: [ReturnType<typeof BalanceQuestionSelected>, TestsModel]) => {
// TODO - MES-9495 - remove old analytics
const eventText = `balance question ${action.index + 1} changed`;
this.analytics.logEvent(
formatAnalyticsText(AnalyticsEventCategories.VEHICLE_CHECKS, tests),
eventText,
action.balanceQuestion.code,
);
// GA4 Analytics
this.analytics.logGAEvent(
(GoogleAnalyticsEvents.BALANCE_QUESTION + (action.index + 1)),
GoogleAnalyticsEventsTitles.QUESTION_NUMBER,
action.balanceQuestion.code,
);
return of(AnalyticRecorded());
}),
));
Expand All @@ -121,13 +148,21 @@ export class VehicleChecksModalCatAMod2AnalyticsEffects {
),
)),
switchMap(([action, tests]: [ReturnType<typeof BalanceQuestionOutcomeChanged>, TestsModel]) => {
// TODO - MES-9495 - remove old analytics
const eventText = `balance question ${action.index + 1} outcome changed`;
const outComeText = action.balanceQuestionOutcome === 'P' ? 'correct' : 'driving fault';
this.analytics.logEvent(
formatAnalyticsText(AnalyticsEventCategories.VEHICLE_CHECKS, tests),
eventText,
outComeText,
);
// GA4 Analytics
this.analytics.logGAEvent(
(GoogleAnalyticsEvents.BALANCE_QUESTION + (action.index + 1)),
GoogleAnalyticsEventsTitles.RESULT,
action.balanceQuestionOutcome === 'P' ?
GoogleAnalyticsEventsValues.CORRECT : GoogleAnalyticsEventsValues.DRIVING_FAULT,
);
return of(AnalyticRecorded());
}),
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import { provideMockActions } from '@ngrx/effects/testing';
import * as testsActions from '@store/tests/tests.actions';
import { TestCategory } from '@dvsa/mes-test-schema/category-definitions/common/test-category';
import { AnalyticRecorded } from '@providers/analytics/analytics.actions';
import { AnalyticsEventCategories, AnalyticsScreenNames } from '@providers/analytics/analytics.model';
import {
AnalyticsEventCategories,
AnalyticsScreenNames,
GoogleAnalyticsEvents,
GoogleAnalyticsEventsTitles,
GoogleAnalyticsEventsValues,
} from '@providers/analytics/analytics.model';
import * as VehicleChecksActions
from '@store/tests/test-data/cat-adi-part2/vehicle-checks/vehicle-checks.cat-adi-part2.action';
import {
Expand Down Expand Up @@ -55,13 +61,14 @@ describe('VehicleChecksModalAnalyticsEffects', () => {
effects.vehicleChecksModalViewDidEnter$.subscribe((result) => {
expect(result.type === AnalyticRecorded.type).toBe(true);
expect(analyticsProviderMock.setCurrentPage).toHaveBeenCalledWith(screenName);
expect(analyticsProviderMock.setGACurrentPage).toHaveBeenCalledWith(screenName);
done();
});
});
});

describe('tellMeQuestionChanged$ effect', () => {
const questionNumber: number = 1;
const questionNumber: number = 0;
const tellMeQuestion: QuestionResult = {
code: 'T1',
};
Expand All @@ -75,14 +82,19 @@ describe('VehicleChecksModalAnalyticsEffects', () => {
`tell me question ${questionNumber + 1} changed`,
tellMeQuestion.code,
);
expect(analyticsProviderMock.logGAEvent).toHaveBeenCalledWith(
(GoogleAnalyticsEvents.TELL_ME_QUESTION + '1'),
GoogleAnalyticsEventsTitles.QUESTION_NUMBER,
tellMeQuestion.code,
);
done();
});
});
});

describe('tellMeQuestionOutComeChanged$', () => {
const questionOutcome: QuestionOutcome = 'DF';
const questionNumber: number = 1;
const questionNumber: number = 0;
it('should log an analytics event with tell me question outcome info', (done) => {
store$.dispatch(testsActions.StartTest(12345, TestCategory.ADI2));
actions$.next(VehicleChecksActions.TellMeQuestionOutcomeChanged(questionOutcome, questionNumber));
Expand All @@ -93,6 +105,11 @@ describe('VehicleChecksModalAnalyticsEffects', () => {
`tell me question ${questionNumber + 1} outcome changed`,
'driving fault',
);
expect(analyticsProviderMock.logGAEvent).toHaveBeenCalledWith(
(GoogleAnalyticsEvents.TELL_ME_QUESTION + '1'),
GoogleAnalyticsEventsTitles.RESULT,
GoogleAnalyticsEventsValues.DRIVING_FAULT,
);
done();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { concatMap, switchMap, withLatestFrom } from 'rxjs/operators';
import {
AnalyticsEventCategories,
AnalyticsScreenNames,
GoogleAnalyticsEvents,
GoogleAnalyticsEventsTitles,
GoogleAnalyticsEventsValues,
} from '@providers/analytics/analytics.model';
import { AnalyticRecorded } from '@providers/analytics/analytics.actions';
import { AnalyticsProvider } from '@providers/analytics/analytics';
Expand Down Expand Up @@ -41,9 +44,14 @@ export class VehicleChecksModalAnalyticsEffects {
),
)),
switchMap(([, tests]: [ReturnType<typeof VehicleChecksViewDidEnter>, TestsModel]) => {
// TODO - MES-9495 - remove old analytics
this.analytics.setCurrentPage(
formatAnalyticsText(AnalyticsScreenNames.VEHICLE_CHECKS, tests),
);
// GA4 Analytics
this.analytics.setGACurrentPage(
formatAnalyticsText(AnalyticsScreenNames.VEHICLE_CHECKS, tests),
);
return of(AnalyticRecorded());
}),
));
Expand All @@ -58,12 +66,19 @@ export class VehicleChecksModalAnalyticsEffects {
),
)),
switchMap(([action, tests]: [ReturnType<typeof TellMeQuestionSelected>, TestsModel]) => {
// TODO - MES-9495 - remove old analytics
const eventText = `tell me question ${action.index + 1} changed`;
this.analytics.logEvent(
formatAnalyticsText(AnalyticsEventCategories.VEHICLE_CHECKS, tests),
eventText,
action.tellMeQuestion.code,
);
// GA4 Analytics
this.analytics.logGAEvent(
(GoogleAnalyticsEvents.TELL_ME_QUESTION + (action.index + 1)),
GoogleAnalyticsEventsTitles.QUESTION_NUMBER,
action.tellMeQuestion.code,
);
return of(AnalyticRecorded());
}),
));
Expand All @@ -78,13 +93,22 @@ export class VehicleChecksModalAnalyticsEffects {
),
)),
switchMap(([action, tests]: [ReturnType<typeof TellMeQuestionOutcomeChanged>, TestsModel]) => {
// TODO - MES-9495 - remove old analytics
const eventText = `tell me question ${action.index + 1} outcome changed`;
const outComeText = action.tellMeQuestionOutcome === 'P' ? 'correct' : 'driving fault';
this.analytics.logEvent(
formatAnalyticsText(AnalyticsEventCategories.VEHICLE_CHECKS, tests),
eventText,
outComeText,
);

// GA4 Analytics
this.analytics.logGAEvent(
(GoogleAnalyticsEvents.TELL_ME_QUESTION + (action.index + 1)),
GoogleAnalyticsEventsTitles.RESULT,
action.tellMeQuestionOutcome === 'P' ?
GoogleAnalyticsEventsValues.CORRECT : GoogleAnalyticsEventsValues.DRIVING_FAULT,
);
return of(AnalyticRecorded());
}),
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { provideMockActions } from '@ngrx/effects/testing';
import * as testsActions from '@store/tests/tests.actions';
import { TestCategory } from '@dvsa/mes-test-schema/category-definitions/common/test-category';
import { AnalyticRecorded } from '@providers/analytics/analytics.actions';
import { AnalyticsEventCategories, AnalyticsScreenNames } from '@providers/analytics/analytics.model';
import {
AnalyticsEventCategories,
AnalyticsScreenNames,
GoogleAnalyticsEvents, GoogleAnalyticsEventsTitles, GoogleAnalyticsEventsValues,
} from '@providers/analytics/analytics.model';
import * as VehicleChecksActions from '@store/tests/test-data/cat-c/vehicle-checks/vehicle-checks.cat-c.action';
import { QuestionOutcome, QuestionResult } from '@dvsa/mes-test-schema/categories/common';
import { VehicleChecksViewDidEnter } from '../vehicle-checks-modal.cat-c.actions';
Expand Down Expand Up @@ -56,6 +60,8 @@ describe('VehicleChecksModalCatCAnalyticsEffects', () => {
.toBe(true);
expect(analyticsProviderMock.setCurrentPage)
.toHaveBeenCalledWith(screenName);
expect(analyticsProviderMock.setGACurrentPage)
.toHaveBeenCalledWith(screenName);
done();
});
});
Expand All @@ -78,6 +84,11 @@ describe('VehicleChecksModalCatCAnalyticsEffects', () => {
`show me question ${questionNumber + 1} changed`,
showMeQuestion.code,
);
expect(analyticsProviderMock.logGAEvent).toHaveBeenCalledWith(
(GoogleAnalyticsEvents.SHOW_ME_QUESTION + '2'),
GoogleAnalyticsEventsTitles.QUESTION_NUMBER,
showMeQuestion.code,
);
done();
});
});
Expand All @@ -98,6 +109,11 @@ describe('VehicleChecksModalCatCAnalyticsEffects', () => {
`show me question ${questionNumber + 1} outcome changed`,
'correct',
);
expect(analyticsProviderMock.logGAEvent).toHaveBeenCalledWith(
(GoogleAnalyticsEvents.SHOW_ME_QUESTION + '2'),
GoogleAnalyticsEventsTitles.RESULT,
GoogleAnalyticsEventsValues.CORRECT,
);
done();
});
});
Expand All @@ -120,6 +136,11 @@ describe('VehicleChecksModalCatCAnalyticsEffects', () => {
`tell me question ${questionNumber + 1} changed`,
tellMeQuestion.code,
);
expect(analyticsProviderMock.logGAEvent).toHaveBeenCalledWith(
(GoogleAnalyticsEvents.TELL_ME_QUESTION + '2'),
GoogleAnalyticsEventsTitles.QUESTION_NUMBER,
tellMeQuestion.code,
);
done();
});
});
Expand All @@ -140,6 +161,11 @@ describe('VehicleChecksModalCatCAnalyticsEffects', () => {
`tell me question ${questionNumber + 1} outcome changed`,
'driving fault',
);
expect(analyticsProviderMock.logGAEvent).toHaveBeenCalledWith(
(GoogleAnalyticsEvents.TELL_ME_QUESTION + '2'),
GoogleAnalyticsEventsTitles.RESULT,
GoogleAnalyticsEventsValues.DRIVING_FAULT,
);
done();
});
});
Expand Down
Loading
Loading