mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-29 16:19:43 +08:00
chore(electron): self-hosted mixpanel flag (#11561)
fix AF-2341 
This commit is contained in:
@@ -577,8 +577,8 @@ export type LiveDataOperation = 'set' | 'get' | 'watch' | 'unwatch';
|
|||||||
export type Unwrap<T> =
|
export type Unwrap<T> =
|
||||||
T extends LiveData<infer Z>
|
T extends LiveData<infer Z>
|
||||||
? Unwrap<Z>
|
? Unwrap<Z>
|
||||||
: T extends LiveData<infer A>[]
|
: T extends readonly [...infer Elements]
|
||||||
? Unwrap<A>[]
|
? { [K in keyof Elements]: Unwrap<Elements[K]> }
|
||||||
: T;
|
: T;
|
||||||
|
|
||||||
export type Flat<T> = T extends LiveData<infer P> ? LiveData<Unwrap<P>> : T;
|
export type Flat<T> = T extends LiveData<infer P> ? LiveData<Unwrap<P>> : T;
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { shallowEqual } from '@affine/component';
|
||||||
|
import { ServerDeploymentType } from '@affine/graphql';
|
||||||
import { mixpanel } from '@affine/track';
|
import { mixpanel } from '@affine/track';
|
||||||
import { LiveData, OnEvent, Service } from '@toeverything/infra';
|
import { LiveData, OnEvent, Service } from '@toeverything/infra';
|
||||||
|
|
||||||
@@ -16,8 +18,21 @@ export class TelemetryService extends Service {
|
|||||||
: new LiveData<Server | undefined>(undefined)
|
: new LiveData<Server | undefined>(undefined)
|
||||||
)
|
)
|
||||||
.flat()
|
.flat()
|
||||||
.selector(server => server?.account$)
|
.selector(
|
||||||
.flat();
|
server =>
|
||||||
|
[
|
||||||
|
server?.account$,
|
||||||
|
server?.config$.selector(
|
||||||
|
c => c.type === ServerDeploymentType.Selfhosted
|
||||||
|
),
|
||||||
|
] as const
|
||||||
|
)
|
||||||
|
.flat()
|
||||||
|
.map(([account, selfHosted]) => ({
|
||||||
|
account,
|
||||||
|
selfHosted,
|
||||||
|
}))
|
||||||
|
.distinctUntilChanged(shallowEqual);
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly globalContextService: GlobalContextService,
|
private readonly globalContextService: GlobalContextService,
|
||||||
@@ -28,20 +43,30 @@ export class TelemetryService extends Service {
|
|||||||
// TODO: support multiple servers
|
// TODO: support multiple servers
|
||||||
|
|
||||||
let prevAccount: AuthAccountInfo | null = null;
|
let prevAccount: AuthAccountInfo | null = null;
|
||||||
const unsubscribe = this.currentAccount$.subscribe(account => {
|
let prevSelfHosted: boolean | undefined = undefined;
|
||||||
if (prevAccount) {
|
const unsubscribe = this.currentAccount$.subscribe(
|
||||||
mixpanel.reset();
|
({ account, selfHosted }) => {
|
||||||
|
if (prevAccount) {
|
||||||
|
mixpanel.reset();
|
||||||
|
}
|
||||||
|
// the isSelfHosted property from environment is not reliable
|
||||||
|
if (selfHosted !== prevSelfHosted) {
|
||||||
|
mixpanel.register({
|
||||||
|
isSelfHosted: selfHosted,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
prevSelfHosted = selfHosted;
|
||||||
|
prevAccount = account ?? null;
|
||||||
|
if (account) {
|
||||||
|
mixpanel.identify(account.id);
|
||||||
|
mixpanel.people.set({
|
||||||
|
$email: account.email,
|
||||||
|
$name: account.label,
|
||||||
|
$avatar: account.avatar,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
prevAccount = account ?? null;
|
);
|
||||||
if (account) {
|
|
||||||
mixpanel.identify(account.id);
|
|
||||||
mixpanel.people.set({
|
|
||||||
$email: account.email,
|
|
||||||
$name: account.label,
|
|
||||||
$avatar: account.avatar,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.disposableFns.push(() => {
|
this.disposableFns.push(() => {
|
||||||
unsubscribe.unsubscribe();
|
unsubscribe.unsubscribe();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { DebugLogger } from '@affine/debug';
|
import { DebugLogger } from '@affine/debug';
|
||||||
import type { OverridedMixpanel } from 'mixpanel-browser';
|
import type { Dict, OverridedMixpanel } from 'mixpanel-browser';
|
||||||
import mixpanelBrowser from 'mixpanel-browser';
|
import mixpanelBrowser from 'mixpanel-browser';
|
||||||
|
|
||||||
const logger = new DebugLogger('mixpanel');
|
const logger = new DebugLogger('mixpanel');
|
||||||
@@ -30,14 +30,19 @@ function createMixpanel() {
|
|||||||
|
|
||||||
const wrapped = {
|
const wrapped = {
|
||||||
init() {
|
init() {
|
||||||
mixpanel.register({
|
const defaultProps = {
|
||||||
appVersion: BUILD_CONFIG.appVersion,
|
appVersion: BUILD_CONFIG.appVersion,
|
||||||
environment: BUILD_CONFIG.appBuildType,
|
environment: BUILD_CONFIG.appBuildType,
|
||||||
editorVersion: BUILD_CONFIG.editorVersion,
|
editorVersion: BUILD_CONFIG.editorVersion,
|
||||||
isDesktop: BUILD_CONFIG.isElectron,
|
isDesktop: BUILD_CONFIG.isElectron,
|
||||||
isSelfHosted: environment.isSelfHosted,
|
|
||||||
distribution: BUILD_CONFIG.distribution,
|
distribution: BUILD_CONFIG.distribution,
|
||||||
});
|
};
|
||||||
|
this.register(defaultProps);
|
||||||
|
},
|
||||||
|
// provide a way to override the default properties
|
||||||
|
register(props: Dict) {
|
||||||
|
logger.debug('register with', props);
|
||||||
|
mixpanel.register(props);
|
||||||
},
|
},
|
||||||
reset() {
|
reset() {
|
||||||
mixpanel.reset();
|
mixpanel.reset();
|
||||||
|
|||||||
Reference in New Issue
Block a user