33import { useState , useEffect } from "react" ;
44import { Copy , Check , Link2 , Share2 , Download , FileText } from "lucide-react" ;
55import { SHARE_FORMATS , downloadBlob } from "./share-image" ;
6+ import { trackEvent , AnalyticsEvents } from "@/lib/analytics" ;
67import type { ShareActionsProps , ShareFormat } from "./types" ;
78
89// Brand icons (Lucide doesn't include these)
@@ -70,6 +71,7 @@ export function ShareActions({
7071 try {
7172 await navigator . clipboard . writeText ( shareText ) ;
7273 setCopied ( true ) ;
74+ trackEvent ( AnalyticsEvents . PROFILE_SHARE , { method : "copy_text" } ) ;
7375 setTimeout ( ( ) => setCopied ( false ) , 2000 ) ;
7476 } catch {
7577 setCopied ( false ) ;
@@ -81,6 +83,7 @@ export function ShareActions({
8183 try {
8284 await navigator . clipboard . writeText ( shareUrl ) ;
8385 setCopiedLink ( true ) ;
86+ trackEvent ( AnalyticsEvents . PROFILE_SHARE , { method : "copy_link" } ) ;
8487 setTimeout ( ( ) => setCopiedLink ( false ) , 2000 ) ;
8588 } catch {
8689 setCopiedLink ( false ) ;
@@ -96,6 +99,7 @@ export function ShareActions({
9699 const u = new URL ( "https://twitter.com/intent/tweet" ) ;
97100 u . searchParams . set ( "text" , shareCaption ) ;
98101 u . searchParams . set ( "url" , shareUrl ) ;
102+ trackEvent ( AnalyticsEvents . PROFILE_SHARE , { method : "twitter" } ) ;
99103 openSharePopup ( u . toString ( ) ) ;
100104 } ;
101105
@@ -104,13 +108,15 @@ export function ShareActions({
104108 const u = new URL ( "https://www.facebook.com/sharer/sharer.php" ) ;
105109 u . searchParams . set ( "u" , shareUrl ) ;
106110 if ( shareCaption ) u . searchParams . set ( "quote" , shareCaption ) ;
111+ trackEvent ( AnalyticsEvents . PROFILE_SHARE , { method : "facebook" } ) ;
107112 openSharePopup ( u . toString ( ) ) ;
108113 } ;
109114
110115 const handleShareLinkedIn = ( ) => {
111116 if ( ! shareUrl ) return ;
112117 const u = new URL ( "https://www.linkedin.com/sharing/share-offsite/" ) ;
113118 u . searchParams . set ( "url" , shareUrl ) ;
119+ trackEvent ( AnalyticsEvents . PROFILE_SHARE , { method : "linkedin" } ) ;
114120 openSharePopup ( u . toString ( ) ) ;
115121 } ;
116122
@@ -119,13 +125,15 @@ export function ShareActions({
119125 const u = new URL ( "https://www.reddit.com/submit" ) ;
120126 u . searchParams . set ( "url" , shareUrl ) ;
121127 if ( shareHeadline ) u . searchParams . set ( "title" , shareHeadline ) ;
128+ trackEvent ( AnalyticsEvents . PROFILE_SHARE , { method : "reddit" } ) ;
122129 openSharePopup ( u . toString ( ) ) ;
123130 } ;
124131
125132 const handleShareWhatsApp = ( ) => {
126133 if ( ! shareUrl ) return ;
127134 const u = new URL ( "https://wa.me/" ) ;
128135 u . searchParams . set ( "text" , `${ shareCaption } \n${ shareUrl } ` . trim ( ) ) ;
136+ trackEvent ( AnalyticsEvents . PROFILE_SHARE , { method : "whatsapp" } ) ;
129137 openSharePopup ( u . toString ( ) ) ;
130138 } ;
131139
@@ -158,12 +166,13 @@ export function ShareActions({
158166 files : [ file ] ,
159167 title : shareHeadline ,
160168 // Some platforms ignore text if files are present, but good to include
161- text : shareCaption ,
169+ text : shareCaption ,
162170 // Note: Including URL with files is often flaky on Android/iOS (sometimes creates a link card instead of image).
163171 // We prioritize the IMAGE here as per user request ("share that [the image]").
164172 // If you really need the URL, append it to text.
165- // url: shareUrl,
173+ // url: shareUrl,
166174 } ) ;
175+ trackEvent ( AnalyticsEvents . PROFILE_SHARE , { method : "native_share" } ) ;
167176 } else {
168177 // Fallback if file sharing not supported
169178 await navigator . share ( {
@@ -200,6 +209,7 @@ export function ShareActions({
200209 }
201210 const blob = await res . blob ( ) ;
202211 downloadBlob ( blob , `vcp-${ entityId } -${ shareFormat } .png` ) ;
212+ trackEvent ( AnalyticsEvents . PROFILE_DOWNLOAD_IMAGE , { format : shareFormat } ) ;
203213 console . log ( "PNG download complete" ) ;
204214 } catch ( e ) {
205215 console . error ( "PNG download failed:" , e ) ;
@@ -220,6 +230,7 @@ export function ShareActions({
220230 if ( ! res . ok ) throw new Error ( "story_failed" ) ;
221231 const blob = await res . blob ( ) ;
222232 downloadBlob ( blob , `vcp-${ entityId } -story.png` ) ;
233+ trackEvent ( AnalyticsEvents . PROFILE_DOWNLOAD_IMAGE , { format : "story" } ) ;
223234 } catch ( e ) {
224235 console . error ( "Story download failed:" , e ) ;
225236 setDownloadError ( e instanceof Error ? e . message : "story_download_failed" ) ;
0 commit comments