Skip to content

Commit

Permalink
Mes-9450: rekey reason cp (#1546)
Browse files Browse the repository at this point in the history
* GA4 analytics for rekey reason

* add test, fix screen name issue
  • Loading branch information
andrewsetterfield authored Apr 8, 2024
1 parent bb2c83d commit 4ef7a1b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { TestCategory } from '@dvsa/mes-test-schema/category-definitions/common/

import { AnalyticsProvider } from '@providers/analytics/analytics';
import { AnalyticsProviderMock } from '@providers/analytics/__mocks__/analytics.mock';
import { AnalyticsScreenNames } from '@providers/analytics/analytics.model';
import { AnalyticsScreenNames, GoogleAnalyticsEventPrefix } from '@providers/analytics/analytics.model';
import { AnalyticRecorded } from '@providers/analytics/analytics.actions';
import { testsReducer } from '@store/tests/tests.reducer';
import { StoreModel } from '@shared/models/store.model';
Expand All @@ -17,6 +17,8 @@ import { AppConfigProvider } from '@providers/app-config/app-config';
import { AppConfigProviderMock } from '@providers/app-config/__mocks__/app-config.mock';
import * as rekeyReasonActions from '../rekey-reason.actions';
import { RekeyReasonAnalyticsEffects } from '../rekey-reason.analytics.effects';
import * as fakeJournalActions from '@pages/fake-journal/fake-journal.actions';
import { end2endPracticeSlotId } from '@shared/mocks/test-slot-ids.mock';

describe('RekeyReasonAnalyticsEffects', () => {
let effects: RekeyReasonAnalyticsEffects;
Expand Down Expand Up @@ -66,8 +68,33 @@ describe('RekeyReasonAnalyticsEffects', () => {
effects.rekeyReasonViewDidEnter$.subscribe((result) => {
expect(result.type === AnalyticRecorded.type)
.toBe(true);

// TODO - MES-9495 - remove old analytics
expect(analyticsProviderMock.setCurrentPage)
.toHaveBeenCalledWith(screenName);

// GA4 Analytics
expect(analyticsProviderMock.setGACurrentPage)
.toHaveBeenCalledWith(screenName);
done();
});
});

it('should call setCurrentPage with pass and practice mode prefix', (done) => {
// ARRANGE
store$.dispatch(testsActions.StartTest(123, TestCategory.B));
store$.dispatch(fakeJournalActions.StartE2EPracticeTest(end2endPracticeSlotId));
store$.dispatch(candidateActions.PopulateCandidateDetails(candidateMock));
// ACT
actions$.next(rekeyReasonActions.RekeyReasonViewDidEnter());
// ASSERT
effects.rekeyReasonViewDidEnter$.subscribe((result) => {
expect(result.type === AnalyticRecorded.type)
.toBe(true);

// GA4 Analytics
expect(analyticsProviderMock.setGACurrentPage)
.toHaveBeenCalledWith(`${GoogleAnalyticsEventPrefix.PRACTICE_MODE}_${screenName}`);
done();
});
});
Expand All @@ -84,8 +111,14 @@ describe('RekeyReasonAnalyticsEffects', () => {
effects.rekeyReasonUploadTest$.subscribe((result) => {
expect(result.type === AnalyticRecorded.type)
.toBe(true);

// TODO - MES-9495 - remove old analytics
expect(analyticsProviderMock.logEvent)
.toHaveBeenCalled();

// GA4 Analytics
expect(analyticsProviderMock.logGAEvent)
.toHaveBeenCalled();
done();
});
});
Expand Down
19 changes: 17 additions & 2 deletions src/app/pages/rekey-reason/rekey-reason.analytics.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
AnalyticsDimensionIndices,
AnalyticsEventCategories,
AnalyticsEvents,
AnalyticsScreenNames,
AnalyticsScreenNames, GoogleAnalyticsEvents, GoogleAnalyticsEventsTitles,
} from '@providers/analytics/analytics.model';
import { select, Store } from '@ngrx/store';
import { StoreModel } from '@shared/models/store.model';
Expand All @@ -17,7 +17,7 @@ import {
getCurrentTest, getJournalData, isPracticeMode,
} from '@store/tests/tests.selector';
import { of } from 'rxjs';
import { formatAnalyticsText } from '@shared/helpers/format-analytics-text';
import { analyticsEventTypePrefix, formatAnalyticsText } from '@shared/helpers/format-analytics-text';
import { TestsModel } from '@store/tests/tests.model';
import { AnalyticRecorded } from '@providers/analytics/analytics.actions';
import { getCandidate } from '@store/tests/journal-data/common/candidate/candidate.reducer';
Expand Down Expand Up @@ -78,10 +78,18 @@ export class RekeyReasonAnalyticsEffects {
[, tests, candidateId, applicationReference]:
[ReturnType<typeof RekeyReasonViewDidEnter>, TestsModel, number, string, boolean],
) => {

// TODO - MES-9495 - remove old analytics
const screenName = formatAnalyticsText(AnalyticsScreenNames.REKEY_REASON, tests);
this.analytics.addCustomDimension(AnalyticsDimensionIndices.CANDIDATE_ID, `${candidateId}`);
this.analytics.addCustomDimension(AnalyticsDimensionIndices.APPLICATION_REFERENCE, applicationReference);
this.analytics.setCurrentPage(screenName);

// GA4 Analytics
this.analytics.setGACurrentPage(analyticsEventTypePrefix(AnalyticsScreenNames.REKEY_REASON, tests));
this.analytics.addGACustomDimension(AnalyticsDimensionIndices.CANDIDATE_ID, `${candidateId}`);
this.analytics.addGACustomDimension(AnalyticsDimensionIndices.APPLICATION_REFERENCE, applicationReference);

return of(AnalyticRecorded());
}),
));
Expand Down Expand Up @@ -113,12 +121,19 @@ export class RekeyReasonAnalyticsEffects {
[ReturnType<typeof RekeyUploadTest>, string, TestsModel, boolean],
) => {


this.analytics.logEvent(
formatAnalyticsText(AnalyticsEventCategories.POST_TEST, tests),
formatAnalyticsText(AnalyticsEvents.CONFIRM_UPLOAD, tests),
formatAnalyticsText(`Upload confirmed - ${testOutcome}`, tests),
);

// GA4 Analytics
this.analytics.logGAEvent(
analyticsEventTypePrefix(GoogleAnalyticsEvents.SUBMIT_TEST, tests),
GoogleAnalyticsEventsTitles.RESULT,
testOutcome,
);
return of(AnalyticRecorded());
}),
));
Expand Down
1 change: 1 addition & 0 deletions src/app/providers/analytics/analytics.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ export enum GoogleAnalyticsEvents {
COMPLETED_TEST_SEARCH = 'completed_test_search',
LDTM_SEARCH = 'ldtm_search',
SUBMIT_FORM_ERROR = 'submit_form_error',
SUBMIT_TEST = 'submit_test',
VALIDATION_ERROR = 'validation_error',
CANDIDATE_RECEIVE_TEST_RESULTS = 'send_candidate_test_results',
SET_D255 = 'set_d255',
Expand Down

0 comments on commit 4ef7a1b

Please sign in to comment.