Skip to content

Commit

Permalink
Make analytics instance consent-aware
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriyyakym committed Jan 28, 2025
1 parent c0fd741 commit 11dff9c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/analytics-nextjs/src/Analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ export class Analytics {
domain: document.location.host,
},
...options,
integrations: {
Prezly: this.permissions.canTrackToPrezly,
'Segment.io': this.permissions.canTrackToSegment,

Check warning on line 71 in packages/analytics-nextjs/src/Analytics.ts

View workflow job for this annotation

GitHub Actions / ESLint

packages/analytics-nextjs/src/Analytics.ts#L71

Object Literal Property name `Segment.io` must match one of the following formats: snake_case, strictCamelCase, StrictPascalCase, UPPER_CASE (@typescript-eslint/naming-convention)
...options?.integrations,
},
},
);
}
Expand All @@ -77,9 +82,17 @@ export class Analytics {
public setConsent(consent: Consent) {
this.consent = consent;

if (this.permissions.canLoadSegment) {
if (!this.segment?.instance && this.permissions.canLoadSegment) {
this.loadSegment();
}

if (this.segment?.instance?.options) {
this.segment.instance.options.integrations = {
...this.segment?.instance?.options.integrations,
Prezly: this.permissions.canTrackToPrezly,
'Segment.io': this.permissions.canTrackToSegment,

Check warning on line 93 in packages/analytics-nextjs/src/Analytics.ts

View workflow job for this annotation

GitHub Actions / ESLint

packages/analytics-nextjs/src/Analytics.ts#L93

Object Literal Property name `Segment.io` must match one of the following formats: snake_case, strictCamelCase, StrictPascalCase, UPPER_CASE (@typescript-eslint/naming-convention)
};
}
}

public alias(userId: string, previousId: string) {
Expand Down

0 comments on commit 11dff9c

Please sign in to comment.