Skip to content

Commit

Permalink
Merge branch 'feature/small-fixes' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
musicEnfanthen committed Oct 9, 2020
2 parents ced3a78 + 3378f8d commit 525e4f3
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 33 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 10 additions & 0 deletions src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}).
Expand Down
91 changes: 62 additions & 29 deletions src/app/core/services/analytics-sercvice/analytics.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
*
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}
2 changes: 0 additions & 2 deletions src/app/shared/external-link/external-link.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
17 changes: 17 additions & 0 deletions tsconfig.doc.json
Original file line number Diff line number Diff line change
@@ -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/**/*"]
}

0 comments on commit 525e4f3

Please sign in to comment.