diff --git a/aio/src/app/shared/ga.service.spec.ts b/aio/src/app/shared/ga.service.spec.ts index be3c80cc59..ffd95fbc45 100644 --- a/aio/src/app/shared/ga.service.spec.ts +++ b/aio/src/app/shared/ga.service.spec.ts @@ -74,6 +74,13 @@ describe('GaService', () => { }); }); + describe('sendEvent', () => { + it('should send "event" with associated data', () => { + gaService.sendEvent('some source', 'some campaign', 'a label', 45); + expect(gaSpy).toHaveBeenCalledWith('send', 'event', 'some source', 'some campaign', 'a label', 45); + }); + }); + it('should support replacing the `window.ga` function', () => { const gaSpy2 = jasmine.createSpy('new ga'); mockWindow.ga = gaSpy2; diff --git a/aio/src/app/shared/ga.service.ts b/aio/src/app/shared/ga.service.ts index 122bfa4a93..65318f2a20 100644 --- a/aio/src/app/shared/ga.service.ts +++ b/aio/src/app/shared/ga.service.ts @@ -29,6 +29,10 @@ export class GaService { this.ga('send', 'pageview'); } + sendEvent(source: string, action: string, label?: string, value?: number) { + this.ga('send', 'event', source, action, label, value); + } + ga(...args: any[]) { const gaFn = (this.window as any)['ga']; if (gaFn) {