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

feat(analytics): Google Analytics・同意モード・一部機能のトラッキング実装 #784

Merged
merged 2 commits into from
Nov 5, 2024
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 .config/docker_example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,4 @@ signToActivityPubGet: true
#maxFileSize: 262144000

# Value of Content-Security-Policy header
#contentSecurityPolicy: "script-src 'self' 'unsafe-eval' https://challenges.cloudflare.com https://hcaptcha.com https://*.hcaptcha.com https://www.google.com/recaptcha/ https://www.gstatic.com/recaptcha/ https://www.recaptcha.net/recaptcha/; base-uri 'self'; object-src 'self';"
#contentSecurityPolicy: "script-src 'self' 'unsafe-eval' https://challenges.cloudflare.com https://hcaptcha.com https://*.hcaptcha.com https://www.google.com/recaptcha/ https://www.gstatic.com/recaptcha/ https://www.recaptcha.net/recaptcha/ https://www.googletagmanager.com/; base-uri 'self'; object-src 'self';"
6 changes: 3 additions & 3 deletions .config/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ redis:
# ┌───────────────────────────┐
#───┘ MeiliSearch configuration └─────────────────────────────

# You can set scope to local (default value) or global
# You can set scope to local (default value) or global
# (include notes from remote).

#meilisearch:
Expand Down Expand Up @@ -214,7 +214,7 @@ proxyRemoteFiles: true
signToActivityPubGet: true

# For security reasons, uploading attachments from the intranet is prohibited,
# but exceptions can be made from the following settings. Default value is "undefined".
# but exceptions can be made from the following settings. Default value is "undefined".
# Read changelog to learn more (Improvements of 12.90.0 (2021/09/04)).
#allowedPrivateNetworks: [
# '127.0.0.1/32'
Expand All @@ -227,4 +227,4 @@ signToActivityPubGet: true
#pidFile: /tmp/misskey.pid

# Value of Content-Security-Policy header
#contentSecurityPolicy: "script-src 'self' 'unsafe-eval' https://challenges.cloudflare.com https://hcaptcha.com https://*.hcaptcha.com https://www.google.com/recaptcha/ https://www.gstatic.com/recaptcha/ https://www.recaptcha.net/recaptcha/; base-uri 'self'; object-src 'self';"
#contentSecurityPolicy: "script-src 'self' 'unsafe-eval' https://challenges.cloudflare.com https://hcaptcha.com https://*.hcaptcha.com https://www.google.com/recaptcha/ https://www.gstatic.com/recaptcha/ https://www.recaptcha.net/recaptcha/ https://www.googletagmanager.com/; base-uri 'self'; object-src 'self';"
14 changes: 14 additions & 0 deletions locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,20 @@ here: "here"
mutualLink: "Mutual Link"
saveThisFile: "Save this file to Drive"
changeUserName: "Change name"
gtagConsentCustomize: "Data Collection and Privacy Settings"
gtagConsentCustomizeDescription: "You can customize the scope of data collected by {host}.\nHowever, you cannot disable the collection of security-related information such as authentication features, fraud prevention, and other user protections."
gtagConsentAnalytics: "Collection of Statistical Information"
gtagConsentAnalyticsDescription: "Enable the storage (cookies, etc.) of analytics-related information such as site visit duration."
gtagConsentFunctionality: "Collection of Feature and Setting Usage"
gtagConsentFunctionalityDescription: "Enable the storage of information that supports website or app features, such as language settings."
gtagConsentPersonalization: "Collection of Personalized Information"
gtagConsentPersonalizationDescription: "Enable the storage of personalization-related information such as recommended posts."
helpUsImproveUserExperience: "To build the future of Misskey,\nplease help us by agreeing to data collection!"
pleaseConsentToTracking: "{host} may collect information that may include personal data such as your IP address, usage data, and device information during your use, based on our [Privacy Policy]({privacyPolicyUrl}), for the purpose of providing and operating the service and improving the user experience.\n\nThe collected data will be used for future feature development, operational policy decisions, and identifying areas for service improvement."
consentEssential: "Allow Essential Items"
consentAll: "Allow All Items"
consentSelected: "Allow Selected Items"

