mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-10-27 13:54:18 +00:00
feat: add PostHog analytics integration
- Add PostHog client configuration in ui/lib/posthog.ts - Integrate PostHog tracking in auth forms and provider workflows - Add PostHog dependencies (posthog-js and posthog-node) - Update Next.js config for PostHog integration - Add environment variables for PostHog configuration - Update changelog with PostHog integration entry
This commit is contained in:
1 parent
aa843b823c
commit
8a65efa441
9 files changed
+73
-5
No files matched your search
@@ -4,6 +4,7 @@ import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { Icon } from "@iconify/react";
|
||||
import { Button, Checkbox, Divider, Link, Tooltip } from "@nextui-org/react";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import posthog from "posthog-js";
|
||||
import { useEffect } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { z } from "zod";
|
||||
@@ -80,6 +81,8 @@ export const AuthForm = ({
|
||||
const isSamlMode = form.watch("isSamlMode");
|
||||
|
||||
const onSubmit = async (data: z.infer<typeof formSchema>) => {
|
||||
//getting an new posthog init
|
||||
posthog.reset(true);
|
||||
if (type === "sign-in") {
|
||||
if (data.isSamlMode) {
|
||||
const email = data.email.toLowerCase();
|
||||
@@ -107,6 +110,11 @@ export const AuthForm = ({
|
||||
password: data.password,
|
||||
});
|
||||
if (result?.message === "Success") {
|
||||
posthog.identify(data.email.toLowerCase());
|
||||
posthog.capture("user_login", {
|
||||
email: data.email.toLocaleLowerCase(),
|
||||
timestamp: Date.now(),
|
||||
});
|
||||
router.push("/");
|
||||
} else if (result?.errors && "credentials" in result.errors) {
|
||||
form.setError("email", {
|
||||
@@ -128,6 +136,20 @@ export const AuthForm = ({
|
||||
const newUser = await createNewUser(data);
|
||||
|
||||
if (!newUser.errors) {
|
||||
let firstName = "";
|
||||
let lastName = "";
|
||||
if (data.name) {
|
||||
const nameParts = data.name.trim().split(" ");
|
||||
firstName = nameParts[0] || "";
|
||||
lastName = nameParts.slice(1).join(" ") || "";
|
||||
}
|
||||
posthog.capture("user_registered", {
|
||||
email: data.email.toLocaleLowerCase(),
|
||||
firstname: firstName,
|
||||
lastname: lastName,
|
||||
company: data.company || "",
|
||||
timestamp: Date.now(),
|
||||
});
|
||||
toast({
|
||||
title: "Success!",
|
||||
description: "The user was registered successfully.",
|
||||
|
||||
@@ -5,6 +5,7 @@ import { Icon } from "@iconify/react";
|
||||
import { Checkbox } from "@nextui-org/react";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import posthog from "posthog-js";
|
||||
import { useState } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { z } from "zod";
|
||||
@@ -145,6 +146,13 @@ export const TestConnectionForm = ({
|
||||
});
|
||||
} else {
|
||||
setIsRedirecting(true);
|
||||
// Capture PostHog event for successful cloud connection
|
||||
posthog.capture("cloud_connection_success", {
|
||||
provider_type: providerType,
|
||||
provider_alias: providerData.data.attributes.alias,
|
||||
scan_type: form.watch("runOnce") ? "single" : "scheduled",
|
||||
timestamp: Date.now(),
|
||||
});
|
||||
router.push("/scans");
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
Reference in new issue
Block a user