Skip to content

Commit

Permalink
346999760: (feat) [GA4] Track CA Certificates (#607)
Browse files Browse the repository at this point in the history
  • Loading branch information
OlgaMardvilko authored Jul 16, 2024
1 parent e91c51f commit 4df693c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions modules/ui/src/app/pages/certificates/certificates.store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ describe('CertificatesStore', () => {
'uploadCertificate',
'deleteCertificate',
]);
// @ts-expect-error data layer should be defined
window.dataLayer = window.dataLayer || [];

TestBed.configureTestingModule({
imports: [NoopAnimationsModule],
Expand Down Expand Up @@ -152,6 +154,21 @@ describe('CertificatesStore', () => {
container
);
});

it('should send GA event "successful_saving_certificate"', () => {
const container = document.createElement('DIV');
container.classList.add('certificates-drawer-content');
document.querySelector('body')?.appendChild(container);
certificateStore.uploadCertificate(FILE);

expect(
// @ts-expect-error data layer should be defined
window.dataLayer.some(
(item: { event: string }) =>
item.event === 'successful_saving_certificate'
)
).toBeTruthy();
});
});

describe('with invalid certificate file', () => {
Expand Down
4 changes: 4 additions & 0 deletions modules/ui/src/app/pages/certificates/certificates.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ export class CertificatesStore extends ComponentStore<AppComponentState> {
!certificates.some(cert => cert.name === certificate.name)
)[0];
this.updateCertificates(newCertificates);
// @ts-expect-error data layer is not null
window.dataLayer.push({
event: 'successful_saving_certificate',
});
this.notify(
`Certificate successfully added.\n${uploadedCertificate.name} by ${uploadedCertificate.organisation} valid until ${this.datePipe.transform(uploadedCertificate.expires, 'dd MMM yyyy')}`
);
Expand Down

0 comments on commit 4df693c

Please sign in to comment.