Skip to content

Commit

Permalink
Mes-9489: custom analytics (#1578)
Browse files Browse the repository at this point in the history
* WIP

* removed unused code

* failing tests

* corrected tests
  • Loading branch information
andrewsetterfield authored Apr 22, 2024
1 parent 6a863fb commit ccdf206
Show file tree
Hide file tree
Showing 22 changed files with 224 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
AnalyticsDimensionIndices,
AnalyticsEventCategories,
AnalyticsEvents,
AnalyticsScreenNames,
AnalyticsScreenNames, GoogleAnalyticsCustomDimension,
GoogleAnalyticsEventPrefix,
GoogleAnalyticsEvents,
GoogleAnalyticsEventsTitles,
Expand Down Expand Up @@ -149,9 +149,9 @@ describe('BackToOfficeAnalyticsEffects', () => {

// GA4 Analytics
expect(analyticsProviderMock.addGACustomDimension)
.toHaveBeenCalledWith(AnalyticsDimensionIndices.CANDIDATE_ID, '1');
.toHaveBeenCalledWith(GoogleAnalyticsCustomDimension.CANDIDATE_ID, '1');
expect(analyticsProviderMock.addGACustomDimension)
.toHaveBeenCalledWith(AnalyticsDimensionIndices.APPLICATION_REFERENCE, '123456789');
.toHaveBeenCalledWith(GoogleAnalyticsCustomDimension.APPLICATION_REFERENCE, '123456789');
expect(analyticsProviderMock.logGAEvent)
.toHaveBeenCalledWith(
GoogleAnalyticsEvents.DEFER_WRITE_UP,
Expand Down Expand Up @@ -188,9 +188,9 @@ describe('BackToOfficeAnalyticsEffects', () => {

// GA4 Analytics
expect(analyticsProviderMock.addGACustomDimension)
.toHaveBeenCalledWith(AnalyticsDimensionIndices.CANDIDATE_ID, '1');
.toHaveBeenCalledWith(GoogleAnalyticsCustomDimension.CANDIDATE_ID, '1');
expect(analyticsProviderMock.addGACustomDimension)
.toHaveBeenCalledWith(AnalyticsDimensionIndices.APPLICATION_REFERENCE, '123456789');
.toHaveBeenCalledWith(GoogleAnalyticsCustomDimension.APPLICATION_REFERENCE, '123456789');
expect(analyticsProviderMock.logGAEvent)
.toHaveBeenCalledWith(
GoogleAnalyticsEvents.DEFER_WRITE_UP,
Expand Down Expand Up @@ -227,9 +227,9 @@ describe('BackToOfficeAnalyticsEffects', () => {

// GA4 Analytics
expect(analyticsProviderMock.addGACustomDimension)
.toHaveBeenCalledWith(AnalyticsDimensionIndices.CANDIDATE_ID, '1');
.toHaveBeenCalledWith(GoogleAnalyticsCustomDimension.CANDIDATE_ID, '1');
expect(analyticsProviderMock.addGACustomDimension)
.toHaveBeenCalledWith(AnalyticsDimensionIndices.APPLICATION_REFERENCE, '123456789');
.toHaveBeenCalledWith(GoogleAnalyticsCustomDimension.APPLICATION_REFERENCE, '123456789');
expect(analyticsProviderMock.logGAEvent)
.toHaveBeenCalledWith(
`${GoogleAnalyticsEventPrefix.PRACTICE_MODE}_${GoogleAnalyticsEvents.DEFER_WRITE_UP}`,
Expand Down Expand Up @@ -266,9 +266,9 @@ describe('BackToOfficeAnalyticsEffects', () => {

// GA4 Analytics
expect(analyticsProviderMock.addGACustomDimension)
.toHaveBeenCalledWith(AnalyticsDimensionIndices.CANDIDATE_ID, '1');
.toHaveBeenCalledWith(GoogleAnalyticsCustomDimension.CANDIDATE_ID, '1');
expect(analyticsProviderMock.addGACustomDimension)
.toHaveBeenCalledWith(AnalyticsDimensionIndices.APPLICATION_REFERENCE, '123456789');
.toHaveBeenCalledWith(GoogleAnalyticsCustomDimension.APPLICATION_REFERENCE, '123456789');
expect(analyticsProviderMock.logGAEvent)
.toHaveBeenCalledWith(
`${GoogleAnalyticsEventPrefix.PRACTICE_MODE}_${GoogleAnalyticsEvents.DEFER_WRITE_UP}`,
Expand Down
12 changes: 9 additions & 3 deletions src/app/pages/back-to-office/back-to-office.analytics.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import {
AnalyticsDimensionIndices,
AnalyticsEventCategories,
AnalyticsEvents,
AnalyticsScreenNames, GoogleAnalyticsEvents, GoogleAnalyticsEventsTitles, GoogleAnalyticsEventsValues,
AnalyticsScreenNames,
GoogleAnalyticsCustomDimension,
GoogleAnalyticsEvents,
GoogleAnalyticsEventsTitles,
GoogleAnalyticsEventsValues,
} from '@providers/analytics/analytics.model';
import { select, Store } from '@ngrx/store';
import { StoreModel } from '@shared/models/store.model';
Expand Down Expand Up @@ -120,8 +124,10 @@ export class BackToOfficeAnalyticsEffects {
);

//GA4 Analytics
this.analytics.addGACustomDimension(AnalyticsDimensionIndices.CANDIDATE_ID, `${candidateId}`);
this.analytics.addGACustomDimension(AnalyticsDimensionIndices.APPLICATION_REFERENCE, applicationReference);
this.analytics.addGACustomDimension(GoogleAnalyticsCustomDimension.CANDIDATE_ID, `${candidateId}`);
this.analytics.addGACustomDimension(
GoogleAnalyticsCustomDimension.APPLICATION_REFERENCE, applicationReference
);

this.analytics.logGAEvent(
analyticsEventTypePrefix(GoogleAnalyticsEvents.DEFER_WRITE_UP, tests),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
AnalyticsDimensionIndices,
AnalyticsEventCategories,
AnalyticsEvents,
AnalyticsScreenNames, GoogleAnalyticsEvents, GoogleAnalyticsEventsTitles,
AnalyticsScreenNames, GoogleAnalyticsCustomDimension, GoogleAnalyticsEvents, GoogleAnalyticsEventsTitles,
} from '@providers/analytics/analytics.model';
import { AnalyticRecorded } from '@providers/analytics/analytics.actions';
import { StoreModel } from '@shared/models/store.model';
Expand Down Expand Up @@ -100,11 +100,11 @@ describe('CandidateDetailsAnalyticsEffects', () => {
expect(analyticsProviderMock.setGACurrentPage)
.toHaveBeenCalledWith(screenName);
expect(analyticsProviderMock.addGACustomDimension)
.toHaveBeenCalledWith(AnalyticsDimensionIndices.CANDIDATE_ID, '123');
.toHaveBeenCalledWith(GoogleAnalyticsCustomDimension.CANDIDATE_ID, '123');
expect(analyticsProviderMock.addGACustomDimension)
.toHaveBeenCalledWith(AnalyticsDimensionIndices.CANDIDATE_WITH_SPECIAL_NEEDS, '1');
.toHaveBeenCalledWith(GoogleAnalyticsCustomDimension.CANDIDATE_WITH_SPECIAL_NEEDS, '1');
expect(analyticsProviderMock.addGACustomDimension)
.toHaveBeenCalledWith(AnalyticsDimensionIndices.CANDIDATE_WITH_CHECK, '1');
.toHaveBeenCalledWith(GoogleAnalyticsCustomDimension.CANDIDATE_WITH_CHECK, '1');
done();
});
});
Expand Down Expand Up @@ -134,11 +134,11 @@ describe('CandidateDetailsAnalyticsEffects', () => {
expect(analyticsProviderMock.setGACurrentPage)
.toHaveBeenCalledWith(AnalyticsScreenNames.JOURNAL);
expect(analyticsProviderMock.addGACustomDimension)
.toHaveBeenCalledWith(AnalyticsDimensionIndices.CANDIDATE_ID, null);
.toHaveBeenCalledWith(GoogleAnalyticsCustomDimension.CANDIDATE_ID, null);
expect(analyticsProviderMock.addGACustomDimension)
.toHaveBeenCalledWith(AnalyticsDimensionIndices.CANDIDATE_WITH_SPECIAL_NEEDS, null);
.toHaveBeenCalledWith(GoogleAnalyticsCustomDimension.CANDIDATE_WITH_SPECIAL_NEEDS, null);
expect(analyticsProviderMock.addGACustomDimension)
.toHaveBeenCalledWith(AnalyticsDimensionIndices.CANDIDATE_WITH_CHECK, null);
.toHaveBeenCalledWith(GoogleAnalyticsCustomDimension.CANDIDATE_WITH_CHECK, null);
done();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
AnalyticsDimensionIndices,
AnalyticsEventCategories,
AnalyticsEvents,
AnalyticsScreenNames,
AnalyticsScreenNames, GoogleAnalyticsCustomDimension,
GoogleAnalyticsEvents,
GoogleAnalyticsEventsTitles,
} from '@providers/analytics/analytics.model';
Expand Down Expand Up @@ -69,10 +69,13 @@ export class CandidateDetailsAnalyticsEffects {

// GA4 Analytics
this.analytics.setGACurrentPage(AnalyticsScreenNames.CANDIDATE_DETAILS);
this.analytics.addGACustomDimension(AnalyticsDimensionIndices.CANDIDATE_ID, candidateId?.toString());
this.analytics.addGACustomDimension(AnalyticsDimensionIndices.CANDIDATE_WITH_SPECIAL_NEEDS,
specNeeds ? '1' : '0');
this.analytics.addGACustomDimension(AnalyticsDimensionIndices.CANDIDATE_WITH_CHECK, candidateCheck ? '1' : '0');
this.analytics.addGACustomDimension(GoogleAnalyticsCustomDimension.CANDIDATE_ID, candidateId?.toString());
this.analytics.addGACustomDimension(GoogleAnalyticsCustomDimension.CANDIDATE_WITH_SPECIAL_NEEDS,
specNeeds ? '1' : '0'
);
this.analytics.addGACustomDimension(GoogleAnalyticsCustomDimension.CANDIDATE_WITH_CHECK,
candidateCheck ? '1' : '0'
);

return of(AnalyticRecorded());
}),
Expand Down Expand Up @@ -102,9 +105,9 @@ export class CandidateDetailsAnalyticsEffects {

// GA4 Analytics
this.analytics.setGACurrentPage(mapAnalyticsScreenName(sourcePage));
this.analytics.addGACustomDimension(AnalyticsDimensionIndices.CANDIDATE_ID, null);
this.analytics.addGACustomDimension(AnalyticsDimensionIndices.CANDIDATE_WITH_SPECIAL_NEEDS, null);
this.analytics.addGACustomDimension(AnalyticsDimensionIndices.CANDIDATE_WITH_CHECK, null);
this.analytics.addGACustomDimension(GoogleAnalyticsCustomDimension.CANDIDATE_ID, null);
this.analytics.addGACustomDimension(GoogleAnalyticsCustomDimension.CANDIDATE_WITH_SPECIAL_NEEDS, null);
this.analytics.addGACustomDimension(GoogleAnalyticsCustomDimension.CANDIDATE_WITH_CHECK, null);

return of(AnalyticRecorded());
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
AnalyticsErrorTypes,
AnalyticsEventCategories,
AnalyticsEvents,
AnalyticsScreenNames,
AnalyticsScreenNames, GoogleAnalyticsCustomDimension,
GoogleAnalyticsEventPrefix,
GoogleAnalyticsEvents,
GoogleAnalyticsEventsTitles,
Expand Down Expand Up @@ -114,11 +114,11 @@ describe('CommunicationAnalyticsEffects', () => {
expect(analyticsProviderMock.setGACurrentPage)
.toHaveBeenCalledWith(screenName);
expect(analyticsProviderMock.addGACustomDimension)
.toHaveBeenCalledWith(AnalyticsDimensionIndices.TEST_CATEGORY, 'B');
.toHaveBeenCalledWith(GoogleAnalyticsCustomDimension.TEST_CATEGORY, 'B');
expect(analyticsProviderMock.addGACustomDimension)
.toHaveBeenCalledWith(AnalyticsDimensionIndices.CANDIDATE_ID, '1');
.toHaveBeenCalledWith(GoogleAnalyticsCustomDimension.CANDIDATE_ID, '1');
expect(analyticsProviderMock.addGACustomDimension)
.toHaveBeenCalledWith(AnalyticsDimensionIndices.APPLICATION_REFERENCE, '123456789');
.toHaveBeenCalledWith(GoogleAnalyticsCustomDimension.APPLICATION_REFERENCE, '123456789');
done();
});
});
Expand Down Expand Up @@ -147,11 +147,11 @@ describe('CommunicationAnalyticsEffects', () => {
expect(analyticsProviderMock.setGACurrentPage)
.toHaveBeenCalledWith(screenNamePM);
expect(analyticsProviderMock.addGACustomDimension)
.toHaveBeenCalledWith(AnalyticsDimensionIndices.TEST_CATEGORY, 'B');
.toHaveBeenCalledWith(GoogleAnalyticsCustomDimension.TEST_CATEGORY, 'B');
expect(analyticsProviderMock.addGACustomDimension)
.toHaveBeenCalledWith(AnalyticsDimensionIndices.CANDIDATE_ID, '1');
.toHaveBeenCalledWith(GoogleAnalyticsCustomDimension.CANDIDATE_ID, '1');
expect(analyticsProviderMock.addGACustomDimension)
.toHaveBeenCalledWith(AnalyticsDimensionIndices.APPLICATION_REFERENCE, '123456789');
.toHaveBeenCalledWith(GoogleAnalyticsCustomDimension.APPLICATION_REFERENCE, '123456789');
done();
});
});
Expand Down
14 changes: 10 additions & 4 deletions src/app/pages/communication/communication.analytics.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import {
AnalyticsErrorTypes,
AnalyticsEventCategories,
AnalyticsEvents,
AnalyticsScreenNames, GoogleAnalyticsEvents, GoogleAnalyticsEventsTitles, GoogleAnalyticsEventsValues,
AnalyticsScreenNames,
GoogleAnalyticsCustomDimension,
GoogleAnalyticsEvents,
GoogleAnalyticsEventsTitles,
GoogleAnalyticsEventsValues,
} from '@providers/analytics/analytics.model';
import { TestsModel } from '@store/tests/tests.model';
import { analyticsEventTypePrefix, formatAnalyticsText } from '@shared/helpers/format-analytics-text';
Expand Down Expand Up @@ -108,9 +112,11 @@ export class CommunicationAnalyticsEffects {
//GA4 Analytics
this.analytics.setGACurrentPage(analyticsEventTypePrefix(AnalyticsScreenNames.COMMUNICATION, tests));

this.analytics.addGACustomDimension(AnalyticsDimensionIndices.TEST_CATEGORY, category);
this.analytics.addGACustomDimension(AnalyticsDimensionIndices.CANDIDATE_ID, `${candidateId}`);
this.analytics.addGACustomDimension(AnalyticsDimensionIndices.APPLICATION_REFERENCE, applicationReference);
this.analytics.addGACustomDimension(GoogleAnalyticsCustomDimension.TEST_CATEGORY, category);
this.analytics.addGACustomDimension(GoogleAnalyticsCustomDimension.CANDIDATE_ID, `${candidateId}`);
this.analytics.addGACustomDimension(
GoogleAnalyticsCustomDimension.APPLICATION_REFERENCE, applicationReference
);
return of(AnalyticRecorded());
}),
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
JournalRefreshModes,
GoogleAnalyticsEvents,
GoogleAnalyticsEventsTitles,
GoogleAnalyticsEventsValues,
GoogleAnalyticsEventsValues, GoogleAnalyticsCustomDimension,
} from '@providers/analytics/analytics.model';
import * as slotActions from '@providers/slot/slot.actions';
import { AnalyticRecorded } from '@providers/analytics/analytics.actions';
Expand Down Expand Up @@ -86,9 +86,9 @@ describe('JournalAnalyticsEffects', () => {
expect(analyticsProviderMock.setGACurrentPage)
.toHaveBeenCalledWith(screenName);
expect(analyticsProviderMock.addGACustomDimension)
.toHaveBeenCalledWith(AnalyticsDimensionIndices.CANDIDATE_ID, '');
.toHaveBeenCalledWith(GoogleAnalyticsCustomDimension.CANDIDATE_ID, '');
expect(analyticsProviderMock.addGACustomDimension)
.toHaveBeenCalledWith(AnalyticsDimensionIndices.APPLICATION_REFERENCE, '');
.toHaveBeenCalledWith(GoogleAnalyticsCustomDimension.APPLICATION_REFERENCE, '');
done();
});
});
Expand All @@ -114,7 +114,7 @@ describe('JournalAnalyticsEffects', () => {
'Tomorrow',
);
expect(analyticsProviderMock.addGACustomDimension)
.toHaveBeenCalledWith(AnalyticsDimensionIndices.JOURNAL_DAYS_FROM_TODAY, '4');
.toHaveBeenCalledWith(GoogleAnalyticsCustomDimension.JOURNAL_DAYS_FROM_TODAY, '4');

done();
});
Expand Down Expand Up @@ -303,9 +303,9 @@ describe('JournalAnalyticsEffects', () => {
GoogleAnalyticsEventsTitles.RESULT,
GoogleAnalyticsEventsValues.PASS);
expect(analyticsProviderMock.addGACustomDimension)
.toHaveBeenCalledWith(AnalyticsDimensionIndices.CANDIDATE_ID, '1');
.toHaveBeenCalledWith(GoogleAnalyticsCustomDimension.CANDIDATE_ID, '1');
expect(analyticsProviderMock.addGACustomDimension)
.toHaveBeenCalledWith(AnalyticsDimensionIndices.APPLICATION_REFERENCE, '1011');
.toHaveBeenCalledWith(GoogleAnalyticsCustomDimension.APPLICATION_REFERENCE, '1011');
done();
});
});
Expand Down
14 changes: 8 additions & 6 deletions src/app/pages/journal/journal.analytics.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
AnalyticsDimensionIndices,
AnalyticsEventCategories,
AnalyticsEvents,
AnalyticsScreenNames,
AnalyticsScreenNames, GoogleAnalyticsCustomDimension,
GoogleAnalyticsEvents,
GoogleAnalyticsEventsTitles,
GoogleAnalyticsEventsValues,
Expand All @@ -52,8 +52,9 @@ export class JournalAnalyticsEffects {

// GA4 Analytics
this.analytics.setGACurrentPage(AnalyticsScreenNames.JOURNAL);
this.analytics.addGACustomDimension(AnalyticsDimensionIndices.CANDIDATE_ID, '');
this.analytics.addGACustomDimension(AnalyticsDimensionIndices.APPLICATION_REFERENCE, '');
// reset values
this.analytics.addGACustomDimension(GoogleAnalyticsCustomDimension.CANDIDATE_ID, '');
this.analytics.addGACustomDimension(GoogleAnalyticsCustomDimension.APPLICATION_REFERENCE, '');
return of(AnalyticRecorded());
}),
));
Expand Down Expand Up @@ -81,7 +82,7 @@ export class JournalAnalyticsEffects {
);

this.analytics.addGACustomDimension(
AnalyticsDimensionIndices.JOURNAL_DAYS_FROM_TODAY,
GoogleAnalyticsCustomDimension.JOURNAL_DAYS_FROM_TODAY,
this.analytics.getDiffDays(action.day).toString(),
);

Expand Down Expand Up @@ -219,11 +220,12 @@ export class JournalAnalyticsEffects {
isTestPassed ? GoogleAnalyticsEventsValues.PASS : GoogleAnalyticsEventsValues.FAIL);

this.analytics.addGACustomDimension(
AnalyticsDimensionIndices.APPLICATION_REFERENCE,
GoogleAnalyticsCustomDimension.APPLICATION_REFERENCE,
formatApplicationReference(journalDataOfTest.applicationReference),
);
this.analytics.addGACustomDimension(
AnalyticsDimensionIndices.CANDIDATE_ID, journalDataOfTest.candidate.candidateId.toString(),
GoogleAnalyticsCustomDimension.CANDIDATE_ID,
journalDataOfTest.candidate.candidateId.toString(),
);

return of(AnalyticRecorded());
Expand Down
Loading

0 comments on commit ccdf206

Please sign in to comment.