Skip to content

Commit

Permalink
UFAL/Load the matomo configuration from the environment (#755)
Browse files Browse the repository at this point in the history
* Added volume into docker-compose

* Take a matomo configuration from the environment
  • Loading branch information
milanmajchrak authored Dec 3, 2024
1 parent fc70fcb commit 4c2e997
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 14 deletions.
4 changes: 4 additions & 0 deletions config/config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,7 @@ vocabularies:
comcolSelectionSort:
sortField: 'dc.title'
sortDirection: 'ASC'

matomo:
hostUrl: http://localhost:8135/
siteId: 1
2 changes: 2 additions & 0 deletions src/config/app-config.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { HomeConfig } from './homepage-config.interface';
import { MarkdownConfig } from './markdown-config.interface';
import { FilterVocabularyConfig } from './filter-vocabulary-config';
import { DiscoverySortConfig } from './discovery-sort.config';
import { MatomoConfig } from './matomo-config';

interface AppConfig extends Config {
ui: UIServerConfig;
Expand Down Expand Up @@ -49,6 +50,7 @@ interface AppConfig extends Config {
vocabularies: FilterVocabularyConfig[];
comcolSelectionSort: DiscoverySortConfig;
signpostingEnabled: boolean;
matomo: MatomoConfig;
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/config/default-app-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { HomeConfig } from './homepage-config.interface';
import { MarkdownConfig } from './markdown-config.interface';
import { FilterVocabularyConfig } from './filter-vocabulary-config';
import { DiscoverySortConfig } from './discovery-sort.config';
import { MatomoConfig } from './matomo-config';

export class DefaultAppConfig implements AppConfig {
production = false;
Expand Down Expand Up @@ -428,4 +429,10 @@ export class DefaultAppConfig implements AppConfig {

// NOTE: you must disable/enable in the backend the signposting feature to make it work `signposting.enabled`
signpostingEnabled = false;

// Matomo configuration
matomo: MatomoConfig = {
hostUrl: 'http://localhost:8135/',
siteId: '1'
};
}
11 changes: 11 additions & 0 deletions src/config/matomo-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Config } from './config.interface';

/**
* Configuration for Matomo statistics.
*/
export class MatomoConfig implements Config {

public hostUrl: string;

public siteId: string;
}
5 changes: 5 additions & 0 deletions src/environments/environment.production.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ export const environment: Partial<BuildConfig> = {
async: true,
time: false,
inlineCriticalCss: false,
},

matomo: {
hostUrl: 'http://localhost:8135/',
siteId: '1',
}
};
7 changes: 6 additions & 1 deletion src/environments/environment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,5 +315,10 @@ export const environment: BuildConfig = {
}
],

signpostingEnabled: true
signpostingEnabled: true,

matomo: {
hostUrl: 'http://localhost:8135/',
siteId: '1',
}
};
7 changes: 6 additions & 1 deletion src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ export const environment: Partial<BuildConfig> = {
nameSpace: '/server',
},

signpostingEnabled: false
signpostingEnabled: false,

matomo: {
hostUrl: 'http://localhost:8135/',
siteId: '1',
}
};

/*
Expand Down
9 changes: 4 additions & 5 deletions src/main.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { environment } from './environments/environment';
import { AppConfig } from './config/app-config.interface';
import { extendEnvironmentWithAppConfig } from './config/config.util';
import { enableProdMode } from '@angular/core';
import { matomoSettings } from './matomo/matomo-settings';

const bootstrap = () => platformBrowserDynamic()
.bootstrapModule(BrowserAppModule, {});
Expand All @@ -27,8 +26,8 @@ const main = () => {
if (environment.production) {
enableProdMode();
}
addMatomoStatistics();

addMatomoStatistics();
if (hasTransferState) {
// Configuration will be taken from transfer state during initialization
return bootstrap();
Expand All @@ -48,15 +47,15 @@ function addMatomoStatistics() {
(window as any)._paq = (window as any)._paq || [];

// Push all configuration commands first
(window as any)._paq.push(['setTrackerUrl', matomoSettings.hostUrl + 'matomo.php']);
(window as any)._paq.push(['setSiteId', matomoSettings.siteId]);
(window as any)._paq.push(['setTrackerUrl', environment.matomo.hostUrl + 'matomo.php']);
(window as any)._paq.push(['setSiteId', environment.matomo.siteId]);
(window as any)._paq.push(['enableLinkTracking']);

const g = document.createElement('script');
g.type = 'text/javascript';
g.async = true;
g.defer = true;
g.src = matomoSettings.hostUrl + 'matomo.js';
g.src = environment.matomo.hostUrl + 'matomo.js';
document.getElementsByTagName('head')[0].appendChild(g);
}

Expand Down
7 changes: 0 additions & 7 deletions src/matomo/matomo-settings.ts

This file was deleted.

0 comments on commit 4c2e997

Please sign in to comment.