Wire up bunch of interaction events into Posthog (#7707)

This commit is contained in:
Michael Telatynski 2022-02-09 14:42:08 +00:00 committed by GitHub
parent 5620b83d34
commit 999e1b7421
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 120 additions and 26 deletions

View file

@ -14,8 +14,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { PureComponent } from "react";
import { PureComponent, SyntheticEvent } from "react";
import { Screen as ScreenEvent } from "matrix-analytics-events/types/typescript/Screen";
import { Interaction as InteractionEvent } from "matrix-analytics-events/types/typescript/Interaction";
import PageType from "./PageTypes";
import Views from "./Views";
@ -88,6 +89,21 @@ export default class PosthogTrackers {
this.override = null;
this.trackPage();
}
public static trackInteraction(name: InteractionEvent["name"], ev?: SyntheticEvent): void {
let interactionType: InteractionEvent["interactionType"];
if (ev?.type === "click") {
interactionType = "Pointer";
} else if (ev?.type.startsWith("key")) {
interactionType = "Keyboard";
}
PosthogAnalytics.instance.trackEvent<InteractionEvent>({
eventName: "Interaction",
interactionType,
name,
});
}
}
export class PosthogScreenTracker extends PureComponent<{ screenName: ScreenName }> {