diff --git a/package.json b/package.json index e35868c..f117b4b 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "html-to-text": "^5.1.1", "inquirer": "^7.1.0", "ioredis": "^4.17.1", + "matomo-tracker": "^2.2.2", "migrate-mongoose": "^4.0.0", "mjml": "^4.6.3", "mongoose": "^5.9.11", diff --git a/src/service/index.ts b/src/service/index.ts index 98e4816..56d20a8 100644 --- a/src/service/index.ts +++ b/src/service/index.ts @@ -5,6 +5,7 @@ import Redis from 'ioredis'; import { PinoLogger } from 'nestjs-pino/dist'; import { authServices } from './auth'; import { formServices } from './form'; +import { InstallationMetricsService } from './installation.metrics.service'; import { MailService } from './mail.service'; import { profileServices } from './profile'; import { submissionServices } from './submission'; @@ -17,6 +18,7 @@ export const services = [ ...authServices, ...submissionServices, MailService, + InstallationMetricsService, { provide: 'PUB_SUB', inject: [ConfigService, PinoLogger], diff --git a/src/service/installation.metrics.service.ts b/src/service/installation.metrics.service.ts new file mode 100644 index 0000000..8257f95 --- /dev/null +++ b/src/service/installation.metrics.service.ts @@ -0,0 +1,29 @@ +import { Injectable, OnApplicationBootstrap } from '@nestjs/common'; +import MatomoTracker from 'matomo-tracker'; +import { PinoLogger } from 'nestjs-pino/dist'; + +@Injectable() +export class InstallationMetricsService implements OnApplicationBootstrap { + private host = 'https://metrics.ohmyform.com/matomo.php' + + constructor( + private readonly logger: PinoLogger, + ) { + } + + async onApplicationBootstrap(): Promise { + const tracker = new MatomoTracker(1, this.host) + + tracker.on('error', () => { + this.logger.error('failed to register instance') + }) + + tracker.track({ + // eslint-disable-next-line @typescript-eslint/camelcase + action_name: 'startup', + ua: process.arch + }) + } + + +} diff --git a/yarn.lock b/yarn.lock index f975323..d6856b2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6816,6 +6816,11 @@ map-visit@^1.0.0: dependencies: object-visit "^1.0.0" +matomo-tracker@^2.2.2: + version "2.2.2" + resolved "https://registry.yarnpkg.com/matomo-tracker/-/matomo-tracker-2.2.2.tgz#685937f90b318fbda6768260f11cacab471d9bcd" + integrity sha512-xAeojX+LwXn+UHd6A72DbVkqc4a1a6SKCiQPBwpKA6x4R1qy1Nysg3kEfsh6Xq+bzPjcvn2ppDQb9JXcktmJDQ== + md5.js@^1.3.4: version "1.3.5" resolved "https://registry.yarnpkg.com/md5.js/-/md5.js-1.3.5.tgz#b5d07b8e3216e3e27cd728d72f70d1e6a342005f"