-
Notifications
You must be signed in to change notification settings - Fork 137
Posthog widget embedding #767
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
Conversation
Signed-off-by: Timo K <timok@element.io>
Signed-off-by: Timo K <timok@element.io>
Signed-off-by: Timo K <timok@element.io>
robintown
left a comment
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.
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"; |
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.
| import { MatrixClient } from "matrix-js-sdk"; | |
| import { MatrixClient } from "matrix-js-sdk/src/client"; |
Importing from matrix-js-sdk directly can break things IIRC
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.
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
This make it impossible to find users from the element web posthog instance in the element call instance
dbkr
left a comment
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.
otherwise lgtm
| this.setAnonymity(anonymity); | ||
| if (anonymity === Anonymity.Pseudonymous) { | ||
| this.setRegistrationType( | ||
| window.matrixclient.isGuest() || window.isPasswordlessUser |
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.
You probably can't get to the context but you should be able to use MatrixClientPeg.get()
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.
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?
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.
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.
src/PosthogAnalytics.ts
Outdated
| if (analyticsID) { | ||
| setSetting("opt-in-analytics", true); | ||
| } | ||
| setSetting("opt-in-analytics", !!analyticsID); |
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.
I think Boolean(analyticsID) is favoured (wonder if there's a lint rule for this).
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.
Okay good to know. A lint rule would be great. !! is still used in a couple of occasions (I checked before using it).
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:
