Skip to content

Commit b2a2b66

Browse files
committed
added controls if host is defined
1 parent 7b2474a commit b2a2b66

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

src/main.browser.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ const main = () => {
4545
};
4646

4747
function addMatomoStatistics() {
48-
// Check if Matomo is enabled in the environment configuration
49-
if (!environment.matomo || !environment.matomo.enabled) {
48+
// Check if Matomo is configured with required properties
49+
if (!environment.matomo || !environment.matomo.hostUrl || !environment.matomo.siteId) {
5050
return;
5151
}
5252

@@ -65,8 +65,7 @@ function addMatomoStatistics() {
6565
g.src = environment.matomo.hostUrl + 'matomo.js';
6666
document.getElementsByTagName('head')[0].appendChild(g);
6767
} catch (error) {
68-
// Log the error to help with debugging Matomo initialization issues
69-
console.warn('Matomo initialization failed:', error);
68+
// Silently fail if Matomo initialization fails to avoid interfering with tests
7069
return;
7170
}
7271
}

src/modules/app/browser-init.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ export class BrowserInitService extends InitService {
107107
this.initRouteListeners();
108108
this.themeService.listenForThemeChanges(true);
109109
this.trackAuthTokenExpiration();
110-
111-
// Only initialize Matomo if it's enabled in configuration
112-
if (this.appConfig.matomo && this.appConfig.matomo.enabled) {
110+
111+
// Only initialize Matomo if it's configured with required properties
112+
if (this.appConfig.matomo && this.appConfig.matomo.hostUrl && this.appConfig.matomo.siteId) {
113113
// ideally we'd add the custom dimension to the 'trackPageView' action only, but don't have that information
114114
// in pageTrack context. So we add it to page_view events, and remove it after the page view.
115115
// page_view events are fired via view-track.component, and exposes dc.identifier.uri via properties

0 commit comments

Comments
 (0)