@@ -18,6 +18,7 @@ interface ResourceProjectBannerProps extends ResourceProjectProps {
1818}
1919
2020const ResourceProjectBanner : React . FC < ResourceProjectBannerProps > = ( {
21+ id,
2122 title,
2223 description,
2324 subtitle,
@@ -33,14 +34,13 @@ const ResourceProjectBanner: React.FC<ResourceProjectBannerProps> = ({
3334 endDate,
3435 badgeText,
3536 resourceType,
36- downloadCount : initialDownloadCount ,
3737 lastUpdated,
3838 fileSize,
3939 fileType,
4040 trackingContext = 'resource-project' ,
4141 className = ''
4242} ) => {
43- const [ downloadCount , setDownloadCount ] = useState < number | undefined > ( initialDownloadCount ) ;
43+ const [ downloadCount , setDownloadCount ] = useState < number | undefined > ( 0 ) ;
4444
4545 // Fetch download count from Google Analytics
4646 useEffect ( ( ) => {
@@ -51,6 +51,7 @@ const ResourceProjectBanner: React.FC<ResourceProjectBannerProps> = ({
5151
5252 if ( downloadButton ) {
5353 const params = new URLSearchParams ( {
54+ banner_analytics_id : id ,
5455 fileName : title ,
5556 ...( fileType && { fileType } ) ,
5657 ...( resourceType && { resourceType } ) ,
@@ -59,10 +60,8 @@ const ResourceProjectBanner: React.FC<ResourceProjectBannerProps> = ({
5960 const response = await fetch ( `/api/analytics/download-count?${ params . toString ( ) } ` ) ;
6061
6162 if ( response . ok ) {
62- // TODO: Uncomment it when we get value of downloadCount from GA4
63- // const data = await response.json();
64- // setDownloadCount(data.count);
65- setDownloadCount ( undefined ) ;
63+ const data = await response . json ( ) ;
64+ setDownloadCount ( data . count ) ;
6665 }
6766 }
6867 } catch ( error ) {
@@ -71,7 +70,7 @@ const ResourceProjectBanner: React.FC<ResourceProjectBannerProps> = ({
7170 } ;
7271
7372 fetchDownloadCount ( ) ;
74- } , [ title , fileType , resourceType , ctaButtons ] ) ;
73+ } , [ title , fileType , resourceType , ctaButtons , id ] ) ;
7574
7675 const backgroundClasses = generateBackgroundClasses ( background ) ;
7776 const backgroundStyles = generateBackgroundStyles ( background ) ;
@@ -166,6 +165,19 @@ const ResourceProjectBanner: React.FC<ResourceProjectBannerProps> = ({
166165 button_position : index + 1 ,
167166 tracking_context : button . trackingContext || trackingContext
168167 } ) ;
168+
169+ // Track downloads specifically: by default we set up file download to the first button
170+ if ( index === 0 ) {
171+ window . gtag ( 'event' , 'resource_file_download' , {
172+ banner_analytics_id : id ,
173+ resource_title : title ,
174+ resource_type : resourceType || 'unknown' ,
175+ file_type : fileType || 'unknown' ,
176+ cta_position : index + 1 ,
177+ button_label : button . label ,
178+ tracking_context : button . trackingContext || trackingContext
179+ } ) ;
180+ }
169181 }
170182
171183 // Track downloads specifically: by default we set up file download to the first button
@@ -277,8 +289,8 @@ const ResourceProjectBanner: React.FC<ResourceProjectBannerProps> = ({
277289
278290 { /* Resource Stats */ }
279291 { /* Update to lg:grid-cols-3 when we configure downloadCount */ }
280- < div className = "mb-8 grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-2 gap-4" >
281- { downloadCount !== undefined && downloadCount !== 0 && (
292+ < div className = "mb-8 grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4" >
293+ { downloadCount !== undefined && (
282294 < div className = "bg-white/10 backdrop-blur-sm rounded-lg p-4" >
283295 < div className = "flex items-center gap-2 mb-1" >
284296 < svg className = "w-5 h-5" fill = "currentColor" viewBox = "0 0 20 20" aria-hidden = "true" >
@@ -337,7 +349,7 @@ const ResourceProjectBanner: React.FC<ResourceProjectBannerProps> = ({
337349 }
338350 : { href : button . url } ;
339351
340- const isDownload = button . label . toLowerCase ( ) . includes ( 'download' ) ;
352+ const isDownload = button . label . toLowerCase ( ) . includes ( 'download' ) || index === 0 ;
341353
342354 return (
343355 < Component
0 commit comments