File size: 1,602 Bytes
afd56bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
 * Posthog event tracking utility.
 * Wywoływany z kluczowych akcji użytkownika.
 */

/* eslint-disable @typescript-eslint/no-explicit-any */
declare const posthog: any;

function ph(): any | null {
  return typeof posthog !== 'undefined' ? posthog : null;
}

export const analytics = {
  /** Identyfikuj użytkownika po zalogowaniu */
  identify(userId: string, props?: Record<string, unknown>) {
    ph()?.identify(userId, props);
  },

  /** Użytkownik kliknął "Nowy Projekt" */
  projectCreated(projectId: string, name: string) {
    ph()?.capture('project_created', { project_id: projectId, project_name: name });
  },

  /** Sekcja wygenerowana przez AI */
  sectionGenerated(projectId: string, sectionKey: string, tierUsed: string) {
    ph()?.capture('section_generated', { project_id: projectId, section_key: sectionKey, tier: tierUsed });
  },

  /** Upload dokumentu PDF */
  documentUploaded(projectId: string, fileName: string) {
    ph()?.capture('document_uploaded', { project_id: projectId, file_name: fileName });
  },

  /** Klik "Kup Pro" — przed redirect do Stripe */
  checkoutStarted(plan: string) {
    ph()?.capture('checkout_started', { plan });
  },

  /** Powrót z Stripe — sukces */
  checkoutCompleted(plan: string) {
    ph()?.capture('checkout_completed', { plan });
  },

  /** Audyt wniosku */
  auditRun(projectId: string, score: number) {
    ph()?.capture('audit_run', { project_id: projectId, compliance_score: score });
  },

  /** Export DOCX */
  exportDocx(projectId: string) {
    ph()?.capture('export_docx', { project_id: projectId });
  },
};