Skip to content

Commit 6f37e8d

Browse files
Bruno Oliveiraboliveira
authored andcommitted
fix: fix ssr
This fixes the broken ssr introduced by the empty catch block in GoogleConsentMode from blackout-react/analytics. Also fixes some jsdoc errors and changes the version calculation code in analytics from blackout-react/analytics.
1 parent 1544c56 commit 6f37e8d

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

packages/react/src/analytics/constants.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
// We use a require here to avoid typescript complaining of `package.json` is not
2-
// under rootDir that we would get if we used an import. Typescript apparently ignores
3-
// requires.
4-
// eslint-disable-next-line @typescript-eslint/no-var-requires
5-
const { name, version } = require('../../package.json');
1+
import { name, version } from '../../package.json';
62

73
export const PACKAGE_VERSION = version;
84
export const PACKAGE_NAME = name;

packages/react/src/analytics/integrations/shared/GoogleConsentMode/GoogleConsentMode.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class GoogleConsentMode {
6363
this.write(consentCommand, command, consent);
6464
});
6565
}
66-
} catch {
66+
} catch (_) {
6767
// Do nothing...
6868
}
6969
}
@@ -187,8 +187,7 @@ export class GoogleConsentMode {
187187
/**
188188
* Handles consent by updating the data layer with consent information.
189189
*
190-
* @param {string} consent - The consent command "consent".
191-
* @param consentCommand
190+
* @param {string} consentCommand - The consent command "consent".
192191
* @param {string} command - The command "default" or "update".
193192
* @param {object} consentParams - The consent arguments.
194193
*/

packages/react/src/analytics/integrations/shared/GoogleConsentMode/cookieUtils.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { PACKAGE_NAME } from '../../../constants';
33
export const GCM_SHARED_COOKIE_NAME = `${PACKAGE_NAME}__gcm_shared_consent_mode`;
44

55
/**
6+
* Gets the parent domain from the window location.
67
*
8+
* @returns {string} The domain calculated from the window location.
79
*/
810
function getDomain() {
911
const fullDomain = window.location.hostname;
@@ -22,9 +24,14 @@ function getDomain() {
2224
}
2325

2426
/**
25-
* @param name - Cookie name.
26-
* @param value - Cookie value.
27-
* @param domain - Domain to set. If not passed, will use the parent domain from the hostname.
27+
* Sets a cookie with the passed name
28+
* and value and domain. If domain is not
29+
* passed, it will be calculated from the
30+
* window.location to be a parent a domain.
31+
*
32+
* @param {string} name - Cookie name.
33+
* @param {string} value - Cookie value.
34+
* @param {string} [domain=getDomain()] - Domain to set. If not passed, will use the parent domain from the hostname.
2835
*/
2936
export function setCookie(name, value, domain = getDomain()) {
3037
document.cookie = name + '=' + (value || '') + '; path=/ ; domain=' + domain;

0 commit comments

Comments
 (0)