Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

fix: set All integration if all destinations are enabled #349

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/consent-manager-builder/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default function conditionallyLoadAnalytics({
const wd = window as WindowWithAJS
const integrations = { All: false, 'Segment.io': true }
let isAnythingEnabled = false
let isEverythingEnabled = true;

if (!destinationPreferences) {
if (isConsentRequired) {
Expand All @@ -69,6 +70,8 @@ export default function conditionallyLoadAnalytics({
const isEnabled = Boolean(destinationPreferences[destination.id])
if (isEnabled) {
isAnythingEnabled = true
} else {
isEverythingEnabled = false
}
integrations[destination.id] = isEnabled
}
Expand All @@ -86,6 +89,10 @@ export default function conditionallyLoadAnalytics({
return
}

// Enable all destinations if everything is enabled
if (isEverythingEnabled) {
integrations.All = true
}
// Don't load a.js at all if nothing has been enabled
if (isAnythingEnabled) {
const middleware = getConsentMiddleware(
Expand Down