-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #354 from Sunbird-cQube/dev
merge dev to staging
- Loading branch information
Showing
21 changed files
with
320 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { BrowserDetectionService } from './browser-detection.service'; | ||
|
||
describe('BrowserDetectionService', () => { | ||
let service: BrowserDetectionService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(BrowserDetectionService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Injectable } from '@angular/core'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class BrowserDetectionService { | ||
|
||
constructor() { } | ||
|
||
getBrowserType(): string { | ||
const userAgent = window.navigator.userAgent; | ||
|
||
if (userAgent.indexOf('Chrome') !== -1) { | ||
return 'Chrome'; | ||
} else if (userAgent.indexOf('Firefox') !== -1) { | ||
return 'Firefox'; | ||
} else if (userAgent.indexOf('Safari') !== -1) { | ||
return 'Safari'; | ||
} else if (userAgent.indexOf('Edge') !== -1) { | ||
return 'Edge'; | ||
} else if (userAgent.indexOf('IE') !== -1 || userAgent.indexOf('Trident/') !== -1) { | ||
return 'Internet Explorer'; | ||
} else { | ||
return 'Unknown'; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { DeviceDetectionService } from './device-detection.service'; | ||
|
||
describe('DeviceDetectionService', () => { | ||
let service: DeviceDetectionService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(DeviceDetectionService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { DeviceDetectorService } from 'ngx-device-detector'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class DeviceDetectionService { | ||
constructor(private deviceService: DeviceDetectorService) {} | ||
|
||
getDeviceType(): string { | ||
if (this.deviceService.isDesktop()) { | ||
return 'Desktop'; | ||
} else if (this.deviceService.isTablet()) { | ||
return 'Tablet'; | ||
} else if (this.deviceService.isMobile()) { | ||
return 'Mobile'; | ||
} else { | ||
return 'Unknown'; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { DomEventTrackerService } from './dom-event-tracker.service'; | ||
|
||
describe('DomEventTrackerService', () => { | ||
let service: DomEventTrackerService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(DomEventTrackerService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { TelemetryService } from './telemetry.service'; | ||
import { Router } from '@angular/router'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class DomEventTrackerService { | ||
|
||
constructor(private readonly _router: Router, private readonly _telemetryService: TelemetryService) { } | ||
|
||
onClick(event): void { | ||
const { pageName, eventName } = event; | ||
this._telemetryService.saveTelemetry({ | ||
pageName: pageName ? pageName : this._router.url?.slice(1), | ||
pageEvent: "click", | ||
pageEventName: eventName ? eventName : "filter" | ||
}).subscribe(res => console.log('telemetry saved!!!'));; | ||
} | ||
|
||
onChange(event): void { | ||
const { pageName, eventName } = event; | ||
this._telemetryService.saveTelemetry({ | ||
pageName: pageName ? pageName : this._router.url?.slice(1), | ||
pageEvent: "change", | ||
pageEventName: eventName ? eventName : "filter" | ||
}).subscribe(res => console.log('telemetry saved!!!'));; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { PageTrackerService } from './page-tracker.service'; | ||
|
||
describe('PageTrackerService', () => { | ||
let service: PageTrackerService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(PageTrackerService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { TelemetryService } from './telemetry.service'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class PageTrackerService { | ||
|
||
previousRoute: string; | ||
startTime: Date; | ||
|
||
constructor(private readonly _telemetryService: TelemetryService) { } | ||
|
||
onPageChange(event): void { | ||
if (this.previousRoute && event.url !== this.previousRoute) { | ||
const now = new Date(); | ||
this._telemetryService.saveTelemetry({ | ||
pageName: this.previousRoute.slice(1), | ||
pageEvent: "onLoad", | ||
pageEventName: "onLoad", | ||
timeSpent: (now.getTime() - this.startTime.getTime()), | ||
timeIn: this.startTime.getTime(), | ||
timeOut: now.getTime() | ||
}).subscribe(res => console.log('telemetry saved!!!')); | ||
} | ||
|
||
this.startTime = new Date(); | ||
this.previousRoute = event.url; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { TelemetryService } from './telemetry.service'; | ||
|
||
describe('TelemetryService', () => { | ||
let service: TelemetryService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(TelemetryService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Injectable } from '@angular/core'; | ||
import { Observable } from 'rxjs'; | ||
import { environment } from 'src/environments/environment'; | ||
import { BrowserDetectionService } from './browser-detection.service'; | ||
import { DeviceDetectionService } from './device-detection.service'; | ||
import { formatDateToDDMMYY } from 'src/app/utilities/DateFormatter'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class TelemetryService { | ||
|
||
constructor(private _http: HttpClient, private _browserDetectionService: BrowserDetectionService, private _deviceDetectionService: DeviceDetectionService) { } | ||
|
||
saveTelemetry(eventData: any): Observable<any> { | ||
let data = { | ||
date: formatDateToDDMMYY(new Date()), | ||
timestamp: new Date().getTime(), | ||
userId: localStorage.getItem('user_id'), | ||
deviceType: this._deviceDetectionService.getDeviceType(), | ||
userLocation: "", | ||
browserType: this._browserDetectionService.getBrowserType(), | ||
...eventData | ||
}; | ||
|
||
return this._http.post<any>(`${environment.apiURL}/captureTelemetry`, data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ChangeDirective } from './change.directive'; | ||
|
||
describe('ChangeDirective', () => { | ||
it('should create an instance', () => { | ||
const directive = new ChangeDirective(); | ||
expect(directive).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Directive, ElementRef, HostListener } from '@angular/core'; | ||
import { DomEventTrackerService } from 'src/app/core/services/dom-event-tracker.service'; | ||
|
||
@Directive({ | ||
selector: '[appChange]' | ||
}) | ||
export class ChangeDirective { | ||
|
||
constructor(private el: ElementRef, private readonly _domEventTrackerService: DomEventTrackerService) { } | ||
|
||
@HostListener('change') onChange() { | ||
const eventName = this.el.nativeElement.getAttribute("data-event-name"); | ||
const pageName = this.el.nativeElement.getAttribute("data-page-name"); | ||
this._domEventTrackerService.onChange({ | ||
eventName, | ||
pageName | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ClickDirective } from './click.directive'; | ||
|
||
describe('ClickDirective', () => { | ||
it('should create an instance', () => { | ||
const directive = new ClickDirective(); | ||
expect(directive).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Directive, ElementRef, HostListener } from '@angular/core'; | ||
import { DomEventTrackerService } from 'src/app/core/services/dom-event-tracker.service'; | ||
|
||
@Directive({ | ||
selector: '[appClick]' | ||
}) | ||
export class ClickDirective { | ||
|
||
constructor(private el: ElementRef, private readonly _domEventTrackerService: DomEventTrackerService) { } | ||
|
||
@HostListener('click') onClick() { | ||
const eventName = this.el.nativeElement.getAttribute("data-event-name"); | ||
const pageName = this.el.nativeElement.getAttribute("data-page-name"); | ||
this._domEventTrackerService.onClick({ | ||
eventName, | ||
pageName | ||
}); | ||
} | ||
|
||
} |
Oops, something went wrong.