Skip to content

Conversation

@toger5
Copy link
Contributor

@toger5 toger5 commented Nov 28, 2022

Fixes: #764
This loads the "analyticsID" form element web in case the user already has given consent to send analytics to posthog.
Relies on: matrix-org/matrix-react-sdk#9637

Allows to check in what context the app gets used:
image

Signed-off-by: Timo K <timok@element.io>
Signed-off-by: Timo K <timok@element.io>
Signed-off-by: Timo K <timok@element.io>
Copy link
Member

@robintown robintown left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good overall


import posthog, { CaptureOptions, PostHog, Properties } from "posthog-js";
import { logger } from "matrix-js-sdk/src/logger";
import { MatrixClient } from "matrix-js-sdk";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { MatrixClient } from "matrix-js-sdk";
import { MatrixClient } from "matrix-js-sdk/src/client";

Importing from matrix-js-sdk directly can break things IIRC

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as you're consistent with the import it is fine, matrix-js-sdk maps to /src/ or /lib/ depending on if release or develop repsectively

Copy link
Member

@dbkr dbkr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise lgtm

this.setAnonymity(anonymity);
if (anonymity === Anonymity.Pseudonymous) {
this.setRegistrationType(
window.matrixclient.isGuest() || window.isPasswordlessUser
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably can't get to the context but you should be able to use MatrixClientPeg.get()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can i get acces to isPasswordlessUser from the client peg? It seems like this is a element call specific property not part of the client interface?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, no you can't since the js-sdk doesn't know about it. You would indeed need the context, or which is impossible using a shared instance method - we have an impedance mismatch between singletons and contexts. We should probably decide on one or the other rather than mixing them, but this is probably an okay workaround for now.

This fixes an issue that the widget version did not identify the user before sneding
the first track event.
Because start call is called right after app startup.
@toger5 toger5 requested a review from dbkr December 19, 2022 11:05
if (analyticsID) {
setSetting("opt-in-analytics", true);
}
setSetting("opt-in-analytics", !!analyticsID);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Boolean(analyticsID) is favoured (wonder if there's a lint rule for this).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay good to know. A lint rule would be great. !! is still used in a couple of occasions (I checked before using it).

@toger5 toger5 merged commit e3aa810 into element-hq:main Dec 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Telemetry for the widget version of element call.

4 participants