diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 0053584133..ebc50abcbd 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -4,10 +4,11 @@ on: push: branches: - '**' + - '!master' # do not run on master tags-ignore: - '*' paths-ignore: - - '**.md' + - '**.md' # ignore changes to markdown files jobs: test: diff --git a/package.json b/package.json index 3587702c48..41c1cc9d3a 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "format:check": "prettier --check \"src/**/*.{ts,js,css,html}\"", "format:write": "prettier --write \"src/**/*.{ts,js,css,html}\"", "format:fix-staged": "pretty-quick --staged", - "doc": "yarn compodoc --tsconfig tsconfig.base.json --theme Readthedocs --output dist/awg-app/compodoc --disableRoutesGraph", + "doc": "yarn compodoc --tsconfig tsconfig.doc.json --theme Readthedocs --output dist/awg-app/compodoc --disableRoutesGraph", "serve:doc": "yarn doc --serve --watch", "build:doc": "yarn doc", "build": "ng build", diff --git a/src/app/app.config.ts b/src/app/app.config.ts index 5642c36e0a..92335b7b33 100644 --- a/src/app/app.config.ts +++ b/src/app/app.config.ts @@ -26,6 +26,16 @@ export class AppConfig { return 'https://www.google-analytics.com/'; } + /** + * Getter for the Analytics id + * ({@link 'UA-XXXXXXX-Y'}). + * + * @returns {string} + */ + public static get ANALYTICS_ID(): string { + return 'UA-64657372-2'; + } + /** * Getter for the URL of the Inseri Test Instance * ({@link http://test-nieos.nie-ine.ch}). diff --git a/src/app/core/services/analytics-sercvice/analytics.service.ts b/src/app/core/services/analytics-sercvice/analytics.service.ts index acea51ee53..6aa5bc3ebe 100644 --- a/src/app/core/services/analytics-sercvice/analytics.service.ts +++ b/src/app/core/services/analytics-sercvice/analytics.service.ts @@ -41,7 +41,7 @@ export class AnalyticsService { * * It stores the analytics object. */ - private analyticsConfig: AnalyticsConfig = { trackingId: 'UA-64657372-2' }; + private analyticsConfig: AnalyticsConfig = { trackingId: AppConfig.ANALYTICS_ID }; /** * Private variable: isInitialized. @@ -77,17 +77,18 @@ export class AnalyticsService { } // set the page to be tracked - (window as any).ga('set', 'page', page); + this.runAnalytics('set', 'page', page); // Send a pageview hit from that page - (window as any).ga('send', 'pageview'); + this.runAnalytics('send', 'pageview'); } /** * Private method: initializeAnalytics. * - * It initializes the Analytics setup by setting the analytics object - * and a boolean flag for successful initialization. + * It initializes the Analytics environment by setting + * the global analytics object and + * a boolean flag for successful initialization. * * @param {AnalyticsConfig} config The given config object. * @@ -100,6 +101,46 @@ export class AnalyticsService { return; } + this.createAnalytics(config); + + // enable debug mode if needed + if (config.debug) { + (window as any).ga_debug = { trace: true }; + } + + // create tracker + if (config.cookieDomain) { + // create a tracker with custom cookie domain configuration + this.runAnalytics('create', config.trackingId, { + cookieDomain: config.cookieDomain + }); + } else { + // create a default tracker with automatic cookie domain configuration + this.runAnalytics('create', config.trackingId, 'auto'); + } + + // ignore non-production page calls + // cf. https://developers.google.com/analytics/devguides/collection/analyticsjs/debugging#testing_your_implementation_without_sending_hits + /* istanbul ignore else */ + if (!(document.location.hostname === 'edition.anton-webern.ch')) { + console.log('Running non-production analytics replacement now'); + this.runAnalytics('set', 'sendHitTask', null); + } + + // flag for successful initialization + this.isInitialized = true; + } + + /** + * Private method: createAnalytics. + * + * It creates a global Analytics object and loads the necessary JS file. + * + * @param {AnalyticsConfig} config The given config object. + * + * @returns {void} Creates the global analytics object. + */ + private createAnalytics(config: AnalyticsConfig): void { // set debug or default version of analytics.js const analyticsJS = config.debug ? 'analytics_debug.js' : 'analytics.js'; const analyticsURL = AppConfig.ANALYTICS_ENDPOINT + analyticsJS; @@ -142,32 +183,24 @@ export class AnalyticsService { a.src = g; m.parentNode.insertBefore(a, m); })(window, document, 'script', analyticsURL, 'ga'); + } - // enable debug mode if needed - if (config.debug) { - (window as any).ga_debug = { trace: true }; - } - - // create tracker - if (config.cookieDomain) { - // create a tracker with custom cookie domain configuration - (window as any).ga('create', config.trackingId, { - cookieDomain: config.cookieDomain - }); + /** + * Private method: runAnalytics. + * + * It runs a given task on the global Analytics object. + * + * @param {string} task The given task method. + * @param {string} field The given field. + * @param {string} [option] The given option. + * + * @returns {void} Runs a task on the global analytics object. + */ + private runAnalytics(task: string, field: string, option?: any): void { + if (option || option === null) { + (window as any).ga(task, field, option); } else { - // create a default tracker with automatic cookie domain configuration - (window as any).ga('create', config.trackingId, 'auto'); - } - - // ignore non-production page calls - // cf. https://developers.google.com/analytics/devguides/collection/analyticsjs/debugging#testing_your_implementation_without_sending_hits - /* istanbul ignore else */ - if (!(document.location.hostname === 'edition.anton-webern.ch')) { - console.log('Running non-production google analytics replacement now'); - (window as any).ga('set', 'sendHitTask', null); + (window as any).ga(task, field); } - - // flag for successful initialization - this.isInitialized = true; } } diff --git a/src/app/shared/external-link/external-link.directive.spec.ts b/src/app/shared/external-link/external-link.directive.spec.ts index 87f142e932..316b524cc9 100644 --- a/src/app/shared/external-link/external-link.directive.spec.ts +++ b/src/app/shared/external-link/external-link.directive.spec.ts @@ -64,8 +64,6 @@ describe('ExternalLinkDirective', () => { aDes = fixture.debugElement.queryAll(By.directive(ExternalLinkDirective)); expect(aDes.length).toBe(4, 'should be 4'); - - console.log(aDes); }); it('should have 1 anchor element without href attributes', () => { diff --git a/tsconfig.doc.json b/tsconfig.doc.json new file mode 100644 index 0000000000..6eb7d2a1d4 --- /dev/null +++ b/tsconfig.doc.json @@ -0,0 +1,17 @@ +{ + "extends": "./tsconfig.base.json", + "compilerOptions": { + "baseUrl": "./src/", + "outDir": "./out-tsc/app", + "types": ["node"], + "paths": { + "@awg-app/*": ["app/*"], + "@awg-core/*": ["app/core/*"], + "@awg-shared/*": ["app/shared/*"], + "@awg-side-info/*": ["app/side-info/*"], + "@awg-views/*": ["app/views/*"] + } + }, + "include": ["src/main.ts", "src/polyfills.ts", "src/**/*.d.ts", "src/**/*.ts"], + "exclude": ["src/test.ts", "src/**/*.spec.ts", "src/testing/", "e2e/**/*"] +}