From 40343af60dae7b358bfc91ea13c7dc31dbbdfd97 Mon Sep 17 00:00:00 2001 From: Aashil Date: Tue, 13 Sep 2016 12:37:46 -0400 Subject: [PATCH 1/2] PROD-276: Send custom events for various events across stackbot to google analytics. Events on which we send data to google analytics: * On clicking the submit button. * On pressing enter to make a search. * On clicking Add more button to show more data in the reports. * On logging out. * On logging in. --- default/src/app/auth/auth-button.component.ts | 3 +++ default/src/app/report/report.component.ts | 3 +++ default/src/app/search/search.component.ts | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/default/src/app/auth/auth-button.component.ts b/default/src/app/auth/auth-button.component.ts index 98709b5..e7ca535 100644 --- a/default/src/app/auth/auth-button.component.ts +++ b/default/src/app/auth/auth-button.component.ts @@ -4,6 +4,7 @@ import { Component } from '@angular/core'; import { AuthService } from './auth.service'; +declare var ga: Function; @Component({ selector: 'auth-button', @@ -25,9 +26,11 @@ export class AuthButtonComponent { ); } login() { + ga('send', 'event', 'Auth', 'Login', 'click'); this.auth.login(); } logout() { + ga('send', 'event', 'Auth', 'Logout', 'click'); this.auth.logout(); } } diff --git a/default/src/app/report/report.component.ts b/default/src/app/report/report.component.ts index 000cd9f..6b0fef9 100644 --- a/default/src/app/report/report.component.ts +++ b/default/src/app/report/report.component.ts @@ -8,6 +8,8 @@ import { AuthService } from '../auth/index'; // Note that this also imports moment itself. import * as moment from 'moment-timezone'; +declare var ga: Function; + @Component({ selector: 'report', templateUrl: 'report.component.html', @@ -95,6 +97,7 @@ export class ReportComponent { } getMoreData(cursor: string) { + ga('send', 'event', 'Report', 'Show more', 'click'); this.queryService.getQueries(cursor).subscribe( (data: any[]) => { this.data = this.data.concat(this.processData(data['payload'], data['cursor'])); diff --git a/default/src/app/search/search.component.ts b/default/src/app/search/search.component.ts index 38fc0e6..12013fc 100644 --- a/default/src/app/search/search.component.ts +++ b/default/src/app/search/search.component.ts @@ -3,6 +3,8 @@ import { Component } from '@angular/core'; import { QueryService } from '../query/index'; import {AuthService} from '../auth/auth.service'; +declare var ga: Function; + @Component({ selector: 'search', templateUrl: 'search.component.html', @@ -33,12 +35,14 @@ export class SearchComponent { submit(searchField: string) { if (searchField !== '') { this.doSearch(searchField) ; + ga('send', 'event', 'Search', 'submit', 'clicking submit button'); } } onPressEnter(e: any, searchField: any) { if (e.keyCode === 13 && searchField !== '') { this.doSearch(searchField); + ga('send', 'event', 'Search', 'submit', 'pressing enter'); } } From d372ff31ba57da4c17116cedf5b15118814732e7 Mon Sep 17 00:00:00 2001 From: Aashil Date: Tue, 13 Sep 2016 15:34:26 -0400 Subject: [PATCH 2/2] PROD-276: Send custom event for recording the source of the search (site-search or omnibox) to GA. --- default/src/app/search/search.component.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/default/src/app/search/search.component.ts b/default/src/app/search/search.component.ts index 12013fc..8c31826 100644 --- a/default/src/app/search/search.component.ts +++ b/default/src/app/search/search.component.ts @@ -49,6 +49,7 @@ export class SearchComponent { doSearch(searchField: any) { this.queryService.doQuery(searchField, 'site-search').subscribe( data => { + ga('send', 'event', 'Search', 'source', 'site-search'); // If when data is returned from a query with a redirect set, do the redirect. if (data['payload']['redirect']) { this._redirect(data['payload']['redirect']); @@ -67,6 +68,7 @@ export class SearchComponent { if (parameters['q'] != null) { this.queryService.doQuery(parameters['q'], 'omnibox').subscribe( response => { + ga('send', 'event', 'Search', 'source', 'omnibox'); return; }, error => { console.log('Error happened: ' + error);