From 4d0d5644ddebd8ce1ae03e1ad178f32941d3c2ce Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 4 Oct 2017 22:00:25 -0600 Subject: [PATCH] Google Analytics --- .vscode/launch.json | 15 +++ Client/src/app/app.module.ts | 3 +- .../src/app/components/app/app.component.ts | 18 ++- .../audio-player/audio-player.component.ts | 32 +++++- .../events-page/events-page.component.ts | 7 +- .../share-popup/share-popup.component.html | 4 +- .../share-popup/share-popup.component.ts | 21 +++- .../services/google-analytics.service.spec.ts | 15 +++ .../app/services/google-analytics.service.ts | 106 ++++++++++++++++++ Client/src/index.html | 12 ++ git-post-receive | 2 +- 11 files changed, 220 insertions(+), 15 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 Client/src/app/services/google-analytics.service.spec.ts create mode 100644 Client/src/app/services/google-analytics.service.ts diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..b169bf9 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "chrome", + "request": "launch", + "name": "Launch Chrome against localhost", + "url": "http://localhost:4200", + "webRoot": "${workspaceRoot}" + } + ] +} \ No newline at end of file diff --git a/Client/src/app/app.module.ts b/Client/src/app/app.module.ts index 249f0ec..3de50f5 100644 --- a/Client/src/app/app.module.ts +++ b/Client/src/app/app.module.ts @@ -1,4 +1,5 @@ import { EventService } from './services/event.service'; +import { GoogleAnalyticsService } from './services/google-analytics.service'; import { WindowRefService } from './services/window-ref.service'; import { EmailService } from './services/email.service'; import { SermonService } from './services/sermon.service'; @@ -156,7 +157,7 @@ const Routes = RouterModule.forRoot(Routes) ], - providers: [LoginService,SermonService,EventService,ProgressService,EmailService,WindowRefService,{provide:BrowserXhr,useClass:ProgressXhr}], + providers: [LoginService,GoogleAnalyticsService,SermonService,EventService,ProgressService,EmailService,WindowRefService,{provide:BrowserXhr,useClass:ProgressXhr}], entryComponents: [AddSermonPopupComponent, LoginPopupComponent, OkPopupComponent, diff --git a/Client/src/app/components/app/app.component.ts b/Client/src/app/components/app/app.component.ts index ae1d45f..a927116 100644 --- a/Client/src/app/components/app/app.component.ts +++ b/Client/src/app/components/app/app.component.ts @@ -1,5 +1,6 @@ +import { GoogleAnalyticsService } from './../../services/google-analytics.service'; import { Component, Inject, Injectable, HostListener } from '@angular/core'; -import { Router, NavigationStart, Event } from '@angular/router'; +import { Router, NavigationEnd, Event } from '@angular/router'; import { EventService } from '../../services/event.service'; import { AudioPlayerService } from '../../services/audio-player.service'; import { BibleVerseService } from '../../services/bible-verse.service'; @@ -23,16 +24,21 @@ export class AppComponent { lastScrollPos: number = 0; showAudioPlayer: boolean = false; - constructor(private router: Router, private audioPlayerService: AudioPlayerService){ + constructor(private router: Router, + private audioPlayerService: AudioPlayerService, + private googleAnalyticsService: GoogleAnalyticsService){ this.router.events.subscribe((event:Event) => { - if(event instanceof NavigationStart) { + if(event instanceof NavigationEnd) { this.lastRoute = this.currRoute; - this.currRoute = event.url; + this.currRoute = event.urlAfterRedirects; let doc = document.documentElement; let scrollPos = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0); - if (event.url === '/home'){ + + let url = event.urlAfterRedirects; + + if (url === '/home'){ this.fadeHeader = true; this.headerOpacity = 0; } else { @@ -46,6 +52,8 @@ export class AppComponent { } this.lastRoute = event.url; this.lastScrollPos = scrollPos; + // Google Analytics + googleAnalyticsService.pageView(url.substr(1),url); } }); diff --git a/Client/src/app/components/audio-player/audio-player.component.ts b/Client/src/app/components/audio-player/audio-player.component.ts index ea9fd75..2a128ec 100644 --- a/Client/src/app/components/audio-player/audio-player.component.ts +++ b/Client/src/app/components/audio-player/audio-player.component.ts @@ -1,3 +1,4 @@ +import { GoogleAnalyticsService } from './../../services/google-analytics.service'; import { Component, OnInit, OnDestroy, Output, EventEmitter } from '@angular/core'; import { AudioPlayerService } from '../../services/audio-player.service'; import { AudioStates } from '../../enum/audio-states'; @@ -29,7 +30,8 @@ export class AudioPlayerComponent implements OnInit, OnDestroy { @Output() started: EventEmitter = new EventEmitter(); - constructor(private audioPlayerService: AudioPlayerService){ + constructor(private audioPlayerService: AudioPlayerService, + private googleAnalyticsService: GoogleAnalyticsService){ } @@ -41,20 +43,44 @@ export class AudioPlayerComponent implements OnInit, OnDestroy { this.audioDuration = this.audioPlayerService.getDuration(); this.currentTime = this.audioPlayerService.getCurrentTime(); if (this.audioState == AudioStates.Loading){ - this.started.emit("loading"); + this.started.emit("loading"); } if (this.audioState == AudioStates.Playing){ this.started.emit("playing"); this.interval = setInterval(()=>{ this.audioDuration = this.audioPlayerService.getDuration(); this.currentTime = this.audioPlayerService.getCurrentTime(); - },1000); + },1000); } else { clearInterval(this.interval); } + this.sendGoogleAnalytics(state,error); }); } + sendGoogleAnalytics(state: AudioStates, error: any){ + switch (state) { + case AudioStates.Error: + this.googleAnalyticsService.audioError(this.audioFileId, this.audioFileTitle, error) + break; + + case AudioStates.Loading: + this.googleAnalyticsService.loadingSermon(this.audioFileId,this.audioFileTitle); + break; + + case AudioStates.Paused: + this.googleAnalyticsService.pauseSermon(this.audioFileId,this.audioFileTitle,this.audioPlayerService.getCurrentTime()) + break; + + case AudioStates.Playing: + this.googleAnalyticsService.playSermon(this.audioFileId,this.audioFileTitle,this.audioPlayerService.getCurrentTime()) + break; + + default: + break; + } + } + play(): void{ this.audioPlayerService.resume(); } diff --git a/Client/src/app/components/events-page/events-page.component.ts b/Client/src/app/components/events-page/events-page.component.ts index 4972886..f8c1f01 100644 --- a/Client/src/app/components/events-page/events-page.component.ts +++ b/Client/src/app/components/events-page/events-page.component.ts @@ -1,3 +1,4 @@ +import { GoogleAnalyticsService } from './../../services/google-analytics.service'; import { MdDialog, MdDialogConfig, MdSnackBar } from '@angular/material'; import { ActivatedRoute, Params } from '@angular/router'; import { EventService } from './../../services/event.service'; @@ -28,7 +29,8 @@ export class EventsPageComponent implements OnInit { private dialog: MdDialog, private snackbar: MdSnackBar, private activatedRoute: ActivatedRoute, - private audioPlayerService: AudioPlayerService) { + private audioPlayerService: AudioPlayerService, + private googleAnalyticsService: GoogleAnalyticsService) { this.loginService.isLoggedIn(true).subscribe(is => { this.loggedIn = is; }); this.loginService.onLogin().subscribe(is => { this.loggedIn = is.isLoggedIn; }); this.audioPlayerService.onAudioPlayerOpenClose.subscribe(is => this.audioPlayerOpen = is); @@ -41,7 +43,7 @@ export class EventsPageComponent implements OnInit { id = Number.isNaN(id) ? -1 : id; if (id > -1){ this.getSingleEvent(id); - this.showAllButtonVisible = true; + this.showAllButtonVisible = true; } else { this.getEvents(true); this.showAllButtonVisible = false; @@ -71,6 +73,7 @@ export class EventsPageComponent implements OnInit { this.eventService.getSingleEvent(id).subscribe(event => { this.events.push(event); this.loading = false; + this.googleAnalyticsService.shareEventConversion(event.id,event.title); }); } diff --git a/Client/src/app/components/popups/share-popup/share-popup.component.html b/Client/src/app/components/popups/share-popup/share-popup.component.html index b3b22f7..486a44c 100644 --- a/Client/src/app/components/popups/share-popup/share-popup.component.html +++ b/Client/src/app/components/popups/share-popup/share-popup.component.html @@ -1,6 +1,6 @@
Share
- + - +