11'use client' ;
22
3+ import { useAnalytics } from '@prezly/analytics-nextjs' ;
4+ import type { NewsroomGallery , Story } from '@prezly/sdk' ;
5+
36import classNames from 'classnames' ;
47import {
58 FacebookShareButton ,
@@ -30,16 +33,34 @@ interface Props {
3033 socialNetworks : ThemeSettings [ 'sharing_actions' ] ;
3134 thumbnailUrl ?: string ;
3235 withLabels ?: boolean ;
36+ trackingContext : 'Story Page Header' | 'Story Page Footer' | 'Gallery' ;
37+ uuid : Story [ 'uuid' ] | NewsroomGallery [ 'uuid' ] ;
3338}
3439
35- export function SocialShare ( { className, socialNetworks, thumbnailUrl, url, withLabels } : Props ) {
40+ export function SocialShare ( {
41+ className,
42+ socialNetworks,
43+ thumbnailUrl,
44+ trackingContext,
45+ url,
46+ uuid,
47+ withLabels,
48+ } : Props ) {
49+ const { track } = useAnalytics ( ) ;
50+
3651 return (
3752 < div className = { classNames ( className , styles . social , { [ styles . withLabels ] : withLabels } ) } >
3853 { socialNetworks . includes ( SocialNetwork . LINKEDIN ) && (
3954 < LinkedinShareButton
4055 data-title = "Share on Linkedin"
4156 className = { styles . socialButton }
4257 url = { url }
58+ onClick = { ( ) =>
59+ track (
60+ `Newsroom - ${ trackingContext } - Share to ${ SocialNetwork . LINKEDIN } ` ,
61+ { id : uuid } ,
62+ )
63+ }
4364 >
4465 < IconLinkedin className = { styles . socialIcon } />
4566 </ LinkedinShareButton >
@@ -50,6 +71,12 @@ export function SocialShare({ className, socialNetworks, thumbnailUrl, url, with
5071 data-title = "Share on Facebook"
5172 className = { styles . socialButton }
5273 url = { url }
74+ onClick = { ( ) =>
75+ track (
76+ `Newsroom - ${ trackingContext } - Share to ${ SocialNetwork . FACEBOOK } ` ,
77+ { id : uuid } ,
78+ )
79+ }
5380 >
5481 < IconFacebook className = { styles . socialIcon } />
5582 </ FacebookShareButton >
@@ -60,6 +87,11 @@ export function SocialShare({ className, socialNetworks, thumbnailUrl, url, with
6087 data-title = "Share on X"
6188 className = { styles . socialButton }
6289 url = { url }
90+ onClick = { ( ) =>
91+ track ( `Newsroom - ${ trackingContext } - Share to ${ SocialNetwork . TWITTER } ` , {
92+ id : uuid ,
93+ } )
94+ }
6395 >
6496 < IconTwitter className = { styles . socialIcon } />
6597 </ TwitterShareButton >
@@ -71,6 +103,12 @@ export function SocialShare({ className, socialNetworks, thumbnailUrl, url, with
71103 className = { styles . socialButton }
72104 media = { thumbnailUrl }
73105 url = { url }
106+ onClick = { ( ) =>
107+ track (
108+ `Newsroom - ${ trackingContext } - Share to ${ SocialNetwork . PINTEREST } ` ,
109+ { id : uuid } ,
110+ )
111+ }
74112 >
75113 < IconPinterest className = { styles . socialIcon } />
76114 </ PinterestShareButton >
@@ -81,6 +119,11 @@ export function SocialShare({ className, socialNetworks, thumbnailUrl, url, with
81119 data-title = "Share on Reddit"
82120 className = { styles . socialButton }
83121 url = { url }
122+ onClick = { ( ) =>
123+ track ( `Newsroom - ${ trackingContext } - Share to ${ SocialNetwork . REDDIT } ` , {
124+ id : uuid ,
125+ } )
126+ }
84127 >
85128 < IconReddit className = { styles . socialIcon } />
86129 </ RedditShareButton >
@@ -97,6 +140,12 @@ export function SocialShare({ className, socialNetworks, thumbnailUrl, url, with
97140 data-title = "Share on WhatsApp"
98141 className = { styles . socialButton }
99142 url = { url }
143+ onClick = { ( ) =>
144+ track (
145+ `Newsroom - ${ trackingContext } - Share to ${ SocialNetwork . WHATSAPP } ` ,
146+ { id : uuid } ,
147+ )
148+ }
100149 >
101150 < IconWhatsApp className = { styles . socialIcon } />
102151 </ WhatsappShareButton >
@@ -107,6 +156,12 @@ export function SocialShare({ className, socialNetworks, thumbnailUrl, url, with
107156 data-title = "Share on Telegram"
108157 className = { styles . socialButton }
109158 url = { url }
159+ onClick = { ( ) =>
160+ track (
161+ `Newsroom - ${ trackingContext } - Share to ${ SocialNetwork . TELEGRAM } ` ,
162+ { id : uuid } ,
163+ )
164+ }
110165 >
111166 < IconTelegram className = { styles . socialIcon } />
112167 </ TelegramShareButton >
0 commit comments