Skip to content

Commit

Permalink
Make google configuration consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriyyakym committed Jan 29, 2025
1 parent 3fc08d6 commit 25943f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
10 changes: 5 additions & 5 deletions packages/analytics-nextjs/src/Analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ export class Analytics {
}

if (config.google) {
const { analyticsId } = config.google;
import('./lib/loadGoogleAnalytics').then(({ loadGoogleAnalytics }) => {
// @ts-ignore
loadGoogleAnalytics(config.google.analyticsId);
loadGoogleAnalytics(analyticsId);
});
}

Expand Down Expand Up @@ -147,9 +147,9 @@ export class Analytics {

this.consent = consent;

const googleAnalyticsId = this.config?.google?.analyticsId;
if (googleAnalyticsId) {
window[`ga-disable-${googleAnalyticsId}`] = this.permissions.canTrackToGoogle;
if (this.config?.google) {
const { analyticsId } = this.config.google;
window[`ga-disable-${analyticsId}`] = this.permissions.canTrackToGoogle;
}

this.promises.segmentInit?.then(() => {
Expand Down
8 changes: 5 additions & 3 deletions packages/analytics-nextjs/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ export interface TrackingPermissions {
export interface Config {
consent?: Consent;
trackingPolicy: TrackingPolicy;
google?: {
analyticsId: string;
};
google?:
| false
| {
analyticsId: string;
};
plausible?: false | PlausibleOptions;
segment:
| false
Expand Down

0 comments on commit 25943f3

Please sign in to comment.