Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add tracking service to portalicious #6539

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion interfaces/Portalicious/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module.exports = tseslint.config(
],
'@angular-eslint/component-max-inline-declarations': [
'error',
{ template: 10 },
{ template: 20 },
],
'@angular-eslint/no-async-lifecycle-method': ['error'],
'@angular-eslint/no-conflicting-lifecycle': ['error'],
Expand Down
32 changes: 3 additions & 29 deletions interfaces/Portalicious/src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,18 @@ import {
withComponentInputBinding,
} from '@angular/router';

import { parseMatomoConnectionString } from '_matomo.utils.mjs';
import {
provideTanStackQuery,
QueryClient,
} from '@tanstack/angular-query-experimental';
import { provideMatomo, withRouter } from 'ngx-matomo-client';
import { providePrimeNG } from 'primeng/config';

import { AppRoutes, routes } from '~/app.routes';
import { routes } from '~/app.routes';
import AppTheme from '~/app.theme';
import { CustomPageTitleStrategy } from '~/app.title-strategy';
import { AuthService } from '~/services/auth.service';
import { TrackingService } from '~/services/tracking.service';
import { Locale } from '~/utils/locale';
import { environment } from '~environment';

const conditionalProvideMatomo = () => {
const connectionInfo = parseMatomoConnectionString(
environment.matomo_connection_string,
);
if (!connectionInfo.id || !connectionInfo.api || !connectionInfo.sdk) {
return [];
}
return provideMatomo(
{
siteId: connectionInfo.id,
trackerUrl: connectionInfo.api,
trackerUrlSuffix: '', // Should be included in `connectionInfo.api` used as `trackerUrl`
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- `scriptUrl` seems to be expecting more than only a string
scriptUrl: connectionInfo.sdk,
enableJSErrorTracking: true,
requireConsent: 'none',
runOutsideAngularZone: true,
},
withRouter({
exclude: [new RegExp(AppRoutes.authCallback)],
}),
);
};

export const getAppConfig = (locale: Locale): ApplicationConfig => ({
providers: [
Expand Down Expand Up @@ -95,8 +69,8 @@ export const getAppConfig = (locale: Locale): ApplicationConfig => ({
}),
),
...AuthService.APP_PROVIDERS,
...TrackingService.APP_PROVIDERS,
{ provide: TitleStrategy, useClass: CustomPageTitleStrategy },
{ provide: LOCALE_ID, useValue: locale },
conditionalProvideMatomo(),
],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';

@Component({
selector: 'app-privacy-copy-no-tracking',
imports: [],
template: `
<p i18n>
We do not share any personal information with other third-parties.
</p>
`,
styles: ``,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class PrivacyCopyNoTrackingComponent {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';

@Component({
selector: 'app-privacy-copy-tracking',
imports: [],
template: `
<p i18n>
We use the external "<em>Matomo Cloud</em>"-service by InnoCraft Ltd. to
measure the usage of the 121 Platform.
</p>
<p i18n>
We do not share any personal information with Matomo/InnoCraft Ltd. Our
use of their service is covered by the
<a
href="https://matomo.org/matomo-cloud-privacy-policy/"
target="_blank"
>Matomo Cloud Privacy Policy</a
>
and the
<a
href="https://matomo.org/matomo-cloud-dpa/"
target="_blank"
>Matomo Cloud Data Processing Agreement</a
>.
</p>
`,
styles: ``,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class PrivacyCopyTrackingComponent {}
26 changes: 1 addition & 25 deletions interfaces/Portalicious/src/app/pages/privacy/privacy.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,31 +71,7 @@ <h2 i18n>Who we share information with</h2>
The data of the 121 Platform is hosted in a Microsoft Azure-environment of
The Netherlands Red Cross.
</p>
@if (isMatomoEnabled) {
<p i18n>
We use the external "<em>Matomo Cloud</em>"-service by InnoCraft Ltd. to
measure the usage of the 121 Platform.
</p>
<p i18n>
We do not share any personal information with Matomo/InnoCraft Ltd. Our
use of their service is covered by the
<a
href="https://matomo.org/matomo-cloud-privacy-policy/"
target="_blank"
>Matomo Cloud Privacy Policy</a
>
and the
<a
href="https://matomo.org/matomo-cloud-dpa/"
target="_blank"
>Matomo Cloud Data Processing Agreement</a
>.
</p>
} @else {
<p i18n>
We do not share any personal information with other third-parties.
</p>
}
<ng-container *ngComponentOutlet="TrackingCopyComponent"></ng-container>

<h2 i18n>Cookies</h2>

Expand Down
12 changes: 7 additions & 5 deletions interfaces/Portalicious/src/app/pages/privacy/privacy.page.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { DatePipe } from '@angular/common';
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { DatePipe, NgComponentOutlet } from '@angular/common';
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';

import { PageLayoutComponent } from '~/components/page-layout/page-layout.component';
import { environment } from '~environment';
import { TrackingService } from '~/services/tracking.service';

@Component({
selector: 'app-privacy-page',
imports: [PageLayoutComponent, DatePipe],
imports: [PageLayoutComponent, DatePipe, NgComponentOutlet],
templateUrl: './privacy.page.html',
styles: ``,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class PrivacyPageComponent {
public isMatomoEnabled = !!environment.matomo_connection_string;
readonly trackingService = inject(TrackingService);

TrackingCopyComponent = this.trackingService.PrivacyCopyComponent;
}
58 changes: 58 additions & 0 deletions interfaces/Portalicious/src/app/services/tracking.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Injectable } from '@angular/core';

import { parseMatomoConnectionString } from '_matomo.utils.mjs';
import { provideMatomo, withRouter } from 'ngx-matomo-client';

import { AppRoutes } from '~/app.routes';
import { PrivacyCopyNoTrackingComponent } from '~/components/privacy/privacy-copy-no-tracking.component';
import { PrivacyCopyTrackingComponent } from '~/components/privacy/privacy-copy-tracking.component';
import { environment } from '~environment';

const MATOMO_CONNECTION_INFO = parseMatomoConnectionString(
environment.matomo_connection_string,
);

const IS_MATOMO_ENABLED = () =>
MATOMO_CONNECTION_INFO.id &&
MATOMO_CONNECTION_INFO.api &&
MATOMO_CONNECTION_INFO.sdk;

@Injectable({
providedIn: 'root',
})
export class TrackingService {
public static APP_PROVIDERS = IS_MATOMO_ENABLED()
? [
provideMatomo(
{
siteId: MATOMO_CONNECTION_INFO.id,
trackerUrl: MATOMO_CONNECTION_INFO.api,
trackerUrlSuffix: '', // Should be included in `connectionInfo.api` used as `trackerUrl`

scriptUrl: MATOMO_CONNECTION_INFO.sdk,
enableJSErrorTracking: true,
requireConsent: 'none',
runOutsideAngularZone: true,
},
withRouter({
exclude: [new RegExp(AppRoutes.authCallback)],
}),
),
]
: [];

public get PrivacyCopyComponent() {
return IS_MATOMO_ENABLED()
? PrivacyCopyTrackingComponent
: PrivacyCopyNoTrackingComponent;
}

// TODO: AB#33807 - implement and use this function
public trackEvent() {
if (!IS_MATOMO_ENABLED()) {
return;
}

// track event to matomo
}
}
Loading