Skip to content

Commit a727aca

Browse files
committed
fix: added browser detection logic and ids for GTM tracking
1 parent 0b9608b commit a727aca

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

packages/frontend/pages/index.jsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import VlogVideo from "../components/vlogVideo";
66
import usePageVisibility from "../hooks/pageVisibility";
77
import { classNames } from "../utils/classNames";
88
import { text } from "../utils/constants";
9-
import { capitalize } from "../utils/helpers";
9+
import { capitalize, getBrowserName } from "../utils/helpers";
1010
export async function getStaticProps() {
1111
return {
1212
props: {},
@@ -45,7 +45,8 @@ export default function Vlog() {
4545
}
4646
};
4747
useEffect(() => {
48-
if (!document.pictureInPictureEnabled) {
48+
const browserName = getBrowserName(navigator.userAgent);
49+
if (!document.pictureInPictureEnabled || (browserName !== "chrome" && browserName !== "firefox")) {
4950
setShowError(true);
5051
}
5152
}, []);
@@ -98,7 +99,10 @@ export default function Vlog() {
9899
<section className="container flex flex-wrap items-center content-center justify-center w-full h-full px-4 mx-auto">
99100
{showError && (
100101
<Modal title="Oops..." onClose={onModalClose}>
101-
<p>Opps.... Your browser does not support required features to record video.</p>
102+
<p>
103+
Opps.... Your browser does not support required features to record video. <br /> We recommend using latest
104+
version of chrome dekstop.
105+
</p>
102106
</Modal>
103107
)}
104108
<h1 className="w-11/12 mb-10 text-3xl font-bold text-center lg:w-8/12">
@@ -132,6 +136,7 @@ export default function Vlog() {
132136
"md:w-1/4 lg:w-1/6": !isInitialized,
133137
hidden: isInitialized,
134138
})}`}
139+
id="initialize"
135140
onClick={() => setIsInitialized(!isInitialized)}
136141
>
137142
Initialize
@@ -162,6 +167,7 @@ export default function Vlog() {
162167
"bg-red-500 hover:bg-red-700": isRecording,
163168
hidden: !isInitialized,
164169
})}`}
170+
id="startRecording"
165171
onClick={handleRecording}
166172
>
167173
{`${pageTitle || "Start recording"}...`}

packages/frontend/utils/constants.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,9 @@ export const iceConfig = {
7070
},
7171
],
7272
};
73+
74+
export const browserRegexes = {
75+
chrome: /(chrome|omniweb|arora|[tizenoka]{5} ?browser)\/v?([\w\.]+)/i,
76+
edge: /edg(?:e|ios|a)?\/([\w\.]+)/i,
77+
firefox: /(mozilla)\/([\w\.]+) .+rv\:.+gecko\/\d+/i,
78+
};

packages/frontend/utils/helpers.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { browserRegexes } from "./constants";
2+
13
export function capitalize(s) {
24
if (typeof s !== "string") return "";
35
return s.charAt(0).toUpperCase() + s.slice(1);
@@ -6,8 +8,8 @@ export function capitalize(s) {
68
export async function loadBodyPix() {
79
const options = {
810
multiplier: 0.75,
9-
stride: 16,
10-
quantBytes: 2,
11+
stride: 8,
12+
quantBytes: 4,
1113
};
1214
const net = await bodyPix.load(options);
1315
return net;
@@ -35,3 +37,14 @@ export function readAsObjectURL(file) {
3537
reader.readAsArrayBuffer(file);
3638
});
3739
}
40+
41+
export function getBrowserName(uaString) {
42+
const browserMatch = Object.entries(browserRegexes).find(([, regex]) => regex.test(uaString));
43+
44+
if (!browserMatch) {
45+
return null;
46+
}
47+
48+
const [browserName] = browserMatch;
49+
return browserName;
50+
}

0 commit comments

Comments
 (0)