ngx-google-analytics
Version:
A simple ng-9 wrapper to load Google Analytics dependency by angular way
40 lines (39 loc) • 1.82 kB
TypeScript
import { ModuleWithProviders } from '@angular/core';
import { IGoogleAnalyticsRoutingSettings } from '../interfaces/i-google-analytics-routing-settings';
import * as i0 from "@angular/core";
import * as i1 from "@angular/common";
import * as i2 from "../ngx-google-analytics.module";
/**
* Attach a listener to `NavigationEnd` Router event. So, every time Router finish the page resolution it should call `NavigationEnd` event.
* We assume that NavigationEnd is the final page resolution and call GA `page_view` command.
*
* To avoid double binds, we also destroy the subscription when de Bootstrap Component is destroied. But, we don't know for sure
* that this strategy does not cause double bind on multiple bootstrap components.
*
* We are using de component's injector reference to resolve Router, sou I hope there is no problem w/ double bing.
*
* If you have this problem, I encourage not Use NgxGoogleAnalyticsRouterModule and atach the listener on AppComponent initialization.
*
* This Module is just a sugar for:
*
```typescript
constructor(private router: Router) {}
...
ngOnInit() {
...
this.router
.events
.pipe(takeUntil(this.onDestroy$))
.subscribe(event => {
if (event instanceof NavigationEnd) {
gaService.pageView(event.urlAfterRedirects, undefined);
}
});
```
*/
export declare class NgxGoogleAnalyticsRouterModule {
static forRoot(settings?: IGoogleAnalyticsRoutingSettings): ModuleWithProviders<NgxGoogleAnalyticsRouterModule>;
static ɵfac: i0.ɵɵFactoryDeclaration<NgxGoogleAnalyticsRouterModule, never>;
static ɵmod: i0.ɵɵNgModuleDeclaration<NgxGoogleAnalyticsRouterModule, never, [typeof i1.CommonModule, typeof i2.NgxGoogleAnalyticsModule], never>;
static ɵinj: i0.ɵɵInjectorDeclaration<NgxGoogleAnalyticsRouterModule>;
}