UNPKG

ngx-matomo-client

Version:

Matomo (fka. Piwik) client for Angular applications

73 lines (72 loc) 2.46 kB
import { InjectionToken } from '@angular/core'; import { ActivatedRouteSnapshot } from '@angular/router'; import { MatomoECommerceView, MatomoTracker } from 'ngx-matomo-client/core'; import { Observable } from 'rxjs'; import { MatomoRouteInterceptorBase } from './route-interceptor-base'; import * as i0 from "@angular/core"; export declare const DEFAULT_DATA_KEY = "matomo"; /** Token to define the route's data key to be looked-up by `MatomoRouteDataInterceptor` */ export declare const MATOMO_ROUTE_DATA_KEY: InjectionToken<string>; /** Standard properties that may be read from route data */ export interface MatomoRouteData { title?: string; ecommerce?: MatomoECommerceView; } /** * Simple interceptor looking at 'matomo' key of route's data for tracking. * * It is possible to extend this class or {@link MatomoRouteInterceptorBase} * for custom behavior (to use another data key, etc.) * * @example * // Using provided MatomoRouteDataInterceptor (looks into 'matomo' data key) * const routes: Routes = [ * { * path: '/hello', * component: HelloComponent, * data: { * matomo: { * title: 'Page title', * } as MatomoRouteData * } * }, * ]; * * NgxMatomoRouterModule.forRoot({ * interceptors: [MatomoRouteDataInterceptor], * }), * * @example * // Using custom 'myCustomAnalyticsKey' data key * const routes: Routes = [ * { * path: '/hello', * component: HelloComponent, * data: { * myCustomAnalyticsKey: { * title: 'Page title', * } as MatomoRouteData * } * }, * ]; * * @Injectable() * export class MyCustomInterceptor extends MatomoRouteDataInterceptor { * readonly dataKey = 'myCustomAnalyticsKey'; * } * * NgxMatomoRouterModule.forRoot({ * interceptors: [MyCustomInterceptor], * }), * * @see MatomoRouteInterceptorBase * @see MatomoRouteData */ export declare class MatomoRouteDataInterceptor extends MatomoRouteInterceptorBase<MatomoRouteData | undefined> { protected readonly tracker: MatomoTracker; protected readonly dataKey: string; protected extractRouteData(route: ActivatedRouteSnapshot): MatomoRouteData | undefined; protected processRouteData(data: MatomoRouteData | undefined): Observable<void> | Promise<void> | void; static ɵfac: i0.ɵɵFactoryDeclaration<MatomoRouteDataInterceptor, never>; static ɵprov: i0.ɵɵInjectableDeclaration<MatomoRouteDataInterceptor>; }