UNPKG

ngx-matomo-client

Version:

Matomo (fka. Piwik) client for Angular applications

209 lines (202 loc) 6.48 kB
import * as i0 from '@angular/core'; import { InjectionToken, inject, Injectable, makeEnvironmentProviders, NgModule } from '@angular/core'; import * as i1 from 'ngx-matomo-client/core'; import { MatomoTracker, provideMatomo, ɵprovideTestingTracker as _provideTestingTracker, MATOMO_CONFIGURATION, MATOMO_DIRECTIVES } from 'ngx-matomo-client/core'; const MATOMO_TESTING_INSTANCE = new InjectionToken('MATOMO_TESTING_INSTANCE', { factory: () => new MatomoTestingInstance(), }); /** * No-op implementation of {@link MatomoInstance} */ class MatomoTestingInstance { areCookiesEnabled() { return false; } getAttributionCampaignKeyword() { return ''; } getAttributionCampaignName() { return ''; } getAttributionInfo() { return []; } getAttributionReferrerTimestamp() { return ''; } getAttributionReferrerUrl() { return ''; } getCrossDomainLinkingUrlParameter() { return ''; } getCurrentUrl() { return ''; } getCustomDimension(_customDimensionId) { return ''; } getCustomPagePerformanceTiming() { return ''; } getCustomVariable(_index, _scope) { return ''; } getEcommerceItems() { return []; } getExcludedReferrers() { return []; } getLinkTrackingTimer() { return 0; } getMatomoUrl() { return ''; } getPageViewId() { return ''; } getCustomData() { return undefined; } getPiwikUrl() { return ''; } getRememberedConsent() { return ''; } getRememberedCookieConsent() { return ''; } getUserId() { return ''; } getVisitorId() { return ''; } getVisitorInfo() { return []; } hasCookies() { return false; } hasRememberedConsent() { return false; } isConsentRequired() { return false; } isUserOptedOut() { return false; } getIgnoreCampaignsForReferrers() { return []; } } /** * No-op implementation of {@link MatomoTracker} * * All commands are memoized and can later be retrieved using * {@link getAllCommands getAllCommands()} or {@link getCommand getCommand(index)}. * * All <i>getter</i> methods will immediately resolve to an <i>empty value</i>. * This can be customized by setting a custom Matomo instance with {@link setMatomoInstance setMatomoInstance()}. */ class MatomoTestingTracker extends MatomoTracker { #fakeInstance = inject(MATOMO_TESTING_INSTANCE); #paq = []; /** Retrieve the current Matomo instance */ getMatomoInstance() { return this.#fakeInstance; } /** * Set the current matomo instance * * @deprecated will be removed in a future version and injected from DI token `MATOMO_TESTING_INSTANCE` instead * @see MATOMO_TESTING_INSTANCE */ setMatomoInstance(instance) { this.#fakeInstance = instance; } /** Retrieve all memoized commands */ getAllCommands() { return [...this.#paq]; } /** Retrieve nth memoized command */ getCommand(index) { return this.#paq[index]; } /** Clear all memoized commands */ reset() { this.#paq = []; } push(command) { this.#paq.push(command); } async pushFn(fn) { return fn(this.#fakeInstance); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: MatomoTestingTracker, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: MatomoTestingTracker }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: MatomoTestingTracker, decorators: [{ type: Injectable }] }); /** * Set up a no-op Matomo tracker. Useful for testing scenario. * * * Testing tracker is available as both {@link MatomoTracker} and {@link MatomoTestingTracker} injection tokens, * the latter allowing to customize testing behavior (see {@link MatomoTestingTracker}). * * @see MatomoTestingTracker */ function provideMatomoTesting(config = {}, ...features) { const providers = [ provideMatomo(config, ...features), _provideTestingTracker(), MatomoTestingTracker, { provide: MatomoTracker, useExisting: MatomoTestingTracker, }, ]; // Allow to provide a configuration, because it can be useful for users depending on `MATOMO_CONFIGURATION` in their code. if (typeof config === 'function') { providers.push({ provide: MATOMO_CONFIGURATION, useFactory: config, }); } else { providers.push({ provide: MATOMO_CONFIGURATION, useValue: config, }); } return makeEnvironmentProviders(providers); } class MatomoTestingModule { static forRoot() { return { ngModule: MatomoTestingModule, providers: [provideMatomoTesting()], }; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: MatomoTestingModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); } static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.0.0", ngImport: i0, type: MatomoTestingModule, imports: [i1.MatomoTrackerDirective, i1.MatomoTrackClickDirective, i1.MatomoOptOutFormComponent], exports: [i1.MatomoTrackerDirective, i1.MatomoTrackClickDirective, i1.MatomoOptOutFormComponent] }); } static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: MatomoTestingModule, imports: [i1.MatomoOptOutFormComponent] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: MatomoTestingModule, decorators: [{ type: NgModule, args: [{ imports: [...MATOMO_DIRECTIVES], exports: [...MATOMO_DIRECTIVES], }] }] }); /** * Generated bundle index. Do not edit. */ export { MATOMO_TESTING_INSTANCE, MatomoTestingInstance, MatomoTestingModule, MatomoTestingTracker, provideMatomoTesting }; //# sourceMappingURL=ngx-matomo-client-testing.mjs.map