Closed Terriuss closed 2 years ago
Hi @Terriuss,
Yes, as you might guess, Ngx-matomo cannot be used with SSR: you have to disable it when using SSR rendering.
In your root module, update your NgxMatomoTrackerModule
import using the alternative way of providing configuration as described in the README and update your configuration provider to something like this :
import { isPlatformBrowser } from '@angular/common';
import { PLATFORM_ID } from '@angular/core';
import { NgxMatomoTrackerModule } from '@ngx-matomo/tracker';
@NgModule({
// Import module without .forRoot()
imports: [NgxMatomoTrackerModule],
// Provide your config as following
providers: [
{
provide: MATOMO_CONFIGURATION,
useFactory: matomoConfigFactory,
deps: [PLATFORM_ID]
},
],
})
export class AppModule {}
export function matomoConfigFactory(platformId: Object) {
return {
disabled: !isPlatformBrowser(platformId),
// Put your existing configuration here instead of .forRoot()
siteId: '…',
trackerUrl: '…',
};
}
Please let me know if this solves your issue
Maybe I will update this lib soon to handle such case automatically/silently :-)
@EmmanuelRoux thanks for the super fast reply. Works like a charm :)
:tada: This issue has been resolved in version 2.2.0 :tada:
The release is available on:
v2.2.0
Your semantic-release bot :package::rocket:
@Terriuss With version 2.2.0, you should be able to remove this workaround. Tracker now auto-disables itself on SSR platform.
Hi,
when using SSR and prerendering I get the issue, that "window" is not definded. I'm using ngx-matomo version 2.1.0
Console error:
Prerendering 1 route(s) to C:\Development\xxx\dist\xxx\browser\be...Unhandled Promise rejection: window is not defined ; Zone: <root> ; Task: Promise.then ; Value: ReferenceError: window is not defined at initializeMatomoHolder (C:\Development\xxx\dist\xxx\server\be\main.js:3:8382901) at new MatomoInitializerService (C:\Development\xxx\dist\xxx\server\be\main.js:3:8399437) at createMatomoInitializer (C:\Development\xxx\dist\xxx\server\be\main.js:3:8399140) at Object.MatomoInitializerService_Factory [as factory] (C:\Development\xxx\dist\xxx\server\be\main.js:3:8401113) at R3Injector.hydrate (C:\Development\xxx\dist\xxx\server\be\main.js:3:6371603) at R3Injector.get (C:\Development\xxx\dist\xxx\server\be\main.js:3:6368724) at injectInjectorOnly (C:\Development\xxx\dist\xxx\server\be\main.js:3:6263915) at Object.ɵɵinject (C:\Development\xxx\dist\xxx\server\be\main.js:3:6264085) at Object.NgxMatomoTrackerModule_Factory [as factory] (C:\Development\xxx\dist\xxx\server\be\main.js:3:8401652) at R3Injector.hydrate (C:\Development\xxx\dist\xxx\server\be\main.js:3:6371603) ReferenceError: window is not defined at initializeMatomoHolder (C:\Development\xxx\dist\xxx\server\be\main.js:3:8382901) at new MatomoInitializerService (C:\Development\xxx\dist\xxx\server\be\main.js:3:8399437) at createMatomoInitializer (C:\Development\xxx\dist\xxx\server\be\main.js:3:8399140) at Object.MatomoInitializerService_Factory [as factory] (C:\Development\xxx\dist\xxx\server\be\main.js:3:8401113) at R3Injector.hydrate (C:\Development\xxx\dist\xxx\server\be\main.js:3:6371603) at R3Injector.get (C:\Development\xxx\dist\xxx\server\be\main.js:3:6368724) at injectInjectorOnly (C:\Development\xxx\dist\xxx\server\be\main.js:3:6263915) at Object.ɵɵinject (C:\Development\xxx\dist\xxx\server\be\main.js:3:6264085) at Object.NgxMatomoTrackerModule_Factory [as factory] (C:\Development\xxx\dist\xxx\server\be\main.js:3:8401652) at R3Injector.hydrate (C:\Development\xxx\dist\xxx\server\be\main.js:3:6371603) × Prerendering routes to C:\Development\xxx\dist\xxx\browser\be failed.