-
-
Notifications
You must be signed in to change notification settings - Fork 828
Report crypto sdk in posthog #11834
Report crypto sdk in posthog #11834
Changes from 1 commit
ae8f787
3ccc67e
990dad7
219c6c4
2684f97
43a5225
ba14536
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,6 +136,11 @@ export class PosthogAnalytics { | |
private authenticationType: Signup["authenticationType"] = "Other"; | ||
private watchSettingRef?: string; | ||
|
||
// Temporary flag until we can switch to the Rust SDK without restarting the app. | ||
// Currently, you have to set up the flag then logout and login again to switch. | ||
// On login the matrixClient is passed to the analytics object, and we can check the crypto backend version. | ||
private hasLoggedInWithRustCrypto = false; | ||
|
||
public static get instance(): PosthogAnalytics { | ||
if (!this._instance) { | ||
this._instance = new PosthogAnalytics(posthog); | ||
|
@@ -169,7 +174,9 @@ export class PosthogAnalytics { | |
dis.register(this.onAction); | ||
SettingsStore.monitorSetting("layout", null); | ||
SettingsStore.monitorSetting("useCompactLayout", null); | ||
SettingsStore.monitorSetting("feature_rust_crypto", null); | ||
this.onLayoutUpdated(); | ||
this.updateCryptoSuperProperty(); | ||
} | ||
|
||
private onLayoutUpdated = (): void => { | ||
|
@@ -198,6 +205,9 @@ export class PosthogAnalytics { | |
if (["layout", "useCompactLayout"].includes(settingsPayload.settingName)) { | ||
this.onLayoutUpdated(); | ||
} | ||
if (["feature_rust_crypto"].includes(settingsPayload.settingName)) { | ||
this.updateCryptoSuperProperty(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code will never fire, no? Given the feature is not runtime mutable and must be set via config. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I simplified all, it will probably not be fully live ever. Just using the matrixClient passed on load/login/account data and read the crypto version |
||
}; | ||
|
||
// we persist the last `$screen_name` and send it for all events until it is replaced | ||
|
@@ -251,6 +261,14 @@ export class PosthogAnalytics { | |
}; | ||
} | ||
|
||
private getCryptoSDKPropertyValue(): "Rust" | "Legacy" { | ||
// Until we have migration code to switch crypto sdk, we need to track which sdk is being used. | ||
if (SettingsStore.getValue("feature_rust_crypto") && this.hasLoggedInWithRustCrypto) { | ||
return "Rust"; | ||
} | ||
return "Legacy"; | ||
} | ||
|
||
// eslint-disable-nextline no-unused-vars | ||
private capture(eventName: string, properties: Properties, options?: CaptureOptions): void { | ||
if (!this.enabled) { | ||
|
@@ -278,6 +296,8 @@ export class PosthogAnalytics { | |
this.registerSuperProperties(this.platformSuperProperties); | ||
} | ||
this.anonymity = anonymity; | ||
// update anyhow, no-op if not enabled or Disabled. | ||
this.updateCryptoSuperProperty(); | ||
} | ||
|
||
private static getRandomAnalyticsId(): string { | ||
|
@@ -367,7 +387,25 @@ export class PosthogAnalytics { | |
this.registerSuperProperties(this.platformSuperProperties); | ||
} | ||
|
||
private updateCryptoSuperProperty(): void { | ||
if (!this.enabled || this.anonymity === Anonymity.Disabled) return; | ||
// Update super property for cryptoSDK in posthog. | ||
// This property will be subsequently passed in every event. | ||
const value = this.getCryptoSDKPropertyValue(); | ||
this.registerSuperProperties({ cryptoSDK: value }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't these clobber between sessions of the same account? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No I tested (same users with a rust and a legacy "device") As per doc
It's technically stored in a cookie:
There is a thing maybe annoying: if you switch to rust stack and we do PageView per unique user, the same user will report in both Legacy and Rust for some time. However for web insights we can use per Unique Session that could be better for us There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Then we can't use it without updating the cookie policy. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We are already using superProperties for |
||
} | ||
|
||
public async updateAnonymityFromSettings(client: MatrixClient, pseudonymousOptIn: boolean): Promise<void> { | ||
// Temporary until we have migration code to switch crypto sdk. | ||
if (client.getCrypto()) { | ||
const cryptoVersion = client.getCrypto()!.getVersion(); | ||
// version for rust is something like "Rust SDK 0.6.0 (9c6b550), Vodozemac 0.5.0" | ||
// for legacy it will be 'Olm x.x.x" | ||
if (cryptoVersion.indexOf("Rust SDK") != -1) { | ||
BillCarsonFr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.hasLoggedInWithRustCrypto = true; | ||
} | ||
} | ||
|
||
// Update this.anonymity based on the user's analytics opt-in settings | ||
const anonymity = pseudonymousOptIn ? Anonymity.Pseudonymous : Anonymity.Disabled; | ||
this.setAnonymity(anonymity); | ||
|
@@ -379,7 +417,8 @@ export class PosthogAnalytics { | |
} | ||
|
||
if (anonymity !== Anonymity.Disabled) { | ||
await PosthogAnalytics.instance.updatePlatformSuperProperties(); | ||
await this.updatePlatformSuperProperties(); | ||
this.updateCryptoSuperProperty(); | ||
} | ||
} | ||
|
||
|
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.
Note for reviewer: Ideally we should just listen to the
feature_rust_crypto
settings, and this is what we will do when we will have migration in place. But until then you need to enable that feature then logout and login, that's why there is this flag.It will be set when the current MatrixClient is passed to the analytics object (on login / page load / ...), the trick is to look at the crypto version.
I am not sure if it's right to listen to the setting now as it's not yet working. Maybe it should for now just check the crypto version from matrix client for now, and then later when we have migration we use the setting?
Let me know and I will update
Update: Simplified, will now just check the actual crypto version