Closed rationelis closed 2 years ago
Hi @rationelis
I see your configuration loaded from environment is invalid. Please find configuration reference here.
Maybe it should look like something like this:
export const environment = () => ({
[...]
matomoConfig: {
trackerUrl: getEnv('MATOMO_TRACKER_URL').string(),
siteId: getEnv('MATOMO_SITE_ID').number()
trackAppInitialLoad: true, // you sure?
} as MatomoConfiguration, // optionally cast
[...]
});
See I added as MatomoConfiguration
cast to make the compiler help you ;)
(The way you load configuration asynchronously before bootstrap seems ok)
Also, please provide a repro (Stackblitz) to reproduce error details.
Thanks for you fast reply. Neither correcting the config nor casting fixed the issue. I will try to reproduce it in Stackblitz tomorrow :+1:
Screw it, sleep is for the weak.
Editor URL: https://stackblitz.com/edit/angular-ivy-fbcear?file=src/environments/environment.ts&view=editor Application URL: https://angular-ivy-fbcear.stackblitz.io
I reproduced the issue on Stackblitz. As you will be able to see in the application (not visible in preview) it tries to inject the DOM script from that Stackblitz domain since the trackerUrl
is an empty string. The same applies for the siteId
variable.
I hope this provides you with enough details.
Hi @rationelis
A very basic debugging (based on your repro on Stackblitz) shows that the issue is not related to this lib.
I see your environment variables are simply not loaded at all. This can be revealed with a simple console log:
export const environment = () => {
// This log show that your environment variables are all empty
console.log('debug', getEnv('MATOMO_TRACKER_URL').raw(), getEnv('MATOMO_SITE_ID').raw());
return ({
matomoConfig: {
// Following config is correctly read by this lib
trackerUrl: 'https://mysite.com',
siteId: 1,
trackAppInitialLoad: true,
} as MatomoConfiguration,
});
};
So it looks like that's an issue with @elemental-concept/env-bakery
or the way you're using it.
Closing because not related to this repository, please reopen issue if needed
Packages used:
I'm trying to dynamically load in environment variables into NgxMatomoTrackerModule.forRoot() to configure Matomo. For this, I'm using
@elemental-concept/env-bakery
to import the values from a .dotenv file. The code below is how I setup the environment variable that is used throughout my application.And in the @NgModule I feed the config into the forRoot()
If I try and run this I get an error stating
matomo.js
cannot be found on my localhost. That's because it tries to inject the DOM script from my trackerUrl. Breakpointing on the forRoot method in the debugger, I find this:As you can see, it finds my custom configuration object but it just doesn't load in the custom values. In other places where I use this
environment()
global variable it is correctly populated with my environment variables.The first thing my application does is 'bake' the environment variable and THEN load everything in (as seen below). Therefore I cannot see this being an issue with asynchronous actions that have yet to resolve.
Do you have any ideas how I could fix this issue?