From 5cace1a4806988d58460df807706823cb4b0fa3b Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 12 Mar 2024 18:49:16 +0000 Subject: [PATCH] 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. --- packages/react/src/analytics/constants.js | 6 +----- .../shared/GoogleConsentMode/GoogleConsentMode.js | 5 ++--- .../shared/GoogleConsentMode/cookieUtils.js | 13 ++++++++++--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/react/src/analytics/constants.js b/packages/react/src/analytics/constants.js index 4273c96cb..ffd37508a 100644 --- a/packages/react/src/analytics/constants.js +++ b/packages/react/src/analytics/constants.js @@ -1,8 +1,4 @@ -// We use a require here to avoid typescript complaining of `package.json` is not -// under rootDir that we would get if we used an import. Typescript apparently ignores -// requires. -// eslint-disable-next-line @typescript-eslint/no-var-requires -const { name, version } = require('../../package.json'); +import { name, version } from '../../package.json'; export const PACKAGE_VERSION = version; export const PACKAGE_NAME = name; diff --git a/packages/react/src/analytics/integrations/shared/GoogleConsentMode/GoogleConsentMode.js b/packages/react/src/analytics/integrations/shared/GoogleConsentMode/GoogleConsentMode.js index bd846d8a4..0f20c55b4 100644 --- a/packages/react/src/analytics/integrations/shared/GoogleConsentMode/GoogleConsentMode.js +++ b/packages/react/src/analytics/integrations/shared/GoogleConsentMode/GoogleConsentMode.js @@ -63,7 +63,7 @@ export class GoogleConsentMode { this.write(consentCommand, command, consent); }); } - } catch { + } catch (_) { // Do nothing... } } @@ -187,8 +187,7 @@ export class GoogleConsentMode { /** * Handles consent by updating the data layer with consent information. * - * @param {string} consent - The consent command "consent". - * @param consentCommand + * @param {string} consentCommand - The consent command "consent". * @param {string} command - The command "default" or "update". * @param {object} consentParams - The consent arguments. */ diff --git a/packages/react/src/analytics/integrations/shared/GoogleConsentMode/cookieUtils.js b/packages/react/src/analytics/integrations/shared/GoogleConsentMode/cookieUtils.js index b56fedf98..88ebb2f99 100644 --- a/packages/react/src/analytics/integrations/shared/GoogleConsentMode/cookieUtils.js +++ b/packages/react/src/analytics/integrations/shared/GoogleConsentMode/cookieUtils.js @@ -3,7 +3,9 @@ import { PACKAGE_NAME } from '../../../constants'; export const GCM_SHARED_COOKIE_NAME = `${PACKAGE_NAME}__gcm_shared_consent_mode`; /** + * Gets the parent domain from the window location. * + * @returns {string} The domain calculated from the window location. */ function getDomain() { const fullDomain = window.location.hostname; @@ -22,9 +24,14 @@ function getDomain() { } /** - * @param name - Cookie name. - * @param value - Cookie value. - * @param domain - Domain to set. If not passed, will use the parent domain from the hostname. + * Sets a cookie with the passed name + * and value and domain. If domain is not + * passed, it will be calculated from the + * window.location to be a parent a domain. + * + * @param {string} name - Cookie name. + * @param {string} value - Cookie value. + * @param {string} [domain=getDomain()] - Domain to set. If not passed, will use the parent domain from the hostname. */ export function setCookie(name, value, domain = getDomain()) { document.cookie = name + '=' + (value || '') + '; path=/ ; domain=' + domain;