mirror of
https://github.com/akveo/ngx-admin.git
synced 2025-12-16 23:40:14 +01:00
feat(analytics): enable analytic
This commit is contained in:
parent
3eee634861
commit
e8cbd479c6
3 changed files with 37 additions and 2 deletions
|
|
@ -4,6 +4,7 @@ import { NbAuthModule, NbDummyAuthProvider } from '@nebular/auth';
|
||||||
|
|
||||||
import { throwIfAlreadyLoaded } from './module-import-guard';
|
import { throwIfAlreadyLoaded } from './module-import-guard';
|
||||||
import { DataModule } from './data/data.module';
|
import { DataModule } from './data/data.module';
|
||||||
|
import { AnalyticsService } from './utils/analytics.service';
|
||||||
|
|
||||||
const NB_CORE_PROVIDERS = [
|
const NB_CORE_PROVIDERS = [
|
||||||
...DataModule.forRoot().providers,
|
...DataModule.forRoot().providers,
|
||||||
|
|
@ -20,6 +21,7 @@ const NB_CORE_PROVIDERS = [
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}).providers,
|
}).providers,
|
||||||
|
AnalyticsService,
|
||||||
];
|
];
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
|
|
|
||||||
25
src/app/@core/utils/analytics.service.ts
Normal file
25
src/app/@core/utils/analytics.service.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
import {Injectable} from '@angular/core';
|
||||||
|
import {Router, NavigationEnd} from '@angular/router';
|
||||||
|
import {Location} from '@angular/common';
|
||||||
|
|
||||||
|
import {filter} from 'rxjs/operator/filter';
|
||||||
|
|
||||||
|
declare const ga: any;
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class AnalyticsService {
|
||||||
|
private _enabled: boolean;
|
||||||
|
|
||||||
|
constructor(private _location: Location, private _router: Router) {
|
||||||
|
this._enabled = window.location.href.indexOf('akveo.com') >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
trackPageViews() {
|
||||||
|
if (this._enabled) {
|
||||||
|
filter.call(this._router.events, (event) => event instanceof NavigationEnd)
|
||||||
|
.subscribe(() => {
|
||||||
|
ga('send', {hitType: 'pageview', page: this._location.path()});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,11 +3,19 @@
|
||||||
* Copyright Akveo. All Rights Reserved.
|
* Copyright Akveo. All Rights Reserved.
|
||||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||||
*/
|
*/
|
||||||
import { Component } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { AnalyticsService } from './@core/utils/analytics.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ngx-app',
|
selector: 'ngx-app',
|
||||||
template: '<router-outlet></router-outlet>',
|
template: '<router-outlet></router-outlet>',
|
||||||
})
|
})
|
||||||
export class AppComponent {
|
export class AppComponent implements OnInit {
|
||||||
|
|
||||||
|
constructor(private analytics: AnalyticsService) {
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.analytics.trackPageViews();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue