-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
wip: ga #15451
Draft
syuilo
wants to merge
12
commits into
develop
Choose a base branch
from
ga
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
wip: ga #15451
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
79534a4
wip backend
kakkokari-gtyih e57b455
wip frontend
kakkokari-gtyih f1983c2
build misskey-js
kakkokari-gtyih f4d95a6
implement control panel
kakkokari-gtyih b76d61d
fix
kakkokari-gtyih 7bfca6d
introduce analytics wrapper
kakkokari-gtyih 46509c1
spdx
kakkokari-gtyih 1dbc841
Merge pull request #15450 from kakkokari-gtyih/feat-15426
syuilo 951f66c
Update analytics.ts
kakkokari-gtyih e3aad56
Merge branch 'develop' into ga
syuilo 98c4ed7
Update common.ts
syuilo ceb12ef
wip
syuilo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
packages/backend/migration/1739006797620-GoogleAnalytics.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* SPDX-FileCopyrightText: syuilo and misskey-project | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
export class GoogleAnalytics1739006797620 { | ||
name = 'GoogleAnalytics1739006797620' | ||
|
||
async up(queryRunner) { | ||
await queryRunner.query(`ALTER TABLE "meta" ADD "googleAnalyticsMeasurementId" character varying(64)`); | ||
} | ||
|
||
async down(queryRunner) { | ||
await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "googleAnalyticsMeasurementId"`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* SPDX-FileCopyrightText: syuilo and misskey-project | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
import * as Misskey from 'misskey-js'; | ||
import type { AnalyticsInstance, AnalyticsPlugin } from 'analytics'; | ||
|
||
/** | ||
* analytics moduleを読み込まなくても動作するようにするためのラッパー | ||
*/ | ||
class AnalyticsProxy implements AnalyticsInstance { | ||
private analytics?: AnalyticsInstance; | ||
|
||
constructor(analytics?: AnalyticsInstance) { | ||
if (analytics) { | ||
this.analytics = analytics; | ||
} | ||
} | ||
|
||
public setAnalytics(analytics: AnalyticsInstance) { | ||
if (this.analytics) { | ||
throw new Error('Analytics instance already exists.'); | ||
} | ||
this.analytics = analytics; | ||
} | ||
|
||
public identify(...args: Parameters<AnalyticsInstance['identify']>) { | ||
return this.analytics?.identify(...args) ?? Promise.resolve(); | ||
} | ||
|
||
public track(...args: Parameters<AnalyticsInstance['track']>) { | ||
return this.analytics?.track(...args) ?? Promise.resolve(); | ||
} | ||
|
||
public page(...args: Parameters<AnalyticsInstance['page']>) { | ||
return this.analytics?.page(...args) ?? Promise.resolve(); | ||
} | ||
|
||
public user(...args: Parameters<AnalyticsInstance['user']>) { | ||
return this.analytics?.user(...args) ?? Promise.resolve(); | ||
} | ||
|
||
public reset(...args: Parameters<AnalyticsInstance['reset']>) { | ||
return this.analytics?.reset(...args) ?? Promise.resolve(); | ||
} | ||
|
||
public ready(...args: Parameters<AnalyticsInstance['ready']>) { | ||
return this.analytics?.ready(...args) ?? function () { void 0; }; | ||
} | ||
|
||
public on(...args: Parameters<AnalyticsInstance['on']>) { | ||
return this.analytics?.on(...args) ?? function () { void 0; }; | ||
} | ||
|
||
public once(...args: Parameters<AnalyticsInstance['once']>) { | ||
return this.analytics?.once(...args) ?? function () { void 0; }; | ||
} | ||
|
||
public getState(...args: Parameters<AnalyticsInstance['getState']>) { | ||
return this.analytics?.getState(...args) ?? Promise.resolve(); | ||
} | ||
|
||
public get storage() { | ||
return this.analytics?.storage ?? { | ||
getItem: () => null, | ||
setItem: () => void 0, | ||
removeItem: () => void 0, | ||
}; | ||
} | ||
|
||
public get plugins() { | ||
return this.analytics?.plugins ?? { | ||
enable: (p, c) => Promise.resolve(c ? c() : void 0), | ||
disable: (p, c) => Promise.resolve(c ? c() : void 0), | ||
}; | ||
} | ||
} | ||
|
||
export const analytics = new AnalyticsProxy(); | ||
|
||
export async function initAnalytics(instance: Misskey.entities.MetaDetailed) { | ||
// アナリティクスプロバイダに関する設定がひとつもない場合は、アナリティクスモジュールを読み込まない | ||
if (!instance.googleAnalyticsMeasurementId) { | ||
return; | ||
} | ||
|
||
const { default: Analytics } = await import('analytics'); | ||
const plugins: AnalyticsPlugin[] = []; | ||
|
||
// Google Analytics | ||
if (instance.googleAnalyticsMeasurementId) { | ||
const { default: googleAnalytics } = await import('@analytics/google-analytics'); | ||
|
||
plugins.push(googleAnalytics({ | ||
measurementIds: [instance.googleAnalyticsMeasurementId], | ||
debug: _DEV_, | ||
})); | ||
} | ||
|
||
analytics.setAnalytics(Analytics({ | ||
app: 'misskey', | ||
version: _VERSION_, | ||
debug: _DEV_, | ||
plugins, | ||
})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replaceに反応しないのでchangeイベントで取ったほうがいいかも