Skip to content

Commit e633189

Browse files
committed
minor updates
1 parent 9c8c549 commit e633189

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

src/components/SocialShare/SocialShare.tsx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { AiFillTwitterCircle, AiFillFacebook } from "react-icons/ai";
33
import { WEBSITE_URL } from "../../../BLOG_CONSTANTS/_BLOG_SETUP";
44
import { combineClasses } from "../../utils/utils";
55
import { useEffect, useState } from "react";
6+
import { GAEvent } from "../../../google";
67

78
const SocialShare = () => {
89
const url =
@@ -12,9 +13,21 @@ const SocialShare = () => {
1213
const facebookShare = `https://www.facebook.com/sharer/sharer.php?u=${url}`;
1314
const linkedinShare = `https://www.linkedin.com/shareArticle?mini=true&url=${url}&title=Check out this article!!&source=LinkedIn`;
1415

16+
const trackShareEvent = (social: string) => {
17+
GAEvent({
18+
action: "share_clicked",
19+
event_category: "click",
20+
label: social,
21+
value: null,
22+
});
23+
};
24+
1525
const copyLink = () => {
16-
navigator.clipboard.writeText(url);
17-
setShowCopiedAlert(true);
26+
if (typeof window !== "undefined" && navigator) {
27+
navigator.clipboard.writeText(url);
28+
setShowCopiedAlert(true);
29+
}
30+
trackShareEvent("copy_clipboard_clicked");
1831
};
1932

2033
const [showCopiedAlert, setShowCopiedAlert] = useState(false);
@@ -36,6 +49,7 @@ const SocialShare = () => {
3649
href={facebookShare}
3750
onClick={() => {
3851
window.open(facebookShare, "popup", "width=300,height=500");
52+
trackShareEvent("facebook_share_clicked");
3953
return false;
4054
}}
4155
target="popup"
@@ -48,6 +62,7 @@ const SocialShare = () => {
4862
href={twitterShare}
4963
onClick={() => {
5064
window.open(twitterShare, "popup", "width=600,height=500");
65+
trackShareEvent("twitter_share_clicked");
5166
return false;
5267
}}
5368
target="popup"
@@ -60,6 +75,7 @@ const SocialShare = () => {
6075
href={linkedinShare}
6176
onClick={() => {
6277
window.open(linkedinShare, "popup", "width=500,height=500");
78+
trackShareEvent("linkedin_share_clicked");
6379
return false;
6480
}}
6581
target="popup"
@@ -78,7 +94,9 @@ const SocialShare = () => {
7894
<div
7995
className={combineClasses(
8096
"bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded fixed flex transition-all right-[10px]",
81-
showCopiedAlert ? 'md:bottom-10 sm:bottom-[0px] opacity-100' : '-bottom-20 opacity-0'
97+
showCopiedAlert
98+
? "md:bottom-10 sm:bottom-[0px] opacity-100"
99+
: "-bottom-20 opacity-0"
82100
)}
83101
role="alert"
84102
>

src/components/SocialShare/SocialShareModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const SocialShareModal = ({ closeModal, openShareModal = false }: any) => {
1818
></div>
1919
<div
2020
className={combineClasses(
21-
"bg-blue-100 border border-blue-400 text-blue-700 px-4 py-3 rounded lg:w-1/6 relative z-10 transition-all",
21+
"bg-blue-100 border border-blue-400 text-blue-700 px-4 py-3 rounded lg:w-1/6 mx-3 w-full relative z-10 transition-all",
2222
openShareModal ? "top-0" : "top-10"
2323
)}
2424
>

src/utils/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const changeTheme = (): void => {
4747
* @returns string
4848
*/
4949
export const getDeviceType = (): string => {
50-
const ua = navigator.userAgent;
50+
const ua = typeof window !== "undefined" ? navigator.userAgent : 'desktop';
5151
if (/(tablet|ipad|playbook|silk)|(android(?!.*mobi))/i.test(ua)) {
5252
return "tablet";
5353
}
@@ -255,7 +255,7 @@ export const webShare = () => {
255255
if (isDesktopDevice()) {
256256
return false;
257257
} else {
258-
if (navigator.share) {
258+
if (typeof window !== "undefined" && navigator) {
259259
navigator
260260
.share({
261261
text: pageTitle,

0 commit comments

Comments
 (0)