feat(docs-infra): support sending Google Analytics events (#25042)

PR Close #25042
This commit is contained in:
Pete Bacon Darwin 2018-07-23 15:03:34 +01:00 committed by Igor Minar
parent d46a961509
commit a224df43af
2 changed files with 11 additions and 0 deletions

View File

@ -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;

View File

@ -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) {