Skip to content

Commit

Permalink
fix: fix ssr
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Bruno Oliveira committed Mar 13, 2024
1 parent 1544c56 commit 5cace1a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
6 changes: 1 addition & 5 deletions packages/react/src/analytics/constants.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class GoogleConsentMode {
this.write(consentCommand, command, consent);
});
}
} catch {
} catch (_) {
// Do nothing...
}
}
Expand Down Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 5cace1a

Please sign in to comment.