_bubbleGame:
howToPlay: "How to play"
hold: "Hold"
Expand Down
56 changes: 56 additions & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5150,6 +5150,62 @@ export interface Locale extends ILocale {
* 名前を変更
*/
"changeUserName": string;
/**
* データ収集とプライバシー設定
*/
"gtagConsentCustomize": string;
/**
* {host}が収集するデータの範囲をカスタマイズできます。
* ただし、認証機能、不正行為防止、その他のユーザー保護など、セキュリティに関連する情報の収集は無効化できません。
*/
"gtagConsentCustomizeDescription": ParameterizedString<"host">;
/**
* 統計情報の収集
*/
"gtagConsentAnalytics": string;
/**
* サイトの滞在時間など、分析に関連する情報の保存(Cookie など)を有効にします。
*/
"gtagConsentAnalyticsDescription": string;
/**
* 機能・設定の利用状況の収集
*/
"gtagConsentFunctionality": string;
/**
* 言語設定など、ウェブサイトやアプリの機能をサポートする情報の保存を有効にします。
*/
"gtagConsentFunctionalityDescription": string;
/**
* パーソナライズされた情報の収集
*/
"gtagConsentPersonalization": string;
/**
* おすすめの投稿など、パーソナライズに関連する情報の保存を有効にします。
*/
"gtagConsentPersonalizationDescription": string;
/**
* Misskeyの明日を作るために、
* データ収集にご協力ください!
*/
"helpUsImproveUserExperience": string;
/**
* {host}は[プライバシーポリシー]({privacyPolicyUrl})に基づき、サービスの提供・運営・ユーザー体験の向上のためにご利用中のIPアドレス、利用状況、デバイス情報等、個人情報を含む可能性のある情報を収集することがあります。
*
* 収集されたデータは今後の機能の開発、運営の方針の決定、サービスの改善点の特定に利用されます。
*/
"pleaseConsentToTracking": ParameterizedString<"host" | "privacyPolicyUrl">;
/**
* 必須項目のみ許可
*/
"consentEssential": string;
/**
* 全て許可
*/
"consentAll": string;
/**
* 選択した項目のみ許可
*/
"consentSelected": string;
"_bubbleGame": {
/**
* 遊び方
Expand Down
13 changes: 13 additions & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,19 @@ here: "こちら"
mutualLink: "相互リンク"
saveThisFile: "このファイルをドライブに保存する"
changeUserName: "名前を変更"
gtagConsentCustomize: "データ収集とプライバシー設定"
gtagConsentCustomizeDescription: "{host}が収集するデータの範囲をカスタマイズできます。\nただし、認証機能、不正行為防止、その他のユーザー保護など、セキュリティに関連する情報の収集は無効化できません。"
gtagConsentAnalytics: "統計情報の収集"
gtagConsentAnalyticsDescription: "サイトの滞在時間など、分析に関連する情報の保存(Cookie など)を有効にします。"
gtagConsentFunctionality: "機能・設定の利用状況の収集"
gtagConsentFunctionalityDescription: "言語設定など、ウェブサイトやアプリの機能をサポートする情報の保存を有効にします。"
gtagConsentPersonalization: "パーソナライズされた情報の収集"
gtagConsentPersonalizationDescription: "おすすめの投稿など、パーソナライズに関連する情報の保存を有効にします。"
helpUsImproveUserExperience: "Misskeyの明日を作るために、\nデータ収集にご協力ください!"
pleaseConsentToTracking: "{host}は[プライバシーポリシー]({privacyPolicyUrl})に基づき、サービスの提供・運営・ユーザー体験の向上のためにご利用中のIPアドレス、利用状況、デバイス情報等、個人情報を含む可能性のある情報を収集することがあります。\n\n収集されたデータは今後の機能の開発、運営の方針の決定、サービスの改善点の特定に利用されます。"
consentEssential: "必須項目のみ許可"
consentAll: "全て許可"
consentSelected: "選択した項目のみ許可"

_bubbleGame:
howToPlay: "遊び方"
Expand Down
14 changes: 14 additions & 0 deletions locales/ko-KR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,20 @@ here: "여기"
mutualLink: "서로링크"
saveThisFile: "이 파일을 드라이브에 저장"
changeUserName: "이름 변경"
gtagConsentCustomize: "데이터 수집 및 개인정보 설정"
gtagConsentCustomizeDescription: "{host}에서 수집하는 데이터 범위를 사용자 지정할 수 있습니다.\n다만, 인증 기능, 부정 행위 방지, 기타 사용자 보호 등 보안과 관련된 정보 수집은 비활성화할 수 없습니다."
gtagConsentAnalytics: "통계 정보 수집"
gtagConsentAnalyticsDescription: "사이트 체류 시간 등 분석 관련 정보 저장(쿠키 등)을 활성화합니다."
gtagConsentFunctionality: "기능 및 설정 사용 정보 수집"
gtagConsentFunctionalityDescription: "언어 설정 등 웹사이트나 앱의 기능을 지원하는 정보 저장을 활성화합니다."
gtagConsentPersonalization: "개인 맞춤형 정보 수집"
gtagConsentPersonalizationDescription: "추천 게시물 등 개인화 관련 정보 저장을 활성화합니다."
helpUsImproveUserExperience: "Misskey의 미래를 위해,\n데이터 수집에 협조해 주세요!"
pleaseConsentToTracking: "{host}는 [개인정보 처리방침]({privacyPolicyUrl})에 따라 서비스 제공, 운영, 사용자 경험 향상을 위해 사용 중인 IP 주소, 이용 현황, 디바이스 정보 등 개인 정보를 포함할 수 있는 정보를 수집할 수 있습니다.\n\n수집된 데이터는 향후 기능 개발, 운영 방침 결정, 서비스 개선점 파악에 활용됩니다."
consentEssential: "필수 항목만 허용"
consentAll: "모두 허용"
consentSelected: "선택한 항목만 허용"

_bubbleGame:
howToPlay: "설명"
hold: "홀드"
Expand Down
11 changes: 11 additions & 0 deletions packages/backend/migration/1730629332694-GoogleAnalyticsId.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export class GoogleAnalyticsId1730629332694 {
name = 'GoogleAnalyticsId1730629332694'

async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "meta" ADD "googleAnalyticsId" character varying(32)`);
}

async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "googleAnalyticsId"`);
}
}
5 changes: 2 additions & 3 deletions packages/backend/src/NestLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
*/

import { LoggerService } from '@nestjs/common';
import Logger from '@/logger.js';
import { coreLogger } from '@/logger.js';

const logger = new Logger('core', 'cyan');
const nestLogger = logger.createSubLogger('nest', 'green', false);
const nestLogger = coreLogger.createSubLogger('nest', 'green', false);

export class NestLogger implements LoggerService {
/**
Expand Down
15 changes: 7 additions & 8 deletions packages/backend/src/boot/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { EventEmitter } from 'node:events';
import process from 'node:process';
import chalk from 'chalk';
import Xev from 'xev';
import Logger from '@/logger.js';
import { coreLogger } from '@/logger.js';
import { envOption } from '../env.js';
import { masterMain } from './master.js';
import { workerMain } from './worker.js';
Expand All @@ -24,8 +24,7 @@ process.title = `Misskey (${cluster.isPrimary ? 'master' : 'worker'})`;
Error.stackTraceLimit = Infinity;
EventEmitter.defaultMaxListeners = 128;

const logger = new Logger('core', 'cyan');
const clusterLogger = logger.createSubLogger('cluster', 'orange', false);
const clusterLogger = coreLogger.createSubLogger('cluster', 'orange', false);
const ev = new Xev();

//#region Events
Expand Down Expand Up @@ -53,12 +52,12 @@ if (cluster.isPrimary && !envOption.disableClustering) {
});

process.on('SIGINT', () => {
logger.warn(chalk.yellow('Process received SIGINT'));
coreLogger.warn(chalk.yellow('Process received SIGINT'));
isShuttingDown = true;
});

process.on('SIGTERM', () => {
logger.warn(chalk.yellow('Process received SIGTERM'));
coreLogger.warn(chalk.yellow('Process received SIGTERM'));
isShuttingDown = true;
});
}
Expand All @@ -71,18 +70,18 @@ if (!envOption.quiet) {
// Display detail of uncaught exception
process.on('uncaughtException', err => {
try {
logger.error(`Uncaught exception: ${err.message}`, { error: err });
coreLogger.error(`Uncaught exception: ${err.message}`, { error: err });
} catch { }
});

// Dying away...
process.on('exit', code => {
logger.warn(chalk.yellow(`The process is going to exit with code ${code}`));
coreLogger.warn(chalk.yellow(`The process is going to exit with code ${code}`));
});

process.on('warning', warning => {
if ((warning as never)['code'] !== 'MISSKEY_SHUTDOWN') return;
logger.warn(chalk.yellow(`${warning.message}: ${(warning as never)['detail']}`));
coreLogger.warn(chalk.yellow(`${warning.message}: ${(warning as never)['detail']}`));
for (const id in cluster.workers) cluster.workers[id]?.process.kill('SIGTERM');
process.exit();
});
Expand Down
5 changes: 2 additions & 3 deletions packages/backend/src/boot/master.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as os from 'node:os';
import cluster from 'node:cluster';
import chalk from 'chalk';
import chalkTemplate from 'chalk-template';
import Logger from '@/logger.js';
import { coreLogger } from '@/logger.js';
import { loadConfig } from '@/config.js';
import type { Config } from '@/config.js';
import { showMachineInfo } from '@/misc/show-machine-info.js';
Expand All @@ -22,8 +22,7 @@ const _dirname = dirname(_filename);

const meta = JSON.parse(fs.readFileSync(`${_dirname}/../../../../built/meta.json`, 'utf-8'));

const logger = new Logger('core', 'cyan');
const bootLogger = logger.createSubLogger('boot', 'magenta', false);
const bootLogger = coreLogger.createSubLogger('boot', 'magenta', false);

const themeColor = chalk.hex('#86b300');

Expand Down
4 changes: 3 additions & 1 deletion packages/backend/src/core/DriveService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { RoleService } from '@/core/RoleService.js';
import { correctFilename } from '@/misc/correct-filename.js';
import { isMimeImage } from '@/misc/is-mime-image.js';
import { ModerationLogService } from '@/core/ModerationLogService.js';
import { LoggerService } from '@/core/LoggerService.js';

type AddFileArgs = {
/** User who wish to add file */
Expand Down Expand Up @@ -123,12 +124,13 @@ export class DriveService {
private globalEventService: GlobalEventService,
private queueService: QueueService,
private roleService: RoleService,
private loggerService: LoggerService,
private moderationLogService: ModerationLogService,
private driveChart: DriveChart,
private perUserDriveChart: PerUserDriveChart,
private instanceChart: InstanceChart,
) {
const logger = new Logger('drive', 'blue');
const logger = this.loggerService.getLogger('drive', 'blue');
this.registerLogger = logger.createSubLogger('register', 'yellow');
this.downloaderLogger = logger.createSubLogger('downloader');
this.deleteLogger = logger.createSubLogger('delete');
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/core/FetchInstanceMetadataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class FetchInstanceMetadataService {
throw err.statusCode ?? err.message;
});

this.logger.succ(`Successfuly fetched nodeinfo of ${instance.host}`);
this.logger.succ(`Successfully fetched nodeinfo of ${instance.host}`);

return info as NodeInfo;
} catch (err) {
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/core/LoggerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { Injectable } from '@nestjs/common';
import Logger from '@/logger.js';
import { rootLogger } from '@/logger.js';
import { bindThis } from '@/decorators.js';
import type { KEYWORD } from 'color-convert/conversions.js';

Expand All @@ -16,6 +16,6 @@ export class LoggerService {

@bindThis
public getLogger(domain: string, color?: KEYWORD | undefined, store?: boolean) {
return new Logger(domain);
return rootLogger.createSubLogger(domain, color, store);
}
}
10 changes: 5 additions & 5 deletions packages/backend/src/core/NoteCreateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,15 @@ export class NoteCreateService implements OnApplicationShutdown {
const policies = await this.roleService.getUserPolicies(user.id);

if (!policies.canCreateContent) {
this.logger.error('Request rejected because user has no permission to create content', { user: user.id, note: data });
this.logger.error('Request rejected because user has no permission to create content', { userId: user.id, note: data });
throw new IdentifiableError('5b1c2b67-50a6-4a8a-a59c-0ede40890de3', 'User has no permission to create content.');
}

if (data.visibility === 'public' && data.channel == null) {
const sensitiveWords = meta.sensitiveWords;
if (this.utilityService.isKeyWordIncluded(data.cw ?? this.utilityService.concatNoteContentsForKeyWordCheck({ text: data.text, pollChoices: data.poll?.choices }), sensitiveWords)) {
data.visibility = 'home';
this.logger.warn('Visibility changed to home because sensitive words are included', { user: user.id, note: data });
this.logger.warn('Visibility changed to home because sensitive words are included', { userId: user.id, note: data });
} else if (!policies.canPublicNote) {
data.visibility = 'home';
}
Expand All @@ -281,7 +281,7 @@ export class NoteCreateService implements OnApplicationShutdown {
);

if (hasProhibitedWords) {
this.logger.error('Request rejected because prohibited words are included', { user: user.id, note: data });
this.logger.error('Request rejected because prohibited words are included', { userId: user.id, note: data });
throw new IdentifiableError('689ee33f-f97c-479a-ac49-1b9f8140af99', 'Notes including prohibited words are not allowed.');
}

Expand Down Expand Up @@ -384,7 +384,7 @@ export class NoteCreateService implements OnApplicationShutdown {
if (process.env.MISSKEY_BLOCK_MENTIONS_FROM_UNFAMILIAR_REMOTE_USERS === 'true' && user.host !== null && willCauseNotification) {
const userEntity = await this.usersRepository.findOneBy({ id: user.id });
if ((userEntity?.followersCount ?? 0) === 0) {
this.logger.error('Request rejected because user has no local followers', { user: user.id, note: data });
this.logger.error('Request rejected because user has no local followers', { userId: user.id, note: data });
throw new IdentifiableError('e11b3a16-f543-4885-8eb1-66cad131dbfd', 'Notes including mentions, replies, or renotes from remote users are not allowed until user has at least one local follower.');
}
}
Expand All @@ -396,7 +396,7 @@ export class NoteCreateService implements OnApplicationShutdown {
|| (data.visibility === 'specified' && data.visibleUsers?.some(u => u.id !== user.id))
|| (this.isQuote(data) && data.renote.userId !== user.id)
) {
this.logger.error('Request rejected because user has no permission to initiate conversation', { user: user.id, note: data });
this.logger.error('Request rejected because user has no permission to initiate conversation', { userId: user.id, note: data });
throw new IdentifiableError('332dd91b-6a00-430a-ac39-620cf60ad34b', 'Notes including mentions, replies, or renotes are not allowed.');
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/core/UserBlockingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class UserBlockingService implements OnModuleInit {
private apRendererService: ApRendererService,
private loggerService: LoggerService,
) {
this.logger = this.loggerService.getLogger('user-block');
this.logger = this.loggerService.getLogger('user:block');
}

onModuleInit() {
Expand Down
Loading
Loading