diff --git a/.env.example b/.env.example index 60fd4e3152..6958133a0a 100644 --- a/.env.example +++ b/.env.example @@ -6,7 +6,7 @@ TOOLJET_HOST=http://localhost:8082 LOCKBOX_MASTER_KEY=0000000000000000000000000000000000000000000000000000000000000000 SECRET_KEY_BASE=replace_with_secret_key_base -## Configure a hostname for the server +## Configure a hostname for the server SERVER_HOST= # DATABASE CONFIG @@ -16,9 +16,14 @@ PG_USER= PG_HOST= PG_PASS= -# Checks every 24 hours to see if a new version of ToolJet is available (Enabled by default. Set 0 to disable) +# Checks every 24 hours to see if a new version of ToolJet is available +# (Enabled by default. Set 0 to disable) CHECK_FOR_UPDATES=0 +# Checks every 24 hours to update app telemetry data to ToolJet hub. +# (Telemetry is enabled by default. Set value to true to disable.) +# DISABLE_APP_TELEMETRY=false + GOOGLE_CLIENT_ID= GOOGLE_CLIENT_SECRET= @@ -45,4 +50,4 @@ SSO_DISABLE_SIGNUP= SSO_RESTRICTED_DOMAIN= SSO_GOOGLE_OAUTH2_CLIENT_ID= SSO_GIT_OAUTH2_CLIENT_ID= -SSO_GIT_OAUTH2_CLIENT_SECRET= \ No newline at end of file +SSO_GIT_OAUTH2_CLIENT_SECRET= diff --git a/docs/docs/deployment/env-vars.md b/docs/docs/deployment/env-vars.md index 2ec9da9ad8..c9380d3fd6 100644 --- a/docs/docs/deployment/env-vars.md +++ b/docs/docs/deployment/env-vars.md @@ -46,7 +46,7 @@ Self-hosted version of ToolJet pings our server to fetch the latest product upda #### Comment feature enable ( optional ) -Use this environment variable to enable/disable the feature that allows you to add comments on the canvas. +Use this environment variable to enable/disable the feature that allows you to add comments on the canvas. | variable | value | | -------- | ---------------------- | @@ -135,7 +135,7 @@ Specify application monitoring vendor. Currently supported values - `sentry`. #### SENTRY DEBUG ( optional ) -Prints logs for sentry. +Prints logs for sentry. | variable | description | | ---------- | ----------------------------------------- | @@ -167,6 +167,11 @@ Tooljet needs to be configured for custom CA certificate to be able to trust and | ------------------ | ----------------------------------------------------------------- | | NODE_EXTRA_CA_CERTS | absolute path to certifcate PEM file ( eg: /ToolJet/ca/cert.pem ) | + +#### Disable telemetry ( optional ) + +Pings our server to update the total user count every 24 hours. You can disable this by setting the value of `DISABLE_TOOLJET_TELEMETRY` environment variable to `true`. This feature is enabled by default. + ## ToolJet client #### Server URL ( optionally required ) diff --git a/server/src/controllers/metadata.controller.ts b/server/src/controllers/metadata.controller.ts index 8ba78bb267..cd29aba807 100644 --- a/server/src/controllers/metadata.controller.ts +++ b/server/src/controllers/metadata.controller.ts @@ -13,7 +13,9 @@ export class MetadataController { const installedVersion = globalThis.TOOLJET_VERSION; const metadata = await this.metadataService.getMetaData(); - await this.metadataService.finishInstallation(metadata, installedVersion, name, email, org); + if (process.env.NODE_ENV == 'production') { + await this.metadataService.finishInstallation(metadata, installedVersion, name, email, org); + } await this.metadataService.updateMetaData({ onboarded: true, @@ -56,10 +58,16 @@ export class MetadataController { const updateLastCheckedAt = new Date(data['last_checked'] || null); const diffTime = (now.getTime() - updateLastCheckedAt.getTime()) / 1000; - if (diffTime > 86400) { - const result = await this.metadataService.checkForUpdates(installedVersion, ignoredVersion); - latestVersion = result.latestVersion; - versionIgnored = false; + if (diffTime > 86400 && process.env.NODE_ENV == 'production') { + if (process.env.CHECK_FOR_UPDATES) { + const result = await this.metadataService.checkForUpdates(installedVersion, ignoredVersion); + latestVersion = result.latestVersion; + versionIgnored = false; + } + + if (!process.env.DISABLED_TOOLJET_TELEMETRY) { + await this.metadataService.sendTelemetryData(metadata); + } } return { diff --git a/server/src/services/metadata.service.ts b/server/src/services/metadata.service.ts index 60eadc6308..bdd69ea9b5 100644 --- a/server/src/services/metadata.service.ts +++ b/server/src/services/metadata.service.ts @@ -1,9 +1,11 @@ import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; -import { Repository } from 'typeorm'; +import { getManager, Repository } from 'typeorm'; import { Metadata } from 'src/entities/metadata.entity'; import { gt } from 'semver'; -const got = require('got'); +import got from 'got'; +import { User } from 'src/entities/user.entity'; + @Injectable() export class MetadataService { constructor( @@ -30,7 +32,9 @@ export class MetadataService { async updateMetaData(newOptions: any) { const metadata = await this.metadataRepository.findOne({}); - return await this.metadataRepository.update(metadata.id, { data: { ...metadata.data, ...newOptions } }); + return await this.metadataRepository.update(metadata.id, { + data: { ...metadata.data, ...newOptions }, + }); } async finishInstallation(metadata: any, installedVersion: string, name: string, email: string, org: string) { @@ -46,6 +50,18 @@ export class MetadataService { }); } + async sendTelemetryData(metadata: Metadata) { + const totalUserCount = await getManager().count(User); + + return await got('https://hub.tooljet.io/telemetry', { + method: 'post', + json: { + id: metadata.id, + total_users: totalUserCount, + }, + }); + } + async checkForUpdates(installedVersion: string, ignoredVersion: string) { const response = await got('https://hub.tooljet.io/updates', { method: 'post',