Skip to content

Commit

Permalink
fix: form submit issue on Brave browser (#1468)
Browse files Browse the repository at this point in the history
  • Loading branch information
barry800414 authored Dec 25, 2024
1 parent 6ef0c8d commit 24e1eb4
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/utils/GAUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,20 @@ export const getUserPseudoId = ga_measurement_id => {
return new Promise((resolve, reject) => {
try {
if (typeof window !== 'undefined' && typeof window.gtag !== 'undefined') {
window.gtag('get', ga_measurement_id, 'client_id', field =>
resolve(field),
);
/*
In Brave browser, window.gtag execution will be terminated without
throwing error, so this promise will not never being resolved or rejected.
To avoid this, we use setTimeout to resolve the promise after 500ms
*/
const t = setTimeout(() => {
console.error('Unable to resolve GA User Pseudo Id');
resolve(null);
}, 500);

window.gtag('get', ga_measurement_id, 'client_id', field => {
clearTimeout(t);
resolve(field);
});
} else {
resolve(null);
}
Expand Down

0 comments on commit 24e1eb4

Please sign in to comment